diff --git a/default_theme.tres b/default_theme.tres new file mode 100644 index 0000000..3bbe5be --- /dev/null +++ b/default_theme.tres @@ -0,0 +1,4 @@ +[gd_resource type="Theme" format=3 uid="uid://bbasvjlc0fdo8"] + +[resource] +default_font_size = 30 diff --git a/project.godot b/project.godot index 4f2cbd1..64f6156 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="pong" -run/main_scene="res://scenes/playground/Playground.tscn" +run/main_scene="res://scenes/main_menu/MainMenu.tscn" config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://icon.svg" diff --git a/scenes/main_menu/ExitButton.gd b/scenes/main_menu/ExitButton.gd new file mode 100644 index 0000000..cfb604a --- /dev/null +++ b/scenes/main_menu/ExitButton.gd @@ -0,0 +1,5 @@ +extends Button + + +func _on_pressed(): + get_tree().quit() diff --git a/scenes/main_menu/MainMenu.tscn b/scenes/main_menu/MainMenu.tscn new file mode 100644 index 0000000..96c2dbf --- /dev/null +++ b/scenes/main_menu/MainMenu.tscn @@ -0,0 +1,40 @@ +[gd_scene load_steps=4 format=3 uid="uid://c71cjy50eonxj"] + +[ext_resource type="Theme" uid="uid://bbasvjlc0fdo8" path="res://default_theme.tres" id="1_gow2p"] +[ext_resource type="Script" path="res://scenes/main_menu/NewGameButton.gd" id="2_xmp3k"] +[ext_resource type="Script" path="res://scenes/main_menu/ExitButton.gd" id="3_r42kx"] + +[node name="MainMenu" type="Node2D"] + +[node name="NewGameContainer" type="PanelContainer" parent="."] +offset_right = 1200.0 +offset_bottom = 300.0 + +[node name="NewGameCenter" type="CenterContainer" parent="NewGameContainer"] +layout_mode = 2 + +[node name="NewGameButton" type="Button" parent="NewGameContainer/NewGameCenter"] +custom_minimum_size = Vector2(300, 100) +layout_mode = 2 +theme = ExtResource("1_gow2p") +text = "New Game" +script = ExtResource("2_xmp3k") + +[node name="ExitContainer" type="PanelContainer" parent="."] +offset_left = 1.0 +offset_top = 300.0 +offset_right = 1201.0 +offset_bottom = 600.0 + +[node name="ExitCenter" type="CenterContainer" parent="ExitContainer"] +layout_mode = 2 + +[node name="ExitButton" type="Button" parent="ExitContainer/ExitCenter"] +custom_minimum_size = Vector2(300, 100) +layout_mode = 2 +theme = ExtResource("1_gow2p") +text = "Exit" +script = ExtResource("3_r42kx") + +[connection signal="pressed" from="NewGameContainer/NewGameCenter/NewGameButton" to="NewGameContainer/NewGameCenter/NewGameButton" method="_on_pressed"] +[connection signal="pressed" from="ExitContainer/ExitCenter/ExitButton" to="ExitContainer/ExitCenter/ExitButton" method="_on_pressed"] diff --git a/scenes/main_menu/NewGameButton.gd b/scenes/main_menu/NewGameButton.gd new file mode 100644 index 0000000..63be4c2 --- /dev/null +++ b/scenes/main_menu/NewGameButton.gd @@ -0,0 +1,4 @@ +extends Button + +func _on_pressed(): + get_tree().change_scene_to_file("res://scenes/playground/Playground.tscn") diff --git a/scenes/playground/Playground.gd b/scenes/playground/Playground.gd index 5dc07c2..5af76b0 100644 --- a/scenes/playground/Playground.gd +++ b/scenes/playground/Playground.gd @@ -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) + + diff --git a/scenes/playground/Playground.tscn b/scenes/playground/Playground.tscn index da60802..0123cd9 100644 --- a/scenes/playground/Playground.tscn +++ b/scenes/playground/Playground.tscn @@ -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" diff --git a/scenes/playground/racket/Racket.gd b/scenes/playground/racket/Racket.gd index 7afd037..d2f65b3 100644 --- a/scenes/playground/racket/Racket.gd +++ b/scenes/playground/racket/Racket.gd @@ -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)