forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
miniblock.lua
57 lines (46 loc) · 1.4 KB
/
miniblock.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
miniblock = class("miniblock")
function miniblock:init(x, y, i)
self.x = x+math.random()*0.8-0.4
self.y = y
self.i = i
self.speedy = -10
self.timer = math.pi*1.5
end
function miniblock:update(dt)
self.speedy = self.speedy + yacceleration*dt
--check for collision
local x = math.floor(self.x)+1
local y = math.floor(self.y+self.speedy*dt)+1
if inmap(x, y) and self.speedy > 0 and tilequads[map[x][y][1]]:getproperty("collision", x, y) then
self.y = math.ceil(self.y)
self.speedy = 0
self.timer = self.timer + dt*3
end
if self.timer > 5 then
--check for player pickup
for i = 1, players do
local x = objects["player"][i].x+objects["player"][i].width
local y = objects["player"][i].y+objects["player"][i].height
if math.abs(self.x-x) + math.abs(self.y-y) < 1 then
if collectblock(self.i) then
return true
end
end
end
end
self.y = self.y + self.speedy*dt
if self.y > 16 then
return true
end
return false
end
function miniblock:draw()
local img = customtilesimg
if self.i <= smbtilecount then
img = smbtilesimg
elseif self.i <= smbtilecount+portaltilecount then
img = portaltilesimg
end
local yadd = math.sin(self.timer)*0.1+0.15
love.graphics.drawq(img, tilequads[self.i]:quad(), math.floor((self.x-xscroll)*16*scale), math.floor((self.y-yscroll-.5-yadd)*16*scale), 0, scale/2, scale/2, 8, 16)
end