diff --git a/assets-raw/BBB_Simulator_Black.otf b/assets-raw/BBB_Simulator_Black.otf new file mode 100644 index 0000000..efa593a Binary files /dev/null and b/assets-raw/BBB_Simulator_Black.otf differ diff --git a/assets-raw/Background.kra b/assets-raw/Background.kra new file mode 100644 index 0000000..8665e6d Binary files /dev/null and b/assets-raw/Background.kra differ diff --git a/assets-raw/Ball.kra b/assets-raw/Ball.kra new file mode 100644 index 0000000..71d43e9 Binary files /dev/null and b/assets-raw/Ball.kra differ diff --git a/assets-raw/Paddle.kra b/assets-raw/Paddle.kra new file mode 100644 index 0000000..29efb59 Binary files /dev/null and b/assets-raw/Paddle.kra differ diff --git a/assets-raw/bounce_sfx-01.mmpz b/assets-raw/bounce_sfx-01.mmpz new file mode 100644 index 0000000..82a4b1c Binary files /dev/null and b/assets-raw/bounce_sfx-01.mmpz differ diff --git a/assets-raw/icon.kra b/assets-raw/icon.kra new file mode 100644 index 0000000..f09ef32 Binary files /dev/null and b/assets-raw/icon.kra differ diff --git a/assets/Background.png b/assets/Background.png new file mode 100644 index 0000000..6ee2b1e Binary files /dev/null and b/assets/Background.png differ diff --git a/assets/Background.png.import b/assets/Background.png.import new file mode 100644 index 0000000..8228349 --- /dev/null +++ b/assets/Background.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Background.png-6d72d35f07f42b3845e8764c552bb4fb.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/Background.png" +dest_files=[ "res://.import/Background.png-6d72d35f07f42b3845e8764c552bb4fb.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/assets/Ball.png b/assets/Ball.png new file mode 100644 index 0000000..75a3b73 Binary files /dev/null and b/assets/Ball.png differ diff --git a/assets/Ball.png.import b/assets/Ball.png.import new file mode 100644 index 0000000..2da7356 --- /dev/null +++ b/assets/Ball.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Ball.png-6366ecb65c8c630ad766823a9365d76e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/Ball.png" +dest_files=[ "res://.import/Ball.png-6366ecb65c8c630ad766823a9365d76e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/assets/Paddle.png b/assets/Paddle.png new file mode 100644 index 0000000..b5cd8de Binary files /dev/null and b/assets/Paddle.png differ diff --git a/assets/Paddle.png.import b/assets/Paddle.png.import new file mode 100644 index 0000000..18eaaa8 --- /dev/null +++ b/assets/Paddle.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Paddle.png-f985def4d60ce45ea6f40458e74985d9.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/Paddle.png" +dest_files=[ "res://.import/Paddle.png-f985def4d60ce45ea6f40458e74985d9.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/assets/bounce_sfx-01.ogg b/assets/bounce_sfx-01.ogg new file mode 100644 index 0000000..045e9f4 Binary files /dev/null and b/assets/bounce_sfx-01.ogg differ diff --git a/assets/bounce_sfx-01.ogg.import b/assets/bounce_sfx-01.ogg.import new file mode 100644 index 0000000..415f5bb --- /dev/null +++ b/assets/bounce_sfx-01.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/bounce_sfx-01.ogg-e60e59e6d2560efad859e6240ffe51b1.oggstr" + +[deps] + +source_file="res://assets/bounce_sfx-01.ogg" +dest_files=[ "res://.import/bounce_sfx-01.ogg-e60e59e6d2560efad859e6240ffe51b1.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/assets/bounce_sfx-02.ogg b/assets/bounce_sfx-02.ogg new file mode 100644 index 0000000..31d83ef Binary files /dev/null and b/assets/bounce_sfx-02.ogg differ diff --git a/assets/bounce_sfx-02.ogg.import b/assets/bounce_sfx-02.ogg.import new file mode 100644 index 0000000..711cf7c --- /dev/null +++ b/assets/bounce_sfx-02.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/bounce_sfx-02.ogg-eb36d4bdfa9c40de823f3eb2a2e506ac.oggstr" + +[deps] + +source_file="res://assets/bounce_sfx-02.ogg" +dest_files=[ "res://.import/bounce_sfx-02.ogg-eb36d4bdfa9c40de823f3eb2a2e506ac.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/assets/pixelfont.tres b/assets/pixelfont.tres new file mode 100644 index 0000000..ca4ce69 --- /dev/null +++ b/assets/pixelfont.tres @@ -0,0 +1,7 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=1] + +[resource] +size = 24 +font_data = ExtResource( 1 ) diff --git a/assets/ui_theme.tres b/assets/ui_theme.tres new file mode 100644 index 0000000..210b666 --- /dev/null +++ b/assets/ui_theme.tres @@ -0,0 +1,6 @@ +[gd_resource type="Theme" load_steps=2 format=2] + +[ext_resource path="res://assets/pixelfont.tres" type="DynamicFont" id=1] + +[resource] +default_font = ExtResource( 1 ) diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..c2dbadb Binary files /dev/null and b/icon.png differ diff --git a/icon.png.import b/icon.png.import new file mode 100644 index 0000000..a4c02e6 --- /dev/null +++ b/icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..e3c6bf4 --- /dev/null +++ b/project.godot @@ -0,0 +1,93 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ { +"base": "KinematicBody2D", +"class": "Actor", +"language": "GDScript", +"path": "res://src/Actors/Actor.gd" +} ] +_global_script_class_icons={ +"Actor": "" +} + +[application] + +config/name="Pong" +run/main_scene="res://src/Screens/MainMenu.tscn" +config/icon="res://icon.png" + +[autoload] + +PlayerData="*res://src/AutoLoad/PlayerData.tscn" + +[display] + +window/size/width=1280 +window/size/height=720 +window/stretch/mode="2d" +window/stretch/aspect="keep" + +[editor_plugins] + +enabled=PoolStringArray( ) + +[global] + +window=false + +[input] + +P1_Up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) + ] +} +P1_Down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) + ] +} +P2_Up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":12,"pressure":0.0,"pressed":false,"script":null) + ] +} +P2_Down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":13,"pressure":0.0,"pressed":false,"script":null) + ] +} +Pause={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":false,"script":null) + ] +} + +[layer_names] + +2d_physics/layer_1="World" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres" diff --git a/src/Actors/Actor.gd b/src/Actors/Actor.gd new file mode 100644 index 0000000..af11a01 --- /dev/null +++ b/src/Actors/Actor.gd @@ -0,0 +1,13 @@ +extends KinematicBody2D +class_name Actor + +export var speed: = Vector2(0, 0) + + +var _velocity: = Vector2.ZERO +var _direction: = Vector2.ZERO + +func calculate_move_velocity(linear_velocity: Vector2, direction: Vector2, current_speed: Vector2) -> Vector2: + var move_velocity: = linear_velocity + move_velocity = current_speed * direction + return move_velocity diff --git a/src/Actors/Ball.gd b/src/Actors/Ball.gd new file mode 100644 index 0000000..afd8c5f --- /dev/null +++ b/src/Actors/Ball.gd @@ -0,0 +1,30 @@ +extends Actor + +export var top_speed: = 1000 + +func _ready() -> void: + randomize() + _direction.x = random_direction() + _direction.y = randf() * random_direction() + +func _physics_process(_delta: float) -> void: + _velocity = calculate_move_velocity(_velocity, _direction, speed) + _velocity = move_and_slide(_velocity) + +func _on_BounceCheck_body_entered(body: PhysicsBody2D) -> void: + bounce(body) + +func bounce(object: PhysicsBody2D) -> void: + if speed.x <= top_speed: + speed.x *= 1.1 + if object is Actor: + _direction.x = -_direction.x + $"SFX/BounceSound-2".play() + else: + _direction.y *= -1 + $"SFX/BounceSound-1".play() + +func random_direction() -> int: + var directions:= [-1, 1] + return directions[randi() % directions.size()] + diff --git a/src/Actors/Ball.tscn b/src/Actors/Ball.tscn new file mode 100644 index 0000000..d1a9cce --- /dev/null +++ b/src/Actors/Ball.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://src/Actors/Ball.gd" type="Script" id=1] +[ext_resource path="res://assets/Ball.png" type="Texture" id=2] +[ext_resource path="res://assets/bounce_sfx-01.ogg" type="AudioStream" id=3] +[ext_resource path="res://assets/bounce_sfx-02.ogg" type="AudioStream" id=4] + +[sub_resource type="RectangleShape2D" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 14.25, 15 ) + +[node name="Ball" type="KinematicBody2D"] +script = ExtResource( 1 ) +speed = Vector2( 200, 100 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 2 ) +disabled = true + +[node name="BounceCheck" type="Area2D" parent="."] +position = Vector2( -1, 0 ) +rotation = -3.14159 +scale = Vector2( 1.40155, 1.3282 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="BounceCheck"] +modulate = Color( 0.815686, 0.854902, 0.113725, 1 ) +position = Vector2( -0.75, 0 ) +shape = SubResource( 1 ) + +[node name="SFX" type="Node" parent="."] + +[node name="BounceSound-1" type="AudioStreamPlayer" parent="SFX"] +stream = ExtResource( 3 ) + +[node name="BounceSound-2" type="AudioStreamPlayer" parent="SFX"] +stream = ExtResource( 4 ) + +[connection signal="body_entered" from="BounceCheck" to="." method="_on_BounceCheck_body_entered"] diff --git a/src/Actors/Paddle.gd b/src/Actors/Paddle.gd new file mode 100644 index 0000000..80df4e6 --- /dev/null +++ b/src/Actors/Paddle.gd @@ -0,0 +1,15 @@ +extends Actor + +export var Player: = 1 + + +func _physics_process(_delta: float) -> void: + _direction = get_direction() + _velocity = calculate_move_velocity(_velocity, _direction, speed) + _velocity = move_and_slide(_velocity) + +func get_direction() -> Vector2: + return Vector2( + 0, + Input.get_action_strength("P%s_Down" % Player) - Input.get_action_strength("P%s_Up" % Player) + ) diff --git a/src/Actors/Paddle.tscn b/src/Actors/Paddle.tscn new file mode 100644 index 0000000..b3901fa --- /dev/null +++ b/src/Actors/Paddle.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/Paddle.png" type="Texture" id=1] +[ext_resource path="res://src/Actors/Paddle.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 20, 80 ) + +[node name="Paddle" type="KinematicBody2D"] +script = ExtResource( 2 ) +speed = Vector2( 0, 250 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/src/AutoLoad/PlayerData.gd b/src/AutoLoad/PlayerData.gd new file mode 100644 index 0000000..7034982 --- /dev/null +++ b/src/AutoLoad/PlayerData.gd @@ -0,0 +1,21 @@ +extends Node + +# TODO: Look into using an array or something to clean this up + +signal p1_score_updated +signal p2_score_updated + +var p1_score: = 0 setget set_p1_score +var p2_score: = 0 setget set_p2_score + +func reset_scores() -> void: + p1_score = 0 + p2_score = 0 + +func set_p1_score(value: int) -> void: + p1_score = value + emit_signal("p1_score_updated") + +func set_p2_score(value: int) -> void: + p2_score = value + emit_signal("p2_score_updated") diff --git a/src/AutoLoad/PlayerData.tscn b/src/AutoLoad/PlayerData.tscn new file mode 100644 index 0000000..005b762 --- /dev/null +++ b/src/AutoLoad/PlayerData.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://src/AutoLoad/PlayerData.gd" type="Script" id=1] + +[node name="PlayerData" type="Node"] +script = ExtResource( 1 ) diff --git a/src/Screens/Game.gd b/src/Screens/Game.gd new file mode 100644 index 0000000..5df95ac --- /dev/null +++ b/src/Screens/Game.gd @@ -0,0 +1,22 @@ +extends Node + +export var target_score: = 5 + +func _on_Left_area_entered(_area: Area2D) -> void: + score_point(2) + +func _on_Right_area_entered(_area: Area2D) -> void: + score_point(1) + +func score_point(player_scored: int) -> void: + if player_scored == 1: + PlayerData.p1_score += 1 + else: + PlayerData.p2_score += 1 + get_tree().reload_current_scene() + check_winner() + + +func check_winner() -> void: + if PlayerData.p1_score >= target_score or PlayerData.p2_score >= target_score: + get_tree().change_scene("res://src/Screens/ResultsScreen.tscn") diff --git a/src/Screens/Game.tscn b/src/Screens/Game.tscn new file mode 100644 index 0000000..2ae1134 --- /dev/null +++ b/src/Screens/Game.tscn @@ -0,0 +1,86 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://src/Actors/Paddle.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/Background.png" type="Texture" id=2] +[ext_resource path="res://src/UI/GameHUD.tscn" type="PackedScene" id=3] +[ext_resource path="res://src/Screens/Game.gd" type="Script" id=4] +[ext_resource path="res://src/Actors/Ball.tscn" type="PackedScene" id=5] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 640, 0.5 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 4, 358.5 ) + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 4, 358.5 ) + +[node name="Game" type="Node2D"] +script = ExtResource( 4 ) + +[node name="BackgroundLayer" type="CanvasLayer" parent="."] +layer = -101 + +[node name="Background" type="TextureRect" parent="BackgroundLayer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +texture = ExtResource( 2 ) + +[node name="UserInterface" type="CanvasLayer" parent="."] +layer = 100 + +[node name="GameHUD" parent="UserInterface" instance=ExtResource( 3 )] + +[node name="Bounds" type="Node" parent="."] +__meta__ = { +"_editor_description_": "The bounds of the game map" +} + +[node name="Top" type="StaticBody2D" parent="Bounds"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Bounds/Top"] +position = Vector2( 640, -0.5 ) +shape = SubResource( 1 ) + +[node name="Bottom" type="StaticBody2D" parent="Bounds"] +position = Vector2( 0, 720 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Bounds/Bottom"] +position = Vector2( 640, -0.5 ) +shape = SubResource( 1 ) + +[node name="Left" type="Area2D" parent="Bounds"] +monitorable = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Bounds/Left"] +position = Vector2( -4, 359.5 ) +shape = SubResource( 2 ) + +[node name="Right" type="Area2D" parent="Bounds"] +monitorable = false + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Bounds/Right"] +position = Vector2( 1284, 359.5 ) +shape = SubResource( 3 ) + +[node name="Actors" type="Node" parent="."] +__meta__ = { +"_editor_description_": "All actors in the game" +} + +[node name="Player1" parent="Actors" instance=ExtResource( 1 )] +pause_mode = 2 +modulate = Color( 0.0862745, 0.54902, 0.254902, 1 ) +position = Vector2( 64, 376 ) + +[node name="Player2" parent="Actors" instance=ExtResource( 1 )] +modulate = Color( 0.560784, 0.00392157, 0.658824, 1 ) +position = Vector2( 1216, 376 ) +Player = 2 + +[node name="Ball" parent="Actors" instance=ExtResource( 5 )] +modulate = Color( 1, 0.913725, 0, 1 ) +position = Vector2( 640, 376 ) + +[connection signal="area_entered" from="Bounds/Left" to="." method="_on_Left_area_entered"] +[connection signal="area_entered" from="Bounds/Right" to="." method="_on_Right_area_entered"] diff --git a/src/Screens/MainMenu.tscn b/src/Screens/MainMenu.tscn new file mode 100644 index 0000000..a639d90 --- /dev/null +++ b/src/Screens/MainMenu.tscn @@ -0,0 +1,62 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/Background.png" type="Texture" id=2] +[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=3] +[ext_resource path="res://src/UI/QuitButton.tscn" type="PackedScene" id=4] +[ext_resource path="res://src/UI/ChangeScene.tscn" type="PackedScene" id=5] +[ext_resource path="res://src/UI/Title.tscn" type="PackedScene" id=6] + +[sub_resource type="DynamicFont" id=1] +font_data = ExtResource( 1 ) + +[sub_resource type="Theme" id=2] +default_font = SubResource( 1 ) + +[node name="MainMenu" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +theme = ExtResource( 3 ) + +[node name="Background" type="TextureRect" parent="."] +modulate = Color( 0, 0, 0, 1 ) +margin_right = 40.0 +margin_bottom = 40.0 +theme = SubResource( 2 ) +texture = ExtResource( 2 ) + +[node name="Title" parent="." instance=ExtResource( 6 )] +pause_mode = 2 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -150.5 +margin_top = -215.5 +margin_right = 150.5 +margin_bottom = -148.5 +text = "Pong" + +[node name="MenuButtons" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -84.0 +margin_top = -36.0 +margin_right = 87.0 +margin_bottom = 63.0 +alignment = 1 + +[node name="PlayButton" parent="MenuButtons" instance=ExtResource( 5 )] +margin_right = 171.0 +margin_bottom = 47.0 +size_flags_vertical = 3 +text = "Play" +next_scene_path = "res://src/Screens/Game.tscn" + +[node name="QuitButton" parent="MenuButtons" instance=ExtResource( 4 )] +margin_top = 51.0 +margin_right = 171.0 +margin_bottom = 99.0 +size_flags_vertical = 3 diff --git a/src/Screens/ResultsScreen.gd b/src/Screens/ResultsScreen.gd new file mode 100644 index 0000000..761accd --- /dev/null +++ b/src/Screens/ResultsScreen.gd @@ -0,0 +1,8 @@ +extends Control + +onready var results_title: Label = $Title + +func _ready() -> void: + var winner: = 1 if PlayerData.p1_score > PlayerData.p2_score else 2 + results_title.text = "Player %s Wins!" % winner + PlayerData.reset_scores() diff --git a/src/Screens/ResultsScreen.tscn b/src/Screens/ResultsScreen.tscn new file mode 100644 index 0000000..2096fb2 --- /dev/null +++ b/src/Screens/ResultsScreen.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/Background.png" type="Texture" id=2] +[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=3] +[ext_resource path="res://src/UI/QuitButton.tscn" type="PackedScene" id=4] +[ext_resource path="res://src/UI/ChangeScene.tscn" type="PackedScene" id=5] +[ext_resource path="res://src/UI/Title.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/Screens/ResultsScreen.gd" type="Script" id=7] + +[sub_resource type="DynamicFont" id=1] +font_data = ExtResource( 1 ) + +[sub_resource type="Theme" id=2] +default_font = SubResource( 1 ) + +[node name="ResultsScreen" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +theme = ExtResource( 3 ) +script = ExtResource( 7 ) + +[node name="Background" type="TextureRect" parent="."] +modulate = Color( 0, 0, 0, 1 ) +margin_right = 40.0 +margin_bottom = 40.0 +theme = SubResource( 2 ) +texture = ExtResource( 2 ) + +[node name="Title" parent="." instance=ExtResource( 6 )] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -169.0 +margin_top = -168.0 +margin_right = 169.0 +margin_bottom = -101.0 +text = "Player %s Wins!" + +[node name="MenuButtons" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -84.0 +margin_top = -36.0 +margin_right = 87.0 +margin_bottom = 63.0 +alignment = 1 + +[node name="Restart" parent="MenuButtons" instance=ExtResource( 5 )] +margin_right = 171.0 +margin_bottom = 40.0 +text = "Restart" +next_scene_path = "res://src/Screens/Game.tscn" + +[node name="MainMenuButton" parent="MenuButtons" instance=ExtResource( 5 )] +margin_top = 44.0 +margin_right = 171.0 +margin_bottom = 84.0 +text = "Main Menu" +next_scene_path = "res://src/Screens/MainMenu.tscn" + +[node name="QuitButton" parent="MenuButtons" instance=ExtResource( 4 )] +margin_top = 88.0 +margin_right = 171.0 +margin_bottom = 128.0 diff --git a/src/UI/ChangeScene.gd b/src/UI/ChangeScene.gd new file mode 100644 index 0000000..ebff763 --- /dev/null +++ b/src/UI/ChangeScene.gd @@ -0,0 +1,11 @@ +tool +extends Button + +export(String, FILE) var next_scene_path: = "" + +func _on_ChangeSceneButton_button_up() -> void: + get_tree().paused = false + get_tree().change_scene(next_scene_path) + +func _on_configuration_warning() -> String: + return "Next Level property can't be empty" if next_scene_path == "" else "" diff --git a/src/UI/ChangeScene.tscn b/src/UI/ChangeScene.tscn new file mode 100644 index 0000000..215f8d6 --- /dev/null +++ b/src/UI/ChangeScene.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=1] +[ext_resource path="res://src/UI/ChangeScene.gd" type="Script" id=2] + +[node name="ChangeSceneButton" type="Button"] +margin_right = 12.0 +margin_bottom = 20.0 +theme = ExtResource( 1 ) +text = "CHANGE_SCENE" +script = ExtResource( 2 ) + +[connection signal="button_up" from="." to="." method="_on_ChangeSceneButton_button_up"] diff --git a/src/UI/GameHUD.gd b/src/UI/GameHUD.gd new file mode 100644 index 0000000..a28fb69 --- /dev/null +++ b/src/UI/GameHUD.gd @@ -0,0 +1,30 @@ +extends Control + +onready var scene_tree = get_tree() +onready var p1_score: Label = $P1Score +onready var p2_score: Label = $P2Score +onready var pause_overlay: ColorRect = $PauseOverlay + +var paused: = false setget set_paused + +func _ready() -> void: + PlayerData.connect("p1_score_updated", self, "update_interface") + PlayerData.connect("p2_score_updated", self, "update_interface") + update_interface() + +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("Pause"): + self.paused = not paused + # Prevents other nodes handling the "pause" event + scene_tree.set_input_as_handled() + + +func update_interface() -> void: + p1_score.text = "%s" % PlayerData.p1_score + p2_score.text = "%s" % PlayerData.p2_score + + +func set_paused(value: bool) -> void: + paused = value + scene_tree.paused = value + pause_overlay.visible = value diff --git a/src/UI/GameHUD.tscn b/src/UI/GameHUD.tscn new file mode 100644 index 0000000..6120fef --- /dev/null +++ b/src/UI/GameHUD.tscn @@ -0,0 +1,75 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://src/UI/GameHUD.gd" type="Script" id=4] +[ext_resource path="res://src/UI/QuitButton.tscn" type="PackedScene" id=5] +[ext_resource path="res://src/UI/Title.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/UI/ChangeScene.tscn" type="PackedScene" id=7] +[ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=8] + +[sub_resource type="DynamicFont" id=1] +size = 48 +font_data = ExtResource( 8 ) + +[node name="GameHUD" type="Control"] +pause_mode = 2 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 4 ) +__meta__ = { +"_edit_vertical_guides_": [ 640.0 ] +} + +[node name="P1Score" parent="." instance=ExtResource( 6 )] +margin_left = 576.0 +margin_right = 632.0 +margin_bottom = 67.0 +text = "%s" + +[node name="P2Score" parent="." instance=ExtResource( 6 )] +margin_left = 648.0 +margin_right = 704.0 +margin_bottom = 67.0 +text = "%s" + +[node name="PauseOverlay" type="ColorRect" parent="."] +visible = false +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +color = Color( 0, 0, 0, 0.235294 ) + +[node name="Title" parent="PauseOverlay" instance=ExtResource( 6 )] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -150.5 +margin_top = -215.5 +margin_right = 150.5 +margin_bottom = -148.5 +custom_fonts/font = SubResource( 1 ) +text = "Paused" + +[node name="MenuButtons" type="VBoxContainer" parent="PauseOverlay"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -84.0 +margin_top = -36.0 +margin_right = 87.0 +margin_bottom = 63.0 +alignment = 1 + +[node name="MainMenuButton" parent="PauseOverlay/MenuButtons" instance=ExtResource( 7 )] +margin_top = 7.0 +margin_right = 171.0 +margin_bottom = 47.0 +text = "Main Menu" +next_scene_path = "res://src/Screens/MainMenu.tscn" + +[node name="QuitButton" parent="PauseOverlay/MenuButtons" instance=ExtResource( 5 )] +margin_top = 51.0 +margin_right = 171.0 +margin_bottom = 91.0 diff --git a/src/UI/QuitButton.gd b/src/UI/QuitButton.gd new file mode 100644 index 0000000..f8c5c4f --- /dev/null +++ b/src/UI/QuitButton.gd @@ -0,0 +1,4 @@ +extends Button + +func _on_QuitButton_button_up() -> void: + get_tree().quit() diff --git a/src/UI/QuitButton.tscn b/src/UI/QuitButton.tscn new file mode 100644 index 0000000..c176e1f --- /dev/null +++ b/src/UI/QuitButton.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=1] +[ext_resource path="res://src/UI/QuitButton.gd" type="Script" id=2] + +[node name="QuitButton" type="Button"] +margin_right = 12.0 +margin_bottom = 20.0 +theme = ExtResource( 1 ) +text = "Quit" +script = ExtResource( 2 ) + +[connection signal="button_up" from="." to="." method="_on_QuitButton_button_up"] diff --git a/src/UI/Title.tscn b/src/UI/Title.tscn new file mode 100644 index 0000000..d12c3a9 --- /dev/null +++ b/src/UI/Title.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=2] + +[sub_resource type="DynamicFont" id=1] +size = 48 +font_data = ExtResource( 1 ) + +[node name="Title" type="Label"] +margin_right = 40.0 +margin_bottom = 14.0 +theme = ExtResource( 2 ) +custom_fonts/font = SubResource( 1 ) +text = "TITLE_TEXT" +align = 1