-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
76 lines (54 loc) · 2.44 KB
/
main.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
require ("loq_util")
display.setStatusBar( display.HiddenStatusBar ) -- Get rid of that thing
display.setDefault ("magTextureFilter", "nearest") -- make it nice and pixeled
-- Test = display.newImage( "images/img_Backdrop2.png")
-- Some kind of map thing
--foot = display.newImage("mapTile1.png", 100, 100)
local myText = display.newText( "Hello TileMap!", 300, 0, native.systemFont, 16 )
local currentMap = {}
-- Set up the map. Best to NOT do this with hardcoded Numbers, so you can make minimaps, etc.
currentMap.mapWidth = 13 -- This is how many items(rows) are in 1 row of a map.
currentMap.mapHeigth = 12 -- This is how many down
currentMap.TileSizeSquare = 20 -- how many pixels a square
currentMap.mapData = {
2,2,3,1,1,1,1,1,1,1,1,1,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,2,
}
-- OK. We have a map. Now we draw it...
-- think of Y as Rows, and X as columns
local row = 0
local column =0
local mapLocation = 0
local myMapGroup = display.newGroup()
local tileNumber
local drawX = -10
local drawY = 0
for row=1, (currentMap.mapHeigth) do -- This will start at the top first row and work down
-- The reason it starts at 0 and to mapHeigth-1 is because of MAGIC STEP below...
for column=1, (currentMap.mapWidth) do
-- mapLocation = mapLocation + 1
drawX = drawX+ 20
tileNumber = currentMap.mapData [((currentMap.mapWidth*(row-1))+ (column) ) ]
-- print (currentMap.mapData [((currentMap.mapWidth*(row-1))+ (column) ) ] )
io.write (tileNumber) -- this will print the column in the Terminal
--Now that we have the correct tile, lets append the correct filename for the tile.
--currentTile = display.newImage( "/images/mapTile1.png" )
currentTile = display.newImage( "images/mapTile" .. tileNumber .. ".png" )
currentTile.x = 10
currentTile.y = 10
currentTile.x = currentTile.x + (column-1) * 20 -- more MAGIC STEP. since we set that first row to ZERO, if you are on it it won't multiply an extra 20
currentTile.y = currentTile.y + drawY
end
drawY = drawY + 20 -- this moves the tiledrawn down 1 on the app screen
io.write ("\n") -- This moves the terminal to the next line
end