forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsquid.lua
185 lines (152 loc) · 3.82 KB
/
squid.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
squid = class:new()
function squid:init(x, y, color)
self.x = x-1+2/16
self.y = y-1+4/16
self.width = 12/16
self.height = 12/16
self.rotation = 0 --for portals
self.speedy = 0
self.speedx = 0
self.active = true
self.static = false
self.autodelete = true
self.gravity = 0
self.category = 30
--IMAGE STUFF
self.drawable = true
self.graphic = squidimg
self.quad = squidquad[1]
self.offsetX = 6
self.offsetY = 3
self.quadcenterX = 8
self.quadcenterY = 8
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.direction = "left"
self.timer = 0
self.state = "idle"
self.shot = false
end
function squid: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
--get nearest player
closestplayer = 1
for i = 2, players do
local v = objects["player"][i]
if math.abs(self.x - v.x) < math.abs(self.x - objects["player"][closestplayer].x) then
closestplayer = i
end
end
if self.state == "idle" then
self.speedy = squidfallspeed
--get if change state to upward
if (self.y+self.speedy*dt) + self.height + 0.0625 >= (objects["player"][closestplayer].y - (24/16 - objects["player"][closestplayer].height)) then
self.state = "upward"
self.upx = self.x
self.speedx = 0
self.speedy = 0
--get if to change direction
if true then--math.random(2) == 1 then
if self.direction == "right" then
if self.x > objects["player"][closestplayer].x then
self.direction = "left"
end
else
if self.x < objects["player"][closestplayer].x then
self.direction = "right"
end
end
end
end
elseif self.state == "upward" then
if self.direction == "right" then
self.speedx = self.speedx + squidacceleration*dt
if self.speedx > squidxspeed then
self.speedx = squidxspeed
end
else
self.speedx = self.speedx - squidacceleration*dt
if self.speedx < -squidxspeed then
self.speedx = -squidxspeed
end
end
self.speedy = self.speedy - squidacceleration*dt
if self.speedy < -squidupspeed then
self.speedy = -squidupspeed
end
if math.abs(self.x - self.upx) >= 2 then
self.state = "downward"
self.quad = squidquad[2]
self.downy = self.y
self.speedx = 0
end
elseif self.state == "downward" then
self.speedy = squidfallspeed
if self.y > self.downy + squiddowndistance then
self.state = "idle"
self.quad = squidquad[1]
end
end
self.x = self.x+self.speedx*dt
self.y = self.y+self.speedy*dt
return false
end
end
function squid: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 squid:rightcollide(a, b)
if self:globalcollide() then
return false
end
end
function squid:leftcollide(a, b)
if self:globalcollide() then
return false
end
end
function squid:ceilcollide(a, b)
if self:globalcollide() then
return false
end
end
function squid:floorcollide(a, b)
if self:globalcollide() then
return false
end
end
function squid:globalcollide(a, b)
return true
end