added the option for iframes
This commit is contained in:
parent
19dd1809a2
commit
39a6c027c4
3 changed files with 56 additions and 39 deletions
|
@ -4,6 +4,7 @@ const ArrowProjectile = preload("res://objects/player/arrow_projectile.tscn")
|
|||
|
||||
##CLEAN UP CODE LATER
|
||||
##Movement
|
||||
export var use_iframes = false
|
||||
export var walk_speed = 50
|
||||
export var gravity = 12
|
||||
export var max_fall_speed = INF
|
||||
|
@ -18,11 +19,13 @@ onready var sword_sprite = $SwordSprite
|
|||
onready var sword_hitbox = $SwordArea
|
||||
onready var death_particles = $DeathSplatter
|
||||
onready var dust_particles = $DustParticles
|
||||
onready var iframe_timer = $IframeTimer
|
||||
#Map
|
||||
onready var map = get_owner()
|
||||
##States
|
||||
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT,INACTIVE,TRANSPORT}
|
||||
var current_state = State.IDLE
|
||||
var can_die = true
|
||||
##Runtime
|
||||
var axis = Vector2.ZERO #Current direction being held
|
||||
var trail_color = Color(0.25,0,1,0.4)
|
||||
|
@ -296,46 +299,51 @@ func exit_transport():
|
|||
current_state = State.FALL
|
||||
|
||||
func die():
|
||||
Game.ac_climb.set_stream(null) # stop climbing sound\
|
||||
#If the player is already dead, don't kill them again
|
||||
if current_state == State.INACTIVE:
|
||||
return
|
||||
#Create particles
|
||||
var new_particles = death_particles.duplicate()
|
||||
get_parent().add_child(new_particles)
|
||||
new_particles.global_position = global_position
|
||||
new_particles.emitting = true
|
||||
sprite.visible = false
|
||||
current_state = State.INACTIVE # Set to state where player is not controllable
|
||||
position = Game.respawn_point # Set respawn point
|
||||
if Game.lives <= 0 && Game.use_lives:
|
||||
#Gover
|
||||
#Particles
|
||||
new_particles.amount = 64
|
||||
new_particles.lifetime = 0.45
|
||||
new_particles.speed_scale = 1.5
|
||||
if can_die:
|
||||
Game.ac_climb.set_stream(null) # stop climbing sound\
|
||||
#If the player is already dead, don't kill them again
|
||||
if current_state == State.INACTIVE:
|
||||
return
|
||||
#Create particles
|
||||
var new_particles = death_particles.duplicate()
|
||||
get_parent().add_child(new_particles)
|
||||
new_particles.global_position = global_position
|
||||
new_particles.emitting = true
|
||||
sprite.visible = false
|
||||
current_state = State.INACTIVE # Set to state where player is not controllable
|
||||
Game.play_sound(Game.a_gover, Game.ac_die)
|
||||
#Slow down time
|
||||
var time_tween = get_tree().create_tween()
|
||||
time_tween.tween_property(Engine, "time_scale", 0.1, 0.3)
|
||||
Game.ac_music.stop()
|
||||
yield(time_tween, "finished") #Resume from freeze frame
|
||||
yield(get_tree().create_timer(1.0 * 0.1), "timeout")
|
||||
Game.call_deferred("restart_level")
|
||||
else:
|
||||
#Die
|
||||
Game.lives -= 1
|
||||
Game.deaths += 1
|
||||
Game.play_sound(Game.a_die, Game.ac_die)
|
||||
yield(Game.freeze_frame(0.3), "timeout")
|
||||
#Reduce points if playing in infinite lives mode
|
||||
if Game.use_lives == false && Game.lives < 0:
|
||||
Game.score = max(0,Game.score - 500)
|
||||
|
||||
#Respawn player
|
||||
current_state = State.IDLE
|
||||
sprite.visible = true
|
||||
position = Game.respawn_point # Set respawn point
|
||||
if Game.lives <= 0 && Game.use_lives:
|
||||
#Gover
|
||||
#Particles
|
||||
new_particles.amount = 64
|
||||
new_particles.lifetime = 0.45
|
||||
new_particles.speed_scale = 1.5
|
||||
current_state = State.INACTIVE # Set to state where player is not controllable
|
||||
Game.play_sound(Game.a_gover, Game.ac_die)
|
||||
#Slow down time
|
||||
var time_tween = get_tree().create_tween()
|
||||
time_tween.tween_property(Engine, "time_scale", 0.1, 0.3)
|
||||
Game.ac_music.stop()
|
||||
yield(time_tween, "finished") #Resume from freeze frame
|
||||
yield(get_tree().create_timer(1.0 * 0.1), "timeout")
|
||||
Game.call_deferred("restart_level")
|
||||
else:
|
||||
#Die
|
||||
Game.lives -= 1
|
||||
Game.deaths += 1
|
||||
Game.play_sound(Game.a_die, Game.ac_die)
|
||||
yield(Game.freeze_frame(0.3), "timeout")
|
||||
#Reduce points if playing in infinite lives mode
|
||||
if Game.use_lives == false && Game.lives < 0:
|
||||
Game.score = max(0,Game.score - 500)
|
||||
#Iframes after respawn
|
||||
if use_iframes:
|
||||
iframe_timer.start()
|
||||
can_die = false
|
||||
|
||||
#Respawn player
|
||||
current_state = State.IDLE
|
||||
sprite.visible = true
|
||||
|
||||
func _on_AnimationPlayer_animation_finished(anim_name):
|
||||
if current_state == State.INACTIVE:
|
||||
|
@ -371,3 +379,7 @@ func _on_SwordArea_area_entered(area):
|
|||
|
||||
func _on_Area2D_body_entered(body):
|
||||
if body.is_in_group("death"): die()
|
||||
|
||||
|
||||
func _on_IframeTimer_timeout():
|
||||
can_die = true
|
||||
|
|
|
@ -711,6 +711,10 @@ scale_amount = 0.25
|
|||
scale_amount_random = 0.5
|
||||
scale_amount_curve = SubResource( 43 )
|
||||
|
||||
[node name="IframeTimer" type="Timer" parent="."]
|
||||
wait_time = 0.3
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
|
||||
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"]
|
||||
[connection signal="area_entered" from="SwordArea" to="." method="_on_SwordArea_area_entered"]
|
||||
[connection signal="timeout" from="IframeTimer" to="." method="_on_IframeTimer_timeout"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue