This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/Scripts/Timeleton.gd
2022-06-18 13:05:48 +02:00

74 lines
2.2 KiB
GDScript

extends KinematicBody2D
export (int, 5, 1) var hp = 5
export (String, "INTRODUCE", "MOVING", "HIT", "DEATH") var bossState = "INTRODUCE"
var bossStatePrevious = "INTRODUCE"
var bossStateTimer = 0
export (bool) var activateMovement = true
var isBossKilled = false
func _ready():
gameController.logCall("Timeleton","_ready",null)
get_parent().get_node("BossHealth").setHp(hp,200)
$Sprite.playing = false
$Sprite.frame = 0
gameController.gamePaused = true
get_parent().get_node("AnimPlayer").current_animation = "BossIntroduce"
yield(get_tree().create_timer(2),"timeout")
bossState = "MOVING"
gameController.dialog("Timeleton","introduction")
func _process(_delta):
gameController.logCall("Timeleton","_ready",null)
if not gameController.gamePaused:
if bossState == "INTRODUCE":
bossState = "MOVING"
#animManager()
if activateMovement:
isKilled()
get_parent().get_node("BossHealth").hp = hp
func isKilled():
gameController.logCall("Timeleton","isKilled",null)
if hp <= 0:
if isBossKilled:
if not get_parent().get_node("AnimPlayer").is_playing():
queue_free()
else:
gameController.dialog("Timeleton","death")
yield(get_tree().create_timer(1),"timeout")
while true:
yield(get_tree().create_timer(0.1),"timeout")
if not gameController.gamePaused:
isBossKilled = true
bossState == "DEATH"
get_parent().get_node("AnimPlayer").play("BossDeath")
func hit():
gameController.logCall("Timeleton","hit",null)
func animManager():
bossStateTimer += 1
if bossState != bossStatePrevious:
bossStatePrevious = bossState
bossStateTimer = 0
gameController.logCall("Timeleton","animManager",null)
if bossState == "INTRODUCE":
pass
elif bossState == "MOVING":
$Sprite.animation = "Moving"
$Sprite.playing = true
elif bossState == "HIT":
$Sprite.animation = "Hit"
elif bossState == "DEATH":
$Sprite.animation = "Death"
func bossHitZoneEntered(body):
gameController.logCall("Timeleton","bossHitZoneEntered",body)
hp -= 1
get_parent().get_node("Player").move_and_slide(Vector2(0,200),Vector2(0,-1))
func playerHitZoneEntered(body):
gameController.logCall("Timeleton","playerHitZoneEntered",body)
if body.name == "Player":
body.event("death")