2019-04-20 22:51:56 +02:00
|
|
|
-- world2D.lua :: a basic 2D world based on bump2D.
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Copyright © 2019 Kazhnuz
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
]]
|
|
|
|
|
2019-04-22 08:35:07 +02:00
|
|
|
local cwd = (...):gsub('%.world2D$', '') .. "."
|
2019-04-20 22:51:56 +02:00
|
|
|
|
|
|
|
local BaseWorld = require(cwd .. "baseworld")
|
|
|
|
local World2D = BaseWorld:extend()
|
|
|
|
|
|
|
|
local Sti = require(cwd .. "libs.sti")
|
|
|
|
local Bump = require(cwd .. "libs.bump")
|
2019-04-29 11:21:41 +02:00
|
|
|
local CameraSystem = require(cwd .. "camera")
|
2019-04-20 22:51:56 +02:00
|
|
|
|
|
|
|
function World2D:new(scene, actorlist, mapfile)
|
2019-05-01 16:25:44 +02:00
|
|
|
World2D.super.new(self, scene, actorlist, mapfile)
|
2019-04-20 22:51:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- ACTORS FUNCTIONS
|
|
|
|
-- Wrappers around Bump2D functions
|
|
|
|
|
2019-05-01 16:25:44 +02:00
|
|
|
function World2D:initActors()
|
|
|
|
self.actors = Bump.newWorld(50)
|
|
|
|
end
|
|
|
|
|
2019-04-20 22:51:56 +02:00
|
|
|
function World2D:registerActor(actor)
|
|
|
|
return self.actors:add(actor, actor.x, actor.y, actor.w, actor.h)
|
|
|
|
end
|
|
|
|
|
|
|
|
function World2D:removeActor(actor)
|
|
|
|
return self.actors:remove(actor)
|
|
|
|
end
|
|
|
|
|
|
|
|
function World2D:moveActor(actor, x, y, filter)
|
|
|
|
return self.actors:move(actor, x, y, filter)
|
|
|
|
end
|
|
|
|
|
|
|
|
function World2D:queryRect(x, y, w, h)
|
|
|
|
return self.actors:queryRect(x, y, w, h)
|
|
|
|
end
|
|
|
|
|
|
|
|
function World2D:countActors()
|
|
|
|
return self.actors:countItems()
|
|
|
|
end
|
|
|
|
|
|
|
|
function World2D:getActors()
|
|
|
|
return self.actors:getItems()
|
|
|
|
end
|
|
|
|
|
|
|
|
return World2D
|