refactor(levels): port world to gamecore World2D
This commit is contained in:
parent
65a7ffd437
commit
042a2397a1
|
@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
|
||||
- **levels:** assets are now loaded from an asset file
|
||||
|
||||
- **levels:** World is now a gamecore World2D derivative
|
||||
|
||||
### Removed
|
||||
|
||||
- **main:** All functions already provided by gamecore have been removed.
|
||||
|
|
|
@ -45,11 +45,11 @@ function Entity:update(dt)
|
|||
end
|
||||
|
||||
function Entity:register()
|
||||
self.world:addEntity(self, self.x, self.y, self.w, self.h)
|
||||
self.world:registerActor(self)
|
||||
end
|
||||
|
||||
function Entity:destroy()
|
||||
self.world:removeEntity(self)
|
||||
self.world:removeActor(self)
|
||||
end
|
||||
|
||||
function Entity:canBounce(bounce)
|
||||
|
@ -105,7 +105,7 @@ function Entity:getCenter()
|
|||
end
|
||||
|
||||
function Entity:purge()
|
||||
self.world:removeEntity(self)
|
||||
self:remove()
|
||||
end
|
||||
|
||||
function Entity:setFilter()
|
||||
|
@ -124,7 +124,7 @@ function Entity:move(dt)
|
|||
self.onGround = false
|
||||
local xsp, ysp = self.xsp * dt, self.ysp * dt
|
||||
local cols, cols_len
|
||||
self.x, self.y, cols, cols_len = self.world:moveEntity(self, self.x + xsp, self.y + ysp, self.filter)
|
||||
self.x, self.y, cols, cols_len = self.world:moveActor(self, self.x + xsp, self.y + ysp, self.filter)
|
||||
|
||||
for i=1, cols_len do
|
||||
local col = cols[i]
|
||||
|
|
|
@ -43,7 +43,7 @@ function PlayerManager:spawnPlayer(playerID)
|
|||
end
|
||||
|
||||
function PlayerManager:getPlayers()
|
||||
local itemList = self.scene.world:getEntities()
|
||||
local itemList = self.scene.world:getActors()
|
||||
local playerList = {}
|
||||
|
||||
for i,v in ipairs(itemList) do
|
||||
|
@ -56,7 +56,7 @@ function PlayerManager:getPlayers()
|
|||
end
|
||||
|
||||
function PlayerManager:getPlayerByID(id)
|
||||
local itemList = self.scene.world:getEntities()
|
||||
local itemList = self.scene.world:getActors()
|
||||
local player
|
||||
|
||||
if (id == nil) then
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
local World = Object:extend()
|
||||
local World2D = require "core.modules.world.world2D"
|
||||
local World = World2D:extend()
|
||||
|
||||
local Obj = require "scenes.levels.entities"
|
||||
|
||||
local Sti = require "libs.sti"
|
||||
local Bump = require "libs.bump"
|
||||
|
||||
-- INIT FUNCTIONS
|
||||
-- All functions to init the world and the map
|
||||
|
@ -12,7 +12,7 @@ function World:new(scene, mapfile)
|
|||
self.scene = scene
|
||||
self.map = Sti("assets/maps/" .. mapfile .. ".lua")
|
||||
self.obj = Obj
|
||||
self.entities = Bump.newWorld(50)
|
||||
self:initActors()
|
||||
self.backcolor = self.map.backgroundcolor or {0, 0, 0}
|
||||
|
||||
self.activeObjects = 0
|
||||
|
@ -91,33 +91,6 @@ function World:addCollision(x, y, w, h, name)
|
|||
self.obj.Collision(self.scene, x, y, w, h, name)
|
||||
end
|
||||
|
||||
-- ENTITY MANAGEMENT FUNCTIONS
|
||||
-- All BUMP2D wrappers
|
||||
|
||||
function World:addEntity(entity)
|
||||
return self.entities:add(entity, entity.x, entity.y, entity.w, entity.h)
|
||||
end
|
||||
|
||||
function World:moveEntity(entity, x, y, filter)
|
||||
return self.entities:move(entity, x, y, filter)
|
||||
end
|
||||
|
||||
function World:removeEntity(entity)
|
||||
return self.entities:remove(entity)
|
||||
end
|
||||
|
||||
function World:queryRect(x, y, w, h)
|
||||
return self.entities:queryRect(x, y, w, h)
|
||||
end
|
||||
|
||||
function World:countEntities()
|
||||
return self.entities:countItems()
|
||||
end
|
||||
|
||||
function World:getEntities()
|
||||
return self.entities:getItems()
|
||||
end
|
||||
|
||||
-- MAP FUNCTIONS
|
||||
-- All map wrappers
|
||||
|
||||
|
|
Loading…
Reference in New Issue