Skip to content

Commit 3bf232d

Browse files
routrohanagg-shambhavi
authored andcommitted
game: add restart button
1 parent 9c4b10d commit 3bf232d

12 files changed

+113
-29
lines changed

Camera2D.gd

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ extends Camera2D
33
onready var topLeft = $Limits/TopLeft
44
onready var bottomRight = $Limits/BottomRight
55
onready var audioBg = $BackgroundMusic
6+
7+
68
func _ready():
79
limit_top = topLeft.position.y
810
limit_left = topLeft.position.x
911
limit_bottom = bottomRight.position.y
1012
limit_right = bottomRight.position.x
13+
14+
1115
func _process(delta):
1216
if audioBg.playing == false:
1317
audioBg.play()
14-
15-

Enemies/Bat.gd

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ enum{
1515

1616
var velocity = Vector2.ZERO
1717
var knockback = Vector2.ZERO
18-
1918
var state = CHASE
2019

2120
onready var sprite = $AnimatedSprite
@@ -26,9 +25,11 @@ onready var softCollision = $SoftCollision
2625
onready var wanderController = $WanderController
2726
onready var animationPlayer = $AnimationPlayer
2827

28+
2929
func _ready():
3030
state = pick_random_state([IDLE,WANDER])
3131

32+
3233
func _physics_process(delta):
3334
knockback = knockback.move_toward(Vector2.ZERO, FRICTION * delta)
3435
knockback = move_and_slide(knockback)
@@ -61,19 +62,23 @@ func _physics_process(delta):
6162
velocity += softCollision.get_push_vector() * delta * 400
6263
velocity = move_and_slide(velocity)
6364

65+
6466
func accelerate_towards_point(point,delta):
6567
var direction = global_position.direction_to(point)
6668
velocity = velocity.move_toward(direction * MAX_SPEED, ACCELEARATION * delta)
6769
sprite.flip_h = velocity.x < 0
6870

71+
6972
func seek_player():
7073
if playerDetectionZone.can_see_player():
7174
state = CHASE
7275

76+
7377
func update_wander():
7478
state = pick_random_state([IDLE, WANDER])
7579
wanderController.start_wander_timer(rand_range(1,3))
7680

81+
7782
func pick_random_state(state_list):
7883
state_list.shuffle()
7984
return state_list.pop_front()
@@ -85,6 +90,7 @@ func _on_Hurtbox_area_entered(area):
8590
hurtbox.create_hit_effect()
8691
hurtbox.start_invincibility(0.4)
8792

93+
8894
func _on_Stats_no_health():
8995
queue_free()
9096
var enemyDeathEffect = EnemyDeathEffect.instance()

Game Over/GameOver.gd

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
extends Control
22

3+
34
func _on_Quit_pressed():
45
get_tree().quit()
6+
7+
8+
func _on_Button_pressed():
9+
get_tree().change_scene("res://menu/Menu.tscn")

Game Over/GameOver.tscn

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,29 @@ anchor_left = 0.5
4040
anchor_top = 0.5
4141
anchor_right = 0.5
4242
anchor_bottom = 0.5
43-
margin_left = -16.0
43+
margin_left = 104.0
4444
margin_top = 70.0
45-
margin_right = 41.0
45+
margin_right = 161.0
4646
margin_bottom = 90.0
4747
rect_scale = Vector2( 0.5, 0.5 )
4848
text = "Quit"
4949
__meta__ = {
5050
"_edit_use_anchors_": false
5151
}
52+
53+
[node name="Button" type="Button" parent="."]
54+
anchor_left = 0.5
55+
anchor_top = 0.5
56+
anchor_right = 0.5
57+
anchor_bottom = 0.5
58+
margin_left = -136.0
59+
margin_top = 70.0
60+
margin_right = -79.0
61+
margin_bottom = 90.0
62+
rect_scale = Vector2( 0.5, 0.5 )
63+
text = "Restart"
64+
__meta__ = {
65+
"_edit_use_anchors_": false
66+
}
5267
[connection signal="pressed" from="Quit" to="." method="_on_Quit_pressed"]
68+
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]

Game Over/GameOverWin.gd

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
extends Control
22

3+
34
func _on_Quit_pressed():
45
get_tree().quit()
6+
7+
8+
func _on_Button_pressed():
9+
get_tree().change_scene("res://menu/Menu.tscn")

Game Over/GameOverWin.tscn

+23-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,29 @@ anchor_left = 0.5
4040
anchor_top = 0.5
4141
anchor_right = 0.5
4242
anchor_bottom = 0.5
43-
margin_left = -16.0
44-
margin_top = 62.0
45-
margin_right = 41.0
46-
margin_bottom = 82.0
43+
margin_left = 104.0
44+
margin_top = 70.0
45+
margin_right = 161.0
46+
margin_bottom = 90.0
4747
rect_scale = Vector2( 0.5, 0.5 )
4848
text = "Quit"
49+
__meta__ = {
50+
"_edit_use_anchors_": false
51+
}
52+
53+
[node name="Button" type="Button" parent="."]
54+
anchor_left = 0.5
55+
anchor_top = 0.5
56+
anchor_right = 0.5
57+
anchor_bottom = 0.5
58+
margin_left = -136.0
59+
margin_top = 70.0
60+
margin_right = -79.0
61+
margin_bottom = 90.0
62+
rect_scale = Vector2( 0.5, 0.5 )
63+
text = "Restart"
64+
__meta__ = {
65+
"_edit_use_anchors_": false
66+
}
4967
[connection signal="pressed" from="Quit" to="." method="_on_Quit_pressed"]
68+
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]

Player/Player.gd

+37-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export var MAX_SPEED = 80
77
export var FRICTION = 500
88
export var ROLL_SPEED = 125
99

10-
1110
enum {
1211
MOVE,
1312
ROLL,
@@ -27,34 +26,42 @@ onready var animationState = animationTree.get("parameters/playback")
2726
onready var swordHitbox = $HitboxPivot/SwordHitbox
2827
onready var hurtbox = $Hurtbox
2928
onready var blinkAnimationPlayer = $BlinkAnimationPlayer
30-
31-
29+
onready var timer = get_node("Timer")
30+
onready var timer2 = get_node("Timer2")
3231

3332

3433
func _ready():
3534
randomize()
36-
stats.connect("no_health", self, "queue_free")
35+
stats.connect("no_health", self, "game_over")
3736
animationTree.active = true
3837
swordHitbox.knockback_vector = roll_vector
39-
40-
func do_nothing():
41-
pass
38+
39+
40+
func game_over():
41+
queue_free()
42+
stats.health = 4
43+
timer.set_wait_time(2)
44+
timer.start()
45+
4246

4347
func check_enemies():
4448
total +=1
4549
if total == 10:
50+
playerHealth = 0
51+
stats.health = 4
4652
get_tree().change_scene("res://Game Over/GameOverWin.tscn")
4753

54+
4855
func _physics_process(delta):
49-
5056
match state:
5157
MOVE:
5258
move_state(delta)
5359
ROLL:
5460
roll_state()
5561
ATTACK:
5662
attack_state()
57-
63+
64+
5865
func move_state(delta):
5966
var input_vector = Vector2.ZERO
6067
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
@@ -81,26 +88,32 @@ func move_state(delta):
8188

8289
if Input.is_action_just_pressed("attack"):
8390
state = ATTACK
84-
91+
92+
8593
func roll_state():
8694
velocity = roll_vector * ROLL_SPEED
8795
animationState.travel("Roll")
8896
move()
89-
97+
98+
9099
func attack_state():
91100
velocity = Vector2.ZERO
92101
animationState.travel("Attack")
93-
102+
103+
94104
func move():
95105
velocity = move_and_slide(velocity )
96-
106+
107+
97108
func roll_animation_finished():
98109
velocity = velocity * 0.8
99110
state = MOVE
100111

112+
101113
func attack_animation_finished():
102114
state = MOVE
103115

116+
104117
func _on_Hurtbox_area_entered(area):
105118
stats.health -= area.damage
106119
hurtbox.start_invincibility(0.6)
@@ -109,8 +122,11 @@ func _on_Hurtbox_area_entered(area):
109122
get_tree().current_scene.add_child(playerHurtSound)
110123
playerHealth += 1
111124
if playerHealth == 4:
125+
timer2.set_wait_time(2)
126+
timer2.start()
112127
get_tree().change_scene("res://Game Over/GameOver.tscn")
113128

129+
114130
func _on_Hurtbox_invinciblity_started():
115131
blinkAnimationPlayer.play("Start")
116132

@@ -125,6 +141,13 @@ func _on_FlowerHitBox_area_entered(area):
125141
stats.health += 1
126142

127143

128-
129144
func _on_SwordHitbox_area_entered(area):
130145
check_enemies()
146+
147+
148+
func _on_Timer_timeout():
149+
pass
150+
151+
152+
func _on_Timer2_timeout():
153+
pass

Player/Player.tscn

+7
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,18 @@ stream = ExtResource( 7 )
952952
[node name="BlinkAnimationPlayer" type="AnimationPlayer" parent="."]
953953
anims/Start = SubResource( 50 )
954954
anims/Stop = SubResource( 51 )
955+
956+
[node name="Timer" type="Timer" parent="."]
957+
one_shot = true
958+
959+
[node name="Timer2" type="Timer" parent="."]
955960
[connection signal="area_entered" from="HitboxPivot/SwordHitbox" to="." method="_on_SwordHitbox_area_entered"]
956961
[connection signal="area_entered" from="HitboxPivot/FlowerHitBox" to="." method="_on_FlowerHitBox_area_entered"]
957962
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
958963
[connection signal="invincibility_ended" from="Hurtbox" to="." method="_on_Hurtbox_invincibility_ended"]
959964
[connection signal="invinciblity_started" from="Hurtbox" to="." method="_on_Hurtbox_invinciblity_started"]
965+
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
966+
[connection signal="timeout" from="Timer2" to="." method="_on_Timer2_timeout"]
960967

961968
[editable path="HitboxPivot/SwordHitbox"]
962969

Stats.gd

+3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ signal no_health
77
signal health_changed(value)
88
signal max_health_changed(value)
99

10+
1011
func set_max_health(value):
1112
max_health = value
1213
self.health = min(health, max_health)
1314
emit_signal("max_health_changed", max_health)
1415

16+
1517
func set_health(value):
1618
health = value
1719
emit_signal("health_changed", health)
1820
if health <= 0:
1921
emit_signal("no_health")
2022

23+
2124
func _ready():
2225
self.health = max_health

World.tscn

-3
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,6 @@ points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 )
466466
0/z_index = 0
467467

468468
[node name="World" type="Node2D"]
469-
__meta__ = {
470-
"_edit_lock_": true
471-
}
472469

473470
[node name="SpookyGround" type="Sprite" parent="."]
474471
position = Vector2( -174.931, 103.346 )

World/Flower.gd

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
extends Node2D
2+
23
var stats = PlayerStats
34
export var flowerLife = 0
45

6+
57
func create_flower_effect():
68
var FlowerEffect = load("res://Effects/FlowerEffect.tscn")
79
var flowerEffect = FlowerEffect.instance()
810
var world = get_tree().current_scene
911
world.add_child(flowerEffect)
1012
flowerEffect.global_position = global_position
1113
flowerLife += 1
12-
13-
14+
1415

1516
func _on_FlowerHurtBox_area_entered(area):
1617
create_flower_effect()

menu/Menu.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
extends Control
22

3-
# Declare member variables here. Examples:
43
onready var sceneManager = get_node('/root/SceneManager')
54

5+
66
func _on_Settings_pressed():
77
get_tree().change_scene("res://menu/About.tscn") # Will load when parsing the script.
88
#sceneManager.pushScene(nextScene.instance())

0 commit comments

Comments
 (0)