-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEnemy.gd
65 lines (47 loc) · 1.31 KB
/
Enemy.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
extends KinematicBody2D
const GRAVITY = 10
const FLOOR = Vector2(0,-1)
var velocity = Vector2()
var direction = -1
var is_dead = false
export(int) var speed = 35
export(int) var hp = 1
export(Vector2) var size = Vector2(1,1)
func _ready():
scale = size
pass
func dead(damage):
hp = hp - damage
if hp <= 0:
is_dead = true
velocity = Vector2(0,0)
$AnimatedSprite.play("dead")
#This is the bug for 3.1
#$CollisionShape2D.disabled = true
$CollisionShape2D.set_deferred("disabled",true)
$Timer.start()
if scale > Vector2(1,1):
get_parent().get_node("Screenshake").screen_shake(1,10,100)
# warning-ignore:unused_argument
func _physics_process(delta):
if is_dead == false:
velocity.x = speed * direction
if direction == -1:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("walk")
velocity.y = velocity.y + GRAVITY
velocity = move_and_slide(velocity, FLOOR)
if is_on_wall():
direction = direction * -1
$RayCast2D.position.x *= -1
if $RayCast2D.is_colliding() == false:
direction = direction * -1
$RayCast2D.position.x *= -1
if get_slide_count() > 0:
for i in range (get_slide_count()):
if "Player" in get_slide_collision(i).collider.name:
get_slide_collision(i).collider.dead()
func _on_Timer_timeout():
queue_free()