forked from Rapidjonte/NESTRIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.lua
More file actions
70 lines (61 loc) · 2.18 KB
/
block.lua
File metadata and controls
70 lines (61 loc) · 2.18 KB
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
local Block = Class:extend()
function colorHEX(rgba)
local rb = tonumber(string.sub(rgba, 2, 3), 16)
local gb = tonumber(string.sub(rgba, 4, 5), 16)
local bb = tonumber(string.sub(rgba, 6, 7), 16)
local ab = tonumber(string.sub(rgba, 8, 9), 16) or nil
return love.math.colorFromBytes( rb, gb, bb, ab )
end
function Block:new(x,y,c,s)
self.color = c
self.s = s or 1
self.x = x*self.s
self.y = y*self.s
return self
end
function Block:draw()
local x,y=self.x,self.y
if (self.color == "v1") then
love.graphics.setColor(colorHEX(colors[level+1][1]))
love.graphics.draw(v1b, x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
love.graphics.setColor(colorHEX(colors[level+1][2]))
love.graphics.draw(v1h,x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
elseif (self.color == "v2") then
love.graphics.setColor(colorHEX(colors[level+1][3]))
love.graphics.draw(v2b, x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
love.graphics.setColor(colorHEX(colors[level+1][4]))
love.graphics.draw(v2h,x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
elseif (self.color == "v3") then
love.graphics.setColor(colorHEX(colors[level+1][5]))
love.graphics.draw(v2b, x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
love.graphics.setColor(colorHEX(colors[level+1][6]))
love.graphics.draw(v2h, x*CELL_SIZE, y*CELL_SIZE, 0, CELL_SIZE/8*self.s)
end
end
function Block:horizontal_collide(amount)
if self.x+amount < 0 or self.x+amount >= COLUMNS then
return true
end
if field_data[self.y+1] and field_data[self.y+1][self.x+1+amount] ~= nil and field_data[self.y+1][self.x+1+amount] > 0 then
return true
end
return false
end
function Block:vertical_collide(amount)
if self.y+amount >= ROWS then
return true
end
if field_data[self.y+1+amount] and field_data[self.y+1+amount][self.x+1] ~= nil and field_data[self.y+1+amount][self.x+1] > 0 then
return true
end
return false
end
function Block:rotate(pivot, amount)
local dx = self.x - pivot.x
local dy = self.y - pivot.y
local rotated_x = dy * amount
local rotated_y = -dx * amount
self.x = pivot.x + rotated_x
self.y = pivot.y + rotated_y
end
return Block