2014-10-18 11:23:10 +00:00
|
|
|
Class = require 'hump.class'
|
2014-10-18 12:14:51 +00:00
|
|
|
require 'entities/rectangle'
|
2014-10-18 11:23:10 +00:00
|
|
|
require 'settings'
|
|
|
|
|
|
|
|
-- A level manages the level datastructure containing static blocks and level
|
|
|
|
-- specific data like global physics
|
|
|
|
|
|
|
|
-- Reset color to this before drawing each object
|
|
|
|
draw_base_color = {255, 255, 255, 255}
|
|
|
|
|
|
|
|
Level = Class{
|
|
|
|
init = function(self)
|
|
|
|
self.name = 'Default'
|
|
|
|
self.entity_list = {}
|
|
|
|
|
|
|
|
self.backgroundColor = {135, 206, 250, 255}
|
|
|
|
|
|
|
|
self.world = love.physics.newWorld(GRAVITY_X, GRAVITY_Y, true)
|
2014-10-18 12:14:51 +00:00
|
|
|
|
2014-10-18 12:59:39 +00:00
|
|
|
self:insertGround()
|
2014-10-18 11:23:10 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
delete = function(self)
|
|
|
|
for key, entity in pairs(self.entity_list) do
|
|
|
|
entity:delete()
|
|
|
|
end
|
|
|
|
self.entity_list = nil
|
|
|
|
end;
|
|
|
|
|
|
|
|
activate = function(self)
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
drawEntities = function(self)
|
|
|
|
for key, entity in pairs(self.entity_list) do
|
|
|
|
love.graphics.setColor(draw_base_color)
|
|
|
|
entity:draw()
|
|
|
|
end
|
|
|
|
love.graphics.setColor(draw_base_color)
|
|
|
|
end;
|
|
|
|
|
|
|
|
updateEntities = function(self, dt)
|
|
|
|
self.world:update(dt)
|
|
|
|
|
|
|
|
for key, entity in pairs(self.entity_list) do
|
|
|
|
entity:update(dt)
|
|
|
|
end
|
|
|
|
end;
|
2014-10-18 12:59:39 +00:00
|
|
|
|
|
|
|
insertGround = function(self)
|
|
|
|
groundImg = love.graphics.newImage('tiles/grasstop.png')
|
|
|
|
|
|
|
|
for i = 0, 64, 1 do
|
|
|
|
Rectangle(i * 16, 768, self, "static", 0, 16, 16, 0, groundImg)
|
|
|
|
end
|
|
|
|
end;
|
2014-10-18 11:23:10 +00:00
|
|
|
}
|