-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.lua
More file actions
51 lines (41 loc) · 956 Bytes
/
tile.lua
File metadata and controls
51 lines (41 loc) · 956 Bytes
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
Hex = require 'hex'
local Tile = class('Tile')
function Tile:initialize( x, y, tileLayer )
--Offset factor of each hex relative to its parent tile.
self.hexOffsets = {
{ 0,0 }
,{ cos30deg,0 }
,{ cos30deg * 1.5, -0.75 }
,{ cos30deg, -1.5 }
,{ 0, -1.5}
,{ -( cos30deg / 2 ), -0.75 }
,{ cos30deg / 2, -0.75 }
}
self.hexes = {}
self.x = x
self.y = y
self.layer = tileLayer
self:generateHexes()
end
function Tile:flip()
print('TILE FLIP')
for k,hex in ipairs(self.hexes) do
hex:flip()
end
end
function Tile:generateHexes()
for i=1,7 do
hex = Hex:new(i)
-- create a sprite and initialize it
hexSprite = MOAIProp2D.new ()
hexSprite:setDeck ( hex.hexQuad )
hexSprite:setLoc(
self.x + (self.hexOffsets[i][1] * (hex.quadHeight * 2) )
, self.y + (self.hexOffsets[i][2] * (hex.quadHeight * 2) )
)
hex.tilePosition = i
table.insert(self.hexes, hex)
self.layer:insertProp(hexSprite)
end
end
return Tile