forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheepcheep.lua
153 lines (127 loc) · 2.94 KB
/
cheepcheep.lua
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
cheepcheep = class:new()
function cheepcheep:init(x, y, color)
self.x = x
self.y = y
self.starty = y
self.width = 12/16
self.height = 12/16
self.rotation = 0 --for portals
if math.random(2) == 1 then
self.verticalmoving = true
else
self.verticalmoving = false
end
self.color = color
self.active = true
self.static = false
self.autodelete = true
self.gravity = 0
self.category = 24
--IMAGE STUFF
self.drawable = true
self.graphic = cheepcheepimg
self.quad = cheepcheepquad[self.color][1]
self.offsetX = 6
self.offsetY = 3
self.quadcenterX = 8
self.quadcenterY = 8
self.portalable = false
self.mask = { true,
true, false, true, true, true,
true, true, true, true, true,
true, false, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true}
self.speedy = 0
if self.color == 1 then
self.speedx = -cheepredspeed
else
self.speedx = -cheepwhitespeed
end
self.direction = "up"
self.animationtimer = 0
self.shot = false
end
function cheepcheep:update(dt)
--rotate back to 0 (portals)
if self.rotation > 0 then
self.rotation = self.rotation - portalrotationalignmentspeed*dt
if self.rotation < 0 then
self.rotation = 0
end
elseif self.rotation < 0 then
self.rotation = self.rotation + portalrotationalignmentspeed*dt
if self.rotation > 0 then
self.rotation = 0
end
end
if self.shot then
self.speedy = self.speedy + shotgravity*dt
self.x = self.x+self.speedx*dt
self.y = self.y+self.speedy*dt
return false
else
self.animationtimer = self.animationtimer + dt
while self.animationtimer > cheepanimationspeed do
self.animationtimer = self.animationtimer - cheepanimationspeed
if self.frame == 1 then
self.frame = 2
else
self.frame = 1
end
self.quad = cheepcheepquad[self.color][self.frame]
end
--move up and down
if self.verticalmoving then
if self.direction == "up" then
self.speedy = -cheepyspeed
if self.y < self.starty - cheepheight then
self.direction = "down"
end
else
self.speedy = cheepyspeed
if self.y > self.starty + cheepheight then
self.direction = "up"
end
end
end
return false
end
end
function cheepcheep:shotted(dir) --fireball, star, turtle
playsound(shotsound)
self.shot = true
self.active = false
self.gravity = shotgravity
self.speedy = -shotjumpforce
self.direction = dir or "right"
if self.direction == "left" then
self.speedx = -shotspeedx
else
self.speedx = shotspeedx
end
end
function cheepcheep:rightcollide(a, b)
if self:globalcollide() then
return false
end
end
function cheepcheep:leftcollide(a, b)
if self:globalcollide() then
return false
end
end
function cheepcheep:ceilcollide(a, b)
if self:globalcollide() then
return false
end
end
function cheepcheep:floorcollide(a, b)
if self:globalcollide() then
return false
end
end
function cheepcheep:globalcollide(a, b)
return true
end