pongodot

Tinkering with Godot, remaking pong
git clone git://git.hellocld.com/pongodot
Log | Files | Refs

commit 583c362084ad93f980107cb1492309f0d174a4d3
parent b26920abb3c56a7c1db4b4d692f276da7069e6d8
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Thu, 14 Nov 2019 14:34:41 -0500

Sound effects, random ball direction, ball spawning

Diffstat:
MBall.gd | 23+++++++++++++++--------
MBall.tscn | 8+++++++-
MGame.gd | 24+++++++++++++++---------
MGame.tscn | 33++++++++++++++++-----------------
MMainMenu.tscn | 12++++++------
ASounds/goal.wav | 0
ASounds/goal.wav.import | 21+++++++++++++++++++++
ASounds/png-fx.a2m | 0
ASounds/pong.wav | 0
ASounds/pong.wav.import | 21+++++++++++++++++++++
Adefault_bus_layout.tres | 9+++++++++
11 files changed, 110 insertions(+), 41 deletions(-)

diff --git a/Ball.gd b/Ball.gd @@ -5,28 +5,35 @@ var _dir = Vector2(1, 1) var _radius = 0 var _hits = 0 -func _ready(): - reset() - - func _physics_process(delta): var collision = move_and_collide(_dir * _speed * delta) if collision: + $SFX.play() _hits += 1 - if _hits % 10 == 0: - _speed += 2 + if _hits % 3 == 0: + _speed += 10 print(collision.collider.name) $AnimationPlayer.play("Boop") _dir = _dir.bounce(collision.normal) if position.x >= get_viewport().size.x - _radius or position.x < _radius: + $SFX.play() _dir.x *= -1 if position.y >= get_viewport().size.y - _radius or position.y < _radius: + $SFX.play() _dir.y *= -1 -func reset(): +func _ready(): + randomize() + if(randf() > 0.5): + _dir.x = 1 + else: + _dir.x = -1 + if(randf() > 0.5): + _dir.y = 1 + else: + _dir.y = -1 _dir = _dir.normalized() - position = get_viewport().size / 2 var shape = $CollisionShape2D.shape as CircleShape2D _radius = shape.radius _hits = 0 \ No newline at end of file diff --git a/Ball.tscn b/Ball.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Ball.gd" type="Script" id=1] [ext_resource path="res://Sprites/System6-Slice.png" type="Texture" id=2] [ext_resource path="res://Sprites/System6-Slice2.png" type="Texture" id=3] [ext_resource path="res://Sprites/System6-Slice1.png" type="Texture" id=4] +[ext_resource path="res://Sounds/pong.wav" type="AudioStream" id=5] [sub_resource type="CircleShape2D" id=1] @@ -25,6 +26,7 @@ tracks/0/keys = { [node name="Ball" type="KinematicBody2D"] script = ExtResource( 1 ) +_speed = 80 [node name="NinePatchRect" type="NinePatchRect" parent="."] margin_left = -10.0 @@ -44,3 +46,7 @@ shape = SubResource( 1 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] anims/Boop = SubResource( 2 ) + +[node name="SFX" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource( 5 ) +bus = "FX" diff --git a/Game.gd b/Game.gd @@ -5,24 +5,28 @@ export var game_score = 10 var p1_score = 0 var p2_score = 0 +var ball = preload("res://Ball.tscn") func _ready(): p1_score = 0 p2_score = 0 + _reset() func _reset(): $LabelPanel/Label.text = "GET READY" $LabelPanel.visible = true $Timer.connect("timeout", self, "_start_game") $Timer.one_shot = true - $Timer.start(5) + $Timer.start(3) func _start_game(): + print("Game start!") $LabelPanel.visible = false - - $Ball.reset() - + var t_ball = ball.instance() + t_ball.position = get_viewport_rect().size / 2 + add_child(t_ball) + func _print_score(): $HUD/Score.text = "%02d | %02d" % [p1_score, p2_score] @@ -31,21 +35,23 @@ func _print_score(): func _on_Goal_1_body_entered(area): if area == $Ball: + $GoalSFX.play() + $Ball.free() p2_score += 1 _print_score() if p2_score >= game_score: print("P2 Wins!") - $Ball.free() else: - $Ball.reset() + _reset() func _on_Goal_2_body_entered(area): if area == $Ball: + $GoalSFX.play() + $Ball.free() p1_score += 1 _print_score() if p1_score >= game_score: print("P1 Wins!") - $Ball.free() else: - $Ball.reset()- \ No newline at end of file + _reset()+ \ No newline at end of file diff --git a/Game.tscn b/Game.tscn @@ -2,16 +2,16 @@ [ext_resource path="res://Game.gd" type="Script" id=1] [ext_resource path="res://Sprites/bg-01.png" type="Texture" id=2] -[ext_resource path="res://Ball.tscn" type="PackedScene" id=3] -[ext_resource path="res://Paddle.tscn" type="PackedScene" id=4] -[ext_resource path="res://Goal.tscn" type="PackedScene" id=5] -[ext_resource path="res://HUD.tscn" type="PackedScene" id=6] -[ext_resource path="res://Sprites/System6-UI-Slice.png" type="Texture" id=7] -[ext_resource path="res://Fonts/Chicago.ttf" type="DynamicFontData" id=8] +[ext_resource path="res://Paddle.tscn" type="PackedScene" id=3] +[ext_resource path="res://Goal.tscn" type="PackedScene" id=4] +[ext_resource path="res://HUD.tscn" type="PackedScene" id=5] +[ext_resource path="res://Sprites/System6-UI-Slice.png" type="Texture" id=6] +[ext_resource path="res://Fonts/Chicago.ttf" type="DynamicFontData" id=7] +[ext_resource path="res://Sounds/goal.wav" type="AudioStream" id=8] [sub_resource type="DynamicFont" id=1] size = 40 -font_data = ExtResource( 8 ) +font_data = ExtResource( 7 ) [node name="Game" type="Node2D"] script = ExtResource( 1 ) @@ -23,33 +23,29 @@ margin_bottom = 342.0 texture = ExtResource( 2 ) stretch_mode = 2 -[node name="Ball" parent="." instance=ExtResource( 3 )] -position = Vector2( 256, 171 ) -_speed = 128 - -[node name="Paddle 1" parent="." instance=ExtResource( 4 )] +[node name="Paddle 1" parent="." instance=ExtResource( 3 )] position = Vector2( 26, 171 ) _speed = 64 -[node name="Goal 1" parent="." instance=ExtResource( 5 )] +[node name="Goal 1" parent="." instance=ExtResource( 4 )] position = Vector2( 504, 171 ) -[node name="Paddle 2" parent="." instance=ExtResource( 4 )] +[node name="Paddle 2" parent="." instance=ExtResource( 3 )] position = Vector2( 486, 171 ) _speed = 64 _player = "p2" -[node name="Goal 2" parent="." instance=ExtResource( 5 )] +[node name="Goal 2" parent="." instance=ExtResource( 4 )] position = Vector2( 8, 171 ) -[node name="HUD" parent="." instance=ExtResource( 6 )] +[node name="HUD" parent="." instance=ExtResource( 5 )] [node name="LabelPanel" type="NinePatchRect" parent="."] margin_left = 128.0 margin_top = 107.0 margin_right = 384.0 margin_bottom = 235.0 -texture = ExtResource( 7 ) +texture = ExtResource( 6 ) patch_margin_left = 4 patch_margin_top = 12 patch_margin_right = 4 @@ -70,5 +66,8 @@ autowrap = true [node name="Timer" type="Timer" parent="."] wait_time = 5.0 + +[node name="GoalSFX" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 8 ) [connection signal="body_entered" from="Goal 1" to="." method="_on_Goal_1_body_entered"] [connection signal="body_entered" from="Goal 2" to="." method="_on_Goal_2_body_entered"] diff --git a/MainMenu.tscn b/MainMenu.tscn @@ -19,17 +19,17 @@ margin_bottom = 6.0 size = 12 font_data = ExtResource( 6 ) -[sub_resource type="DynamicFont" id=5] +[sub_resource type="DynamicFont" id=3] size = 96 outline_color = Color( 0, 0, 0, 1 ) font_data = ExtResource( 6 ) -[sub_resource type="DynamicFont" id=3] +[sub_resource type="DynamicFont" id=4] size = 32 outline_color = Color( 0, 0, 0, 1 ) font_data = ExtResource( 6 ) -[sub_resource type="DynamicFont" id=4] +[sub_resource type="DynamicFont" id=5] size = 12 outline_color = Color( 0, 0, 0, 1 ) extra_spacing_bottom = 4 @@ -121,7 +121,7 @@ anchor_right = 1.0 anchor_bottom = 0.5 margin_top = -79.0 margin_bottom = 31.0 -custom_fonts/font = SubResource( 5 ) +custom_fonts/font = SubResource( 3 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) text = "P.NG" align = 1 @@ -166,7 +166,7 @@ anchor_right = 1.0 anchor_bottom = 0.5 margin_top = -97.0 margin_bottom = -57.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 4 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) text = "About P.NG" align = 1 @@ -179,7 +179,7 @@ anchor_right = 1.0 anchor_bottom = 0.5 margin_top = -54.0 margin_bottom = 48.0 -custom_fonts/font = SubResource( 4 ) +custom_fonts/font = SubResource( 5 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) text = "First to 3 points wins! W/S - Player 1 Up/Down diff --git a/Sounds/goal.wav b/Sounds/goal.wav Binary files differ. diff --git a/Sounds/goal.wav.import b/Sounds/goal.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/goal.wav-0665d38b229f2397d1e3558d75a93c2c.sample" + +[deps] + +source_file="res://Sounds/goal.wav" +dest_files=[ "res://.import/goal.wav-0665d38b229f2397d1e3558d75a93c2c.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=true +edit/normalize=true +edit/loop=false +compress/mode=0 diff --git a/Sounds/png-fx.a2m b/Sounds/png-fx.a2m Binary files differ. diff --git a/Sounds/pong.wav b/Sounds/pong.wav Binary files differ. diff --git a/Sounds/pong.wav.import b/Sounds/pong.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/pong.wav-777e676839e201c7acccf722c4741e2e.sample" + +[deps] + +source_file="res://Sounds/pong.wav" +dest_files=[ "res://.import/pong.wav-777e676839e201c7acccf722c4741e2e.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=true +edit/normalize=true +edit/loop=false +compress/mode=0 diff --git a/default_bus_layout.tres b/default_bus_layout.tres @@ -0,0 +1,9 @@ +[gd_resource type="AudioBusLayout" format=2] + +[resource] +bus/1/name = "FX" +bus/1/solo = false +bus/1/mute = false +bus/1/bypass_fx = false +bus/1/volume_db = 0.0 +bus/1/send = "Master"