-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slime.gd
53 lines (42 loc) · 940 Bytes
/
Slime.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
extends Character
const UP = Vector2(0,-1)
const JUMP = -500
const GRAVITY = 20
const SPEED = 50
const DECAYTIME = 3
var landed = false
func _ready():
maxhealth = 3
health = 3
pass
var timeOffScreen = 0
func get_pos():
return self.position + get_node("..").position
func _process(delta):
"""
if timeOffScreen > DECAYTIME:
queue_free()
if $VisibilityNotifier2D.is_on_screen():
timeOffScreen = 0
else:
timeOffScreen += delta
"""
pass
func _physics_process(delta):
var pos = get_pos()
motion.y += GRAVITY
var target = sign(get_node("../../../player").position.x-pos.x)*SPEED
motion.x = lerp(motion.x,target,0.05)
if is_on_floor():
if not landed:
landed = true
$Sprite.frame = 0
if $Sprite.frame >= 2:
motion.y = JUMP
else:
landed = false
motion = move_and_slide(motion,UP)
self.modulate.b = float(health)/maxhealth
self.modulate.g = float(health)/maxhealth
if (health == 0):
queue_free()