added the option for iframes

This commit is contained in:
pennyrigate 2023-02-20 00:48:01 -05:00
parent 19dd1809a2
commit 39a6c027c4
3 changed files with 56 additions and 39 deletions

View file

@ -50,6 +50,7 @@ tile_data = PoolIntArray( 851973, 0, 65537, 851976, 1, 0, 917512, 1, 0, 983048,
[node name="Player" parent="." instance=ExtResource( 2 )] [node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 48, 144 ) position = Vector2( 48, 144 )
use_iframes = true
[node name="Boss1" parent="." instance=ExtResource( 1 )] [node name="Boss1" parent="." instance=ExtResource( 1 )]
position = Vector2( 168, 112 ) position = Vector2( 168, 112 )

View file

@ -4,6 +4,7 @@ const ArrowProjectile = preload("res://objects/player/arrow_projectile.tscn")
##CLEAN UP CODE LATER ##CLEAN UP CODE LATER
##Movement ##Movement
export var use_iframes = false
export var walk_speed = 50 export var walk_speed = 50
export var gravity = 12 export var gravity = 12
export var max_fall_speed = INF export var max_fall_speed = INF
@ -18,11 +19,13 @@ onready var sword_sprite = $SwordSprite
onready var sword_hitbox = $SwordArea onready var sword_hitbox = $SwordArea
onready var death_particles = $DeathSplatter onready var death_particles = $DeathSplatter
onready var dust_particles = $DustParticles onready var dust_particles = $DustParticles
onready var iframe_timer = $IframeTimer
#Map #Map
onready var map = get_owner() onready var map = get_owner()
##States ##States
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT,INACTIVE,TRANSPORT} enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT,INACTIVE,TRANSPORT}
var current_state = State.IDLE var current_state = State.IDLE
var can_die = true
##Runtime ##Runtime
var axis = Vector2.ZERO #Current direction being held var axis = Vector2.ZERO #Current direction being held
var trail_color = Color(0.25,0,1,0.4) var trail_color = Color(0.25,0,1,0.4)
@ -296,46 +299,51 @@ func exit_transport():
current_state = State.FALL current_state = State.FALL
func die(): func die():
Game.ac_climb.set_stream(null) # stop climbing sound\ if can_die:
#If the player is already dead, don't kill them again Game.ac_climb.set_stream(null) # stop climbing sound\
if current_state == State.INACTIVE: #If the player is already dead, don't kill them again
return if current_state == State.INACTIVE:
#Create particles return
var new_particles = death_particles.duplicate() #Create particles
get_parent().add_child(new_particles) var new_particles = death_particles.duplicate()
new_particles.global_position = global_position get_parent().add_child(new_particles)
new_particles.emitting = true new_particles.global_position = global_position
sprite.visible = false new_particles.emitting = true
current_state = State.INACTIVE # Set to state where player is not controllable sprite.visible = false
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 current_state = State.INACTIVE # Set to state where player is not controllable
Game.play_sound(Game.a_gover, Game.ac_die) position = Game.respawn_point # Set respawn point
#Slow down time if Game.lives <= 0 && Game.use_lives:
var time_tween = get_tree().create_tween() #Gover
time_tween.tween_property(Engine, "time_scale", 0.1, 0.3) #Particles
Game.ac_music.stop() new_particles.amount = 64
yield(time_tween, "finished") #Resume from freeze frame new_particles.lifetime = 0.45
yield(get_tree().create_timer(1.0 * 0.1), "timeout") new_particles.speed_scale = 1.5
Game.call_deferred("restart_level") current_state = State.INACTIVE # Set to state where player is not controllable
else: Game.play_sound(Game.a_gover, Game.ac_die)
#Die #Slow down time
Game.lives -= 1 var time_tween = get_tree().create_tween()
Game.deaths += 1 time_tween.tween_property(Engine, "time_scale", 0.1, 0.3)
Game.play_sound(Game.a_die, Game.ac_die) Game.ac_music.stop()
yield(Game.freeze_frame(0.3), "timeout") yield(time_tween, "finished") #Resume from freeze frame
#Reduce points if playing in infinite lives mode yield(get_tree().create_timer(1.0 * 0.1), "timeout")
if Game.use_lives == false && Game.lives < 0: Game.call_deferred("restart_level")
Game.score = max(0,Game.score - 500) 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 #Respawn player
current_state = State.IDLE current_state = State.IDLE
sprite.visible = true sprite.visible = true
func _on_AnimationPlayer_animation_finished(anim_name): func _on_AnimationPlayer_animation_finished(anim_name):
if current_state == State.INACTIVE: if current_state == State.INACTIVE:
@ -371,3 +379,7 @@ func _on_SwordArea_area_entered(area):
func _on_Area2D_body_entered(body): func _on_Area2D_body_entered(body):
if body.is_in_group("death"): die() if body.is_in_group("death"): die()
func _on_IframeTimer_timeout():
can_die = true

View file

@ -711,6 +711,10 @@ scale_amount = 0.25
scale_amount_random = 0.5 scale_amount_random = 0.5
scale_amount_curve = SubResource( 43 ) 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="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"] [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="area_entered" from="SwordArea" to="." method="_on_SwordArea_area_entered"]
[connection signal="timeout" from="IframeTimer" to="." method="_on_IframeTimer_timeout"]