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