Skip to content

Commit

Permalink
pause after scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBocch committed Apr 8, 2024
1 parent e449e89 commit dbc5688
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 23 deletions.
3 changes: 2 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ config_version=5
[application]

config/name="3dpong"
config/tags=PackedStringArray("project")
run/main_scene="res://scenes/menu/menu.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"
config/icon="res://showcase.png"

[dotnet]

Expand Down
12 changes: 8 additions & 4 deletions scenes/ball/ball.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var SPEED = 2.0
var accelerate_x
var accelerate_z
var bounces
var paused

var hit_audio

Expand All @@ -20,6 +21,7 @@ func initball():

# Called when the node enters the scene tree for the first time.
func _ready():
paused = true
randomize()
bounces = 0
initball()
Expand All @@ -29,10 +31,11 @@ func _ready():

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
self.position.x += SPEED * accelerate_x * delta
self.position.z += SPEED * accelerate_z * delta
if bounces % 2 == 0:
SPEED += 0.002
if not paused:
self.position.x += SPEED * accelerate_x * delta
self.position.z += SPEED * accelerate_z * delta
if bounces % 2 == 0:
SPEED += 0.002


func reset():
Expand All @@ -42,6 +45,7 @@ func reset():

position.x = 0
position.z = 0
paused = true


# hit right paddle
Expand Down
19 changes: 10 additions & 9 deletions scenes/paddle/leftpaddle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ extends Area3D

const SPEED = 5.0
var direction
var paused
# Called when the node enters the scene tree for the first time.
func _ready():
paused = true
direction = Vector3(self.position.x, self.position.y, self.position.z)
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#print("move paddle up {str}".format(counter))
# - z plane Vector3
# print(type_string(typeof(self.position)))
if Input.is_action_pressed("right_up"):
self.position.z += (-SPEED) * delta
elif Input.is_action_pressed("right_down"):
self.position.z += (SPEED) * delta

self.position.z = clamp(self.position.z, -1.45, 1.45)
if not paused:
if Input.is_action_pressed("right_up"):
self.position.z += (-SPEED) * delta
elif Input.is_action_pressed("right_down"):
self.position.z += (SPEED) * delta

self.position.z = clamp(self.position.z, -1.45, 1.45)


# how do we check if something entered body?
func reset():
self.position.z = 0
paused = true
18 changes: 11 additions & 7 deletions scenes/paddle/rightpaddle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ extends Area3D

const SPEED = 5.0
var direction
var paused
# Called when the node enters the scene tree for the first time.
func _ready():
paused = true
direction = Vector3(self.position.x, self.position.y, self.position.z)
pass # Replace with function body.

Expand All @@ -13,13 +15,15 @@ func _process(delta):
#print("move paddle up {str}".format(counter))
# - z plane Vector3
# print(type_string(typeof(self.position)))
if Input.is_action_pressed("ui_up"):
self.position.z += (self.position.z - SPEED) * delta
elif Input.is_action_pressed("ui_down"):
self.position.z += (self.position.z + SPEED) * delta

self.position.z = clamp(self.position.z, -1.45, 1.45)
# how do we check if something entered body?
if not paused:
if Input.is_action_pressed("ui_up"):
self.position.z += (self.position.z - SPEED) * delta
elif Input.is_action_pressed("ui_down"):
self.position.z += (self.position.z + SPEED) * delta

self.position.z = clamp(self.position.z, -1.45, 1.45)
# how do we check if something entered body?

func reset():
self.position.z = 0
paused = true
12 changes: 12 additions & 0 deletions scenes/playing/Timer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Timer

var ball
var s
# Called when the node enters the scene tree for the first time.
func _ready():
pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
22 changes: 21 additions & 1 deletion scenes/playing/play.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var left_pad_node
var right_pad_node
var scoreboard_node
var score
var timer

# Called when the node enters the scene tree for the first time.
func _ready():
Expand All @@ -18,7 +19,9 @@ func _ready():
right_pad_node = get_node("right")
scoreboard_node = get_node("scoreboard")
score = get_node("score")

timer = get_node("Timer")

print("timer started")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
Expand All @@ -36,6 +39,8 @@ func _on_left_area_entered(area):
ball_node.reset()
left_pad_node.reset()
right_pad_node.reset()
timer.start()


func _on_right_area_entered(area):
score.play()
Expand All @@ -48,3 +53,18 @@ func _on_right_area_entered(area):
ball_node.reset()
left_pad_node.reset()
right_pad_node.reset()

timer.start()
ball_node.paused = true
left_pad_node.paused = true
right_pad_node.paused = true
print(ball_node.paused)


func _on_timer_timeout():

print("timer ended")
ball_node.paused = false
left_pad_node.paused = false
right_pad_node.paused = false

9 changes: 8 additions & 1 deletion scenes/playing/play.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://4w524me1s4ot"]
[gd_scene load_steps=25 format=3 uid="uid://4w524me1s4ot"]

[ext_resource type="PackedScene" uid="uid://daqresh0q8s4n" path="res://scenes/paddle/paddle.tscn" id="1_5dmrk"]
[ext_resource type="Texture2D" uid="uid://bbdh6vbxld618" path="res://assets/textures/texture_09.png" id="1_f4fjx"]
Expand All @@ -11,6 +11,7 @@
[ext_resource type="FontFile" uid="uid://c5xdnn7vexcaj" path="res://assets/fonts/VCR_OSD_MONO_.ttf" id="9_0nx3c"]
[ext_resource type="Script" path="res://scenes/playing/scoreboard.gd" id="9_3o6u0"]
[ext_resource type="AudioStream" uid="uid://dj5exhbmkg37g" path="res://scenes/playing/score.wav" id="11_pc2m1"]
[ext_resource type="Script" path="res://scenes/playing/Timer.gd" id="12_esvi2"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_puux4"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
Expand Down Expand Up @@ -157,9 +158,15 @@ script = ExtResource("9_3o6u0")
[node name="score" type="AudioStreamPlayer" parent="."]
stream = ExtResource("11_pc2m1")

[node name="Timer" type="Timer" parent="."]
process_callback = 0
autostart = true
script = ExtResource("12_esvi2")

[connection signal="area_entered" from="areana/walls/top" to="ball" method="_on_top_area_entered"]
[connection signal="area_entered" from="areana/walls/bot" to="ball" method="_on_bot_area_entered"]
[connection signal="area_entered" from="areana/score_zone/left" to="." method="_on_left_area_entered"]
[connection signal="area_entered" from="areana/score_zone/right" to="." method="_on_right_area_entered"]
[connection signal="area_entered" from="left" to="ball" method="_on_left_area_entered"]
[connection signal="area_entered" from="right" to="ball" method="_on_right_area_entered"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
Binary file added scenes/playing/showcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions scenes/playing/showcase.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bo6l3830cw0bg"
path="res://.godot/imported/showcase.png-5476fe19852226c5687b72db5d227bcb.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/playing/showcase.png"
dest_files=["res://.godot/imported/showcase.png-5476fe19852226c5687b72db5d227bcb.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added showcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions showcase.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://1y1orw86fcqn"
path="res://.godot/imported/showcase.png-0c3959f5f640e6f630709fe710632184.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://showcase.png"
dest_files=["res://.godot/imported/showcase.png-0c3959f5f640e6f630709fe710632184.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

0 comments on commit dbc5688

Please sign in to comment.