Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Patryk | |
Old Version | Published before Godot 3 was released. |
For my school project I make a round pong with four players. The game area is defined with a collider and script. In the script, I managed to split the game area to two players. If the ball flies up, the lower player gets the point and when the ball flies down, the top player gets the point. How can I make that for 4 players? How can I split the game area for 4 players?
Can someone help me?
Here is the complete Script:
extends Node2D
onready var ball = get_node(“Ball”)
var screen_size
var var1 = 0
var var2 = 0
var var3 = 0
func _ready():
set_process(true)
screen_size = get_viewport_rect().size
set_process_input(true)
func _process(delta):
if ((ball.get_global_pos().y < 0) or (ball.get_global_pos().y > screen_size.y) or (ball.get_global_pos().x < 0) or (ball.get_global_pos().x > screen_size.x)):
reset_match()
func reset_match():
ball.set_pos(Vector2(screen_size.x * 0.5,screen_size.y * 0.5))
ball.set_angular_velocity(0)
func _input(event):
if event.is_action_pressed(“btn_return”):
OS.get_main_loop().quit()
func _on_PlayArea_body_exit( body ):
var Area = get_node(“PlayArea”)
var distance = body.get_pos() - Area.get_pos()
if(distance.y < 0):
var1 += 1
get_node(“Scores”).get_child(0).set_text(str(var1))
if var1 == 10:
print(“Player 1 win”)
else:
var2 += 1
get_node(“Scores”).get_child(1).set_text(str(var2))
if var2 == 10:
print(“Player 2 win”)