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,6 +299,7 @@ func exit_transport():
current_state = State.FALL current_state = State.FALL
func die(): func die():
if can_die:
Game.ac_climb.set_stream(null) # stop climbing sound\ Game.ac_climb.set_stream(null) # stop climbing sound\
#If the player is already dead, don't kill them again #If the player is already dead, don't kill them again
if current_state == State.INACTIVE: if current_state == State.INACTIVE:
@ -332,6 +336,10 @@ func die():
#Reduce points if playing in infinite lives mode #Reduce points if playing in infinite lives mode
if Game.use_lives == false && Game.lives < 0: if Game.use_lives == false && Game.lives < 0:
Game.score = max(0,Game.score - 500) 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
@ -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"]