-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelephant.p8
75 lines (68 loc) · 1.6 KB
/
elephant.p8
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
66
67
68
69
70
71
72
73
74
75
pico-8 cartridge // http://www.pico-8.com
version 38
__lua__
elephant=animal:new{
x=0,
y=0,
sprite=3,
width=2,
height=2,
stomp_t=15,
curr_stomp_t=0,
stomp_t_increase=true,
anim_t=5,
curr_anim_t=0,
shadow=nil,
is_friendly=true,
cost=3,
pwidth=16,
dmg=0.1,
health=800,
max_health=800
}
function elephant:draw()
spr(self.sprite,self.x,self.y,self.width,self.height)
end
function elephant:update()
local can_move, coll = self.collider:can_move(self)
if coll then
elephant:do_damage(coll)
end
if self.stomp_t_increase then
self.curr_stomp_t+=1
self.curr_anim_t+=1
if can_move then
self.x+=0.5
end
if self.curr_stomp_t>=self.stomp_t then
self.curr_stomp_t=self.stomp_t
self.stomp_t_increase=false
end
if self.curr_anim_t>=self.anim_t then
if self.sprite==3 then
self.sprite=35
self.y-=1
else
self.sprite=3
self.y+=1
end
self.curr_anim_t=0
end
else
self.curr_stomp_t-=1
if self.curr_stomp_t<=0 then
self.curr_stomp_t=0
self.stomp_t_increase=true
end
end
if self.health < self.max_health and not self.show_health then
self.show_health = true
add_health_bar(self,3,-4,9,1,3)
end
if self.health <=0 then
self.show_health = false
del(objects, self)
end
self.collider:update()
remove_if_out_of_bounds(self)
end