Hsif/Scripts/Player.gd

54 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-04-09 21:28:02 -04:00
extends CharacterBody2D
var speed = 750
var sprite = Sprite2D
var hurtTimer = 0
var hurt = false
var lives = 3
# Called when the node enters the scene tree for the first time.
func _ready():
sprite = $FishSprite
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
movement()
animation()
damage()
func movement():
var direction = Input.get_vector("Left","Right","Up","Down")
velocity = direction * speed
move_and_slide()
func animation():
if Input.is_action_just_pressed("Left"):
sprite.flip_h = false
sprite.position = Vector2(11, 0)
if Input.is_action_just_pressed("Right"):
sprite.flip_h = true
sprite.position = Vector2(-49, 0)
func damage():
if hurtTimer > 0 && hurtTimer % 2 == 0:
sprite.visible = false
if hurtTimer > 0 && hurtTimer % 2 == 1:
sprite.visible = true
if hurt == true && hurtTimer == 0:
var direction = Input.get_vector("Left","Right","Up","Down")
velocity = -direction * speed * 10
move_and_slide()
lives -= 1
hurt = false
hurtTimer = 60
else: if hurt == true && hurtTimer != 0:
var direction = Input.get_vector("Left","Right","Up","Down")
velocity = -direction * speed * 10
move_and_slide()
hurt = false
if hurtTimer != 0:
hurtTimer -= 1