2018-05-23 01:40:45 -04:00
|
|
|
extends Area2D
|
|
|
|
|
|
|
|
signal dead
|
|
|
|
export (int) var SPEED
|
|
|
|
var screensize
|
|
|
|
|
|
|
|
# class member variables go here, for example:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "textvar"
|
2018-05-23 03:57:15 -04:00
|
|
|
var health = 150
|
2018-05-23 01:40:45 -04:00
|
|
|
var hit_timer = 1000
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
connect("area_entered", self, "hit")
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func hit(who):
|
|
|
|
health -= 10
|
|
|
|
# $AnimatedSprite.frame = 1
|
|
|
|
hit_timer = 0
|
|
|
|
|
|
|
|
var velocity = Vector2()
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if health <= 0:
|
2018-05-23 03:57:15 -04:00
|
|
|
emit_signal("dead", 300)
|
2018-05-23 01:40:45 -04:00
|
|
|
queue_free()
|
|
|
|
|
|
|
|
if hit_timer < 0.15:
|
|
|
|
hit_timer += delta
|
|
|
|
elif hit_timer < 0.25:
|
|
|
|
hit_timer += delta
|
|
|
|
else:
|
|
|
|
velocity.x -= 1
|
|
|
|
# $AnimatedSprite.frame = 0
|
|
|
|
# the player's movement vector
|
|
|
|
|
|
|
|
if velocity.length() > 0:
|
|
|
|
velocity = velocity.normalized() * SPEED
|
|
|
|
|
|
|
|
# var health_bar = Vector2(((health * 3) - 157), -273)
|
|
|
|
# $Line2D.set_point_position( 1, health_bar )
|
|
|
|
|
|
|
|
position += velocity * delta
|