Creating a Tile Map of Classes? [Fixed]
Posted: Thu Jan 12, 2012 1:41 am
Hello I'm relatively new at programming and I was attempting to create a tiled game. What I did was create a Wall Tile Class and then I used some of the code in the Tiling tutorials in attempt to initialize, draw, and update the class in accordance to a Tile map... I utterly failed. I dont' get an error, but the titles refuse to show up. Can anybody help out here?
If anybody needs some information on what I did or what I was trying to do just ask.
Code: Select all
require("lib/SECS")
require("Circle")
require("WallTile")
gamestate = require ("lib/hump/gamestate")
level1 = gamestate.new() -- I added a gamestate libary that should help
-- Tile Stuff
tile = {}
tile[1] = WallTile:new()
map_w = 20
map_h = 15
map_x = 0
map_y = 0
map_offset_x = 30
map_offset_y = 30
tile_w = 48
tile_h = 48
--Tile Stuff
function love.load(dt)
gamestate.registerEvents() -- Calling the GameStates
gamestate.switch(level1) -- Ofcourse this will eventually be the into or menu
end
function love.draw()
love.graphics.setColor(255,255,255)
love.graphics.print( "V 0.0001", 100, 10, 0, 1.5,1.5)
end
function level1:init()
entity = Entity:new()
entity:init(0,0,40,40)
map={ -- My friends, we have a tile map for level1
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
initTiles() -- Initiating the tiles
end
function level1:enter()
-- Runs every time it enters the game state.
end
function level1:update(dt)
entity:update(dt)
end
function level1:draw()
entity:draw()
drawTiles()
end
function initTiles()
for y=1, map_h do
for x=1, map_w do
if tile[map[y+map_y][x+map_x]] == 1 then -- if it's a wall tile
tile[map[y+map_y][x+map_x]]:init((x*tile_w)+map_offset_x,(y*tile_h)+map_offset_y ) -- What the fuck just happened?
end
end
end
end
function drawTiles()
for y=1, map_h do
for x=1, map_w do
if tile[map[y+map_y][x+map_x]] == 1 then -- if it's a wall tile
tile[map[y+map_y][x+map_x]]:draw()
end
end
end
end