Skip to content

Commit

Permalink
game: add restart button
Browse files Browse the repository at this point in the history
  • Loading branch information
routrohan authored and agg-shambhavi committed Oct 28, 2020
1 parent 9c4b10d commit 3bf232d
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 29 deletions.
6 changes: 4 additions & 2 deletions Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ extends Camera2D
onready var topLeft = $Limits/TopLeft
onready var bottomRight = $Limits/BottomRight
onready var audioBg = $BackgroundMusic


func _ready():
limit_top = topLeft.position.y
limit_left = topLeft.position.x
limit_bottom = bottomRight.position.y
limit_right = bottomRight.position.x


func _process(delta):
if audioBg.playing == false:
audioBg.play()


8 changes: 7 additions & 1 deletion Enemies/Bat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ enum{

var velocity = Vector2.ZERO
var knockback = Vector2.ZERO

var state = CHASE

onready var sprite = $AnimatedSprite
Expand All @@ -26,9 +25,11 @@ onready var softCollision = $SoftCollision
onready var wanderController = $WanderController
onready var animationPlayer = $AnimationPlayer


func _ready():
state = pick_random_state([IDLE,WANDER])


func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, FRICTION * delta)
knockback = move_and_slide(knockback)
Expand Down Expand Up @@ -61,19 +62,23 @@ func _physics_process(delta):
velocity += softCollision.get_push_vector() * delta * 400
velocity = move_and_slide(velocity)


func accelerate_towards_point(point,delta):
var direction = global_position.direction_to(point)
velocity = velocity.move_toward(direction * MAX_SPEED, ACCELEARATION * delta)
sprite.flip_h = velocity.x < 0


func seek_player():
if playerDetectionZone.can_see_player():
state = CHASE


func update_wander():
state = pick_random_state([IDLE, WANDER])
wanderController.start_wander_timer(rand_range(1,3))


func pick_random_state(state_list):
state_list.shuffle()
return state_list.pop_front()
Expand All @@ -85,6 +90,7 @@ func _on_Hurtbox_area_entered(area):
hurtbox.create_hit_effect()
hurtbox.start_invincibility(0.4)


func _on_Stats_no_health():
queue_free()
var enemyDeathEffect = EnemyDeathEffect.instance()
Expand Down
5 changes: 5 additions & 0 deletions Game Over/GameOver.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
extends Control


func _on_Quit_pressed():
get_tree().quit()


func _on_Button_pressed():
get_tree().change_scene("res://menu/Menu.tscn")
20 changes: 18 additions & 2 deletions Game Over/GameOver.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,29 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -16.0
margin_left = 104.0
margin_top = 70.0
margin_right = 41.0
margin_right = 161.0
margin_bottom = 90.0
rect_scale = Vector2( 0.5, 0.5 )
text = "Quit"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Button" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -136.0
margin_top = 70.0
margin_right = -79.0
margin_bottom = 90.0
rect_scale = Vector2( 0.5, 0.5 )
text = "Restart"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Quit" to="." method="_on_Quit_pressed"]
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
5 changes: 5 additions & 0 deletions Game Over/GameOverWin.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
extends Control


func _on_Quit_pressed():
get_tree().quit()


func _on_Button_pressed():
get_tree().change_scene("res://menu/Menu.tscn")
27 changes: 23 additions & 4 deletions Game Over/GameOverWin.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,29 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -16.0
margin_top = 62.0
margin_right = 41.0
margin_bottom = 82.0
margin_left = 104.0
margin_top = 70.0
margin_right = 161.0
margin_bottom = 90.0
rect_scale = Vector2( 0.5, 0.5 )
text = "Quit"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Button" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -136.0
margin_top = 70.0
margin_right = -79.0
margin_bottom = 90.0
rect_scale = Vector2( 0.5, 0.5 )
text = "Restart"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Quit" to="." method="_on_Quit_pressed"]
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
51 changes: 37 additions & 14 deletions Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export var MAX_SPEED = 80
export var FRICTION = 500
export var ROLL_SPEED = 125


enum {
MOVE,
ROLL,
Expand All @@ -27,34 +26,42 @@ onready var animationState = animationTree.get("parameters/playback")
onready var swordHitbox = $HitboxPivot/SwordHitbox
onready var hurtbox = $Hurtbox
onready var blinkAnimationPlayer = $BlinkAnimationPlayer


onready var timer = get_node("Timer")
onready var timer2 = get_node("Timer2")


func _ready():
randomize()
stats.connect("no_health", self, "queue_free")
stats.connect("no_health", self, "game_over")
animationTree.active = true
swordHitbox.knockback_vector = roll_vector

func do_nothing():
pass


func game_over():
queue_free()
stats.health = 4
timer.set_wait_time(2)
timer.start()


func check_enemies():
total +=1
if total == 10:
playerHealth = 0
stats.health = 4
get_tree().change_scene("res://Game Over/GameOverWin.tscn")


func _physics_process(delta):

match state:
MOVE:
move_state(delta)
ROLL:
roll_state()
ATTACK:
attack_state()



func move_state(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
Expand All @@ -81,26 +88,32 @@ func move_state(delta):

if Input.is_action_just_pressed("attack"):
state = ATTACK



func roll_state():
velocity = roll_vector * ROLL_SPEED
animationState.travel("Roll")
move()



func attack_state():
velocity = Vector2.ZERO
animationState.travel("Attack")



func move():
velocity = move_and_slide(velocity )



func roll_animation_finished():
velocity = velocity * 0.8
state = MOVE


func attack_animation_finished():
state = MOVE


func _on_Hurtbox_area_entered(area):
stats.health -= area.damage
hurtbox.start_invincibility(0.6)
Expand All @@ -109,8 +122,11 @@ func _on_Hurtbox_area_entered(area):
get_tree().current_scene.add_child(playerHurtSound)
playerHealth += 1
if playerHealth == 4:
timer2.set_wait_time(2)
timer2.start()
get_tree().change_scene("res://Game Over/GameOver.tscn")


func _on_Hurtbox_invinciblity_started():
blinkAnimationPlayer.play("Start")

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



func _on_SwordHitbox_area_entered(area):
check_enemies()


func _on_Timer_timeout():
pass


func _on_Timer2_timeout():
pass
7 changes: 7 additions & 0 deletions Player/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -952,11 +952,18 @@ stream = ExtResource( 7 )
[node name="BlinkAnimationPlayer" type="AnimationPlayer" parent="."]
anims/Start = SubResource( 50 )
anims/Stop = SubResource( 51 )

[node name="Timer" type="Timer" parent="."]
one_shot = true

[node name="Timer2" type="Timer" parent="."]
[connection signal="area_entered" from="HitboxPivot/SwordHitbox" to="." method="_on_SwordHitbox_area_entered"]
[connection signal="area_entered" from="HitboxPivot/FlowerHitBox" to="." method="_on_FlowerHitBox_area_entered"]
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
[connection signal="invincibility_ended" from="Hurtbox" to="." method="_on_Hurtbox_invincibility_ended"]
[connection signal="invinciblity_started" from="Hurtbox" to="." method="_on_Hurtbox_invinciblity_started"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
[connection signal="timeout" from="Timer2" to="." method="_on_Timer2_timeout"]

[editable path="HitboxPivot/SwordHitbox"]

Expand Down
3 changes: 3 additions & 0 deletions Stats.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ signal no_health
signal health_changed(value)
signal max_health_changed(value)


func set_max_health(value):
max_health = value
self.health = min(health, max_health)
emit_signal("max_health_changed", max_health)


func set_health(value):
health = value
emit_signal("health_changed", health)
if health <= 0:
emit_signal("no_health")


func _ready():
self.health = max_health
3 changes: 0 additions & 3 deletions World.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,6 @@ points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 )
0/z_index = 0

[node name="World" type="Node2D"]
__meta__ = {
"_edit_lock_": true
}

[node name="SpookyGround" type="Sprite" parent="."]
position = Vector2( -174.931, 103.346 )
Expand Down
5 changes: 3 additions & 2 deletions World/Flower.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
extends Node2D

var stats = PlayerStats
export var flowerLife = 0


func create_flower_effect():
var FlowerEffect = load("res://Effects/FlowerEffect.tscn")
var flowerEffect = FlowerEffect.instance()
var world = get_tree().current_scene
world.add_child(flowerEffect)
flowerEffect.global_position = global_position
flowerLife += 1




func _on_FlowerHurtBox_area_entered(area):
create_flower_effect()
Expand Down
2 changes: 1 addition & 1 deletion menu/Menu.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extends Control

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


func _on_Settings_pressed():
get_tree().change_scene("res://menu/About.tscn") # Will load when parsing the script.
#sceneManager.pushScene(nextScene.instance())
Expand Down

0 comments on commit 3bf232d

Please sign in to comment.