Initial commit

This commit is contained in:
Rain Clark 2022-04-21 20:06:30 -04:00
parent 4aa6a5cabe
commit d422f172a1
41 changed files with 835 additions and 0 deletions

Binary file not shown.

BIN
assets-raw/Background.kra Normal file

Binary file not shown.

BIN
assets-raw/Ball.kra Normal file

Binary file not shown.

BIN
assets-raw/Paddle.kra Normal file

Binary file not shown.

Binary file not shown.

BIN
assets-raw/icon.kra Normal file

Binary file not shown.

BIN
assets/Background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -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

BIN
assets/Ball.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

35
assets/Ball.png.import Normal file
View File

@ -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

BIN
assets/Paddle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

35
assets/Paddle.png.import Normal file
View File

@ -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

BIN
assets/bounce_sfx-01.ogg Normal file

Binary file not shown.

View File

@ -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

BIN
assets/bounce_sfx-02.ogg Normal file

Binary file not shown.

View File

@ -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

7
assets/pixelfont.tres Normal file
View File

@ -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 )

6
assets/ui_theme.tres Normal file
View File

@ -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 )

7
default_env.tres Normal file
View File

@ -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 )

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

35
icon.png.import Normal file
View File

@ -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

93
project.godot Normal file
View File

@ -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"

13
src/Actors/Actor.gd Normal file
View File

@ -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

30
src/Actors/Ball.gd Normal file
View File

@ -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()]

42
src/Actors/Ball.tscn Normal file
View File

@ -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"]

15
src/Actors/Paddle.gd Normal file
View File

@ -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)
)

17
src/Actors/Paddle.tscn Normal file
View File

@ -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 )

View File

@ -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")

View File

@ -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 )

22
src/Screens/Game.gd Normal file
View File

@ -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")

86
src/Screens/Game.tscn Normal file
View File

@ -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"]

62
src/Screens/MainMenu.tscn Normal file
View File

@ -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

View File

@ -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()

View File

@ -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

11
src/UI/ChangeScene.gd Normal file
View File

@ -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 ""

13
src/UI/ChangeScene.tscn Normal file
View File

@ -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"]

30
src/UI/GameHUD.gd Normal file
View File

@ -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

75
src/UI/GameHUD.tscn Normal file
View File

@ -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

4
src/UI/QuitButton.gd Normal file
View File

@ -0,0 +1,4 @@
extends Button
func _on_QuitButton_button_up() -> void:
get_tree().quit()

13
src/UI/QuitButton.tscn Normal file
View File

@ -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"]

16
src/UI/Title.tscn Normal file
View File

@ -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