Here is some very old code, but it has all the basics. Just a warning it is not commented.
My current code is nothing like this, but you gotta start somewhere
forgot you need image for a texture. tiles 66x66 and 660W and 660H
edit I removed all the redundant loops for updating the block one at a time…Sometimes you can’t see the forrest because of the trees. Now I need to look into translate and related functions
I was killing the gpu for no reson thanks Ignatz
-- create world
function setup()
world = worldCreate()
ellipseMode(RADIUS)
playerPos = vec2(HEIGHT/2,WIDTH/2)
maxMapDrag = vec2(250,250)
startDragX = 0
startDragY = 0
prevOffsetX = 0
prevOffsetY = 0
offsetX = 0
offsetY = 0
tX = 0
tY = 0
x=0
y=0
parameter.watch("setTween")
parameter.watch("tweenObject")
parameter.watch("startDragX")
parameter.watch("startDragY")
parameter.watch("endDragX")
parameter.watch("endDragY")
parameter.watch("prevOffsetX")
parameter.watch("prevOffsetY")
parameter.watch("offsetX")
parameter.watch("offsetY")
end
function draw()
background(0, 0, 0, 255)
translate(x,y)
world:draw()
end
function touched(touch)
x =x+touch.deltaX
y = y +touch.deltaY
--world:touched(touch)
end
--# worldCreate
worldCreate = class()
function worldCreate:init()
self.player ={x=1,y=2,health=10,attack=1,def=2,moves=10}
-- you can accept and set parameters here
self.player.x=1
-- self.player.y=1--"health" = 10, "ammo" = 10, "moves" = 10]
print(self.player.x.." "..self.player.y.." "..self.player.health)
wWidth = (WIDTH/66)*2
wHeight = (HEIGHT/66)*2
local grid = {}
local id = {}
local bid = {} -- block id
local worldOffsetY = 0
local worldOffsetX = 0
blocks = {}
img = readImage("Dropbox:TileMap660")
-- the image is the tileset andthe tileoffset is for moving the wholeworld
local tileWidth = 66
local tileWidth = 66
self.blocks = mesh() -- the rectangle mesh
self.blocks.texture = img -- the TIlemap
for i = 1,wWidth do
grid[i] = {}
for j = 1, wHeight do
grid[i][j] = math.random(6) -- random tile
end
end
for r,row in pairs(grid) do
id[r] = {}
bid[r] = {}
for c,col in pairs(row) do
--print(c)
-- add the rectangle to the mesh
id[r][c] = self.blocks:addRect(-33+ r*66,-33 + c*66,66,66)
tileCordList = {name = "grassTile", x = 1/10, y= 9/10}
tileCordList[2] = {name = "zombieTile", x = 2/10, y= 9/10}
tileCordList[2] = {name = "trapTile", x = 3/10, y= 9/10}
tileCordList[2] = {name = "hiddenTile", x = 4/10, y= 9/10}
tileCordList[2] = {name = "playerTile", x = 5/10, y= 9/10}
tileCordList[2] = {name = "goalTile", x = 6/10, y= 9/10}
if(grid[r][c] == 1) then
self.blocks:setRectTex(id[r][c], 1/10,9/10,66/660,66/660)
bid[r][c] = 1
elseif (grid[r][c] == 2) then
self.blocks:setRectTex(id[r][c],2/10,9/10,66/660,66/660)
bid[r][c] = 2
elseif (grid[r][c] == 3) then
self.blocks:setRectTex(id[r][c],3/10,9/10,66/660,66/660)
bid[r][c] = 3
elseif (grid[r][c] == 4) then
self.blocks:setRectTex(id[r][c],4/10,9/10,66/660,66/660)
bid[r][c] = 4
elseif (grid[r][c] == 5) then
self.blocks:setRectTex(id[r][c],4/10,9/10,66/660,66/660)
bid[r][c] = 5
elseif (grid[r][c] == 6) then
self.blocks:setRectTex(id[r][c],4/10,9/10,66/660,66/660)
bid[r][c] = 6
elseif (grid[r][c] == 10) then
self.blocks:setRectTex(id[r][c],3/10,5/10,66/660,66/660)
bid[r][c] = 10
print(" changed ")
end
end
end
self.grid = grid -- the holder for the world
--print(world)
self.id = id -- the id of the block 0 lower left col1 1,2...13 col2 1,2,..13 col3
self.bid = bid -- the tile type id's texture cordinates
end
function worldCreate:draw()
-- Codea does not automatically call this method
self.blocks:draw()
end
function worldCreate:touched(touch)
end