main_menu

This commit is contained in:
2024-03-12 14:41:35 +01:00
parent f83f6989b4
commit 7c6b8ca4c1
8 changed files with 96 additions and 17 deletions
+32 -12
View File
@@ -10,38 +10,58 @@ func start():
add_child(ball)
func set_score():
get_node("Score").text = "{right} - {left}".format({
get_node("Score").text = "{left} - {right}".format({
"left": left_point,
"right": right_point
})
func new_round(ball):
remove_child(ball)
set_score()
start()
func body_is_ball(body):
return body.name == "Ball"
func _ready():
start()
func _process(delta):
pass
func _on_goal_area_left_body_entered(body):
if body.name == "Ball":
left_point += 1
new_round(body)
func _on_goal_area_right_body_entered(body):
if body.name == "Ball":
func _on_goal_area_left_body_entered(body):
if body_is_ball(body):
right_point += 1
new_round(body)
func _on_racket_left_body_entered(body):
if body.name == "Ball":
body.linear_velocity = body.linear_velocity * -1
func _on_goal_area_right_body_entered(body):
if body_is_ball(body):
left_point += 1
new_round(body)
func ball_to_racket(body):
if body_is_ball(body):
var new_linear_velocity = body.linear_velocity * -1
#if new_linear_velocity.y == 300 and new_linear_velocity.x == 300:
# new_linear_velocity.x -= 10
# new_linear_velocity.y += 10
body.linear_velocity = new_linear_velocity
print_debug(new_linear_velocity)
func _on_racket_left_body_entered(body):
ball_to_racket(body)
func _on_racket_right_body_entered(body):
if body.name == "Ball":
body.linear_velocity = body.linear_velocity * -1
ball_to_racket(body)
+10 -1
View File
@@ -40,13 +40,22 @@ shape = SubResource("RectangleShape2D_u7af8")
position = Vector2(128, 224)
collision_layer = 255
collision_mask = 255
max_contacts_reported = 1000
custom_integrator = true
continuous_cd = 2
max_contacts_reported = 1
contact_monitor = true
metadata/UP_KEY = "left_up"
metadata/DOWN_KEY = "left_down"
[node name="RacketRight" parent="." instance=ExtResource("1_ywul3")]
position = Vector2(1032, 224)
collision_layer = 255
collision_mask = 255
freeze = true
custom_integrator = true
continuous_cd = 1
max_contacts_reported = 1
contact_monitor = true
metadata/UP_KEY = "right_up"
metadata/DOWN_KEY = "right_down"
-3
View File
@@ -3,9 +3,6 @@ extends RigidBody2D
const SPEED = 300.0
func _ready():
contact_monitor = true
func _physics_process(delta):
if Input.is_action_pressed(get_meta("UP_KEY")):
move_and_collide(Vector2.UP * SPEED * delta)