modules/world: basic player system
This commit is contained in:
parent
b74be06d26
commit
bdd837d4da
2 changed files with 37 additions and 0 deletions
|
@ -20,6 +20,10 @@ function Actor2D:register()
|
||||||
self.world:registerActor(self)
|
self.world:registerActor(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Actor2D:getInput(keys)
|
||||||
|
self.keys = keys or core.input.fakekeys
|
||||||
|
end
|
||||||
|
|
||||||
function Actor2D:update(dt)
|
function Actor2D:update(dt)
|
||||||
-- here will be update actions
|
-- here will be update actions
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,8 @@ local Sti = require(cwd .. "libs.sti")
|
||||||
|
|
||||||
function BaseWorld:new(scene, actorlist, mapfile)
|
function BaseWorld:new(scene, actorlist, mapfile)
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
|
|
||||||
|
self:initPlayers()
|
||||||
self:setActorList(actorlist)
|
self:setActorList(actorlist)
|
||||||
self:setMap(mapfile)
|
self:setMap(mapfile)
|
||||||
self.actors = {}
|
self.actors = {}
|
||||||
|
@ -84,6 +86,36 @@ function BaseWorld:getActors()
|
||||||
return self.actors
|
return self.actors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- PLAYER MANAGEMENT FUNCTIONS
|
||||||
|
-- Basic function to handle player actors
|
||||||
|
|
||||||
|
function BaseWorld:initPlayers()
|
||||||
|
self.players = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseWorld:addPlayer(actor, sourceid)
|
||||||
|
local player = {}
|
||||||
|
player.actor = actor
|
||||||
|
player.sourceid = sourceid or 1
|
||||||
|
|
||||||
|
table.insert(self.players, player)
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseWorld:sendInputToPlayers(actor)
|
||||||
|
for i,v in ipairs(self.players) do
|
||||||
|
--TODO: make the player get from a selected source inputs
|
||||||
|
v.actor:getInput(self.scene.keys)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseWorld:removePlayer(actor)
|
||||||
|
for i,v in ipairs(self.players) do
|
||||||
|
if (v.actor == actor) then
|
||||||
|
table.remove(self.players, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- MAP FUNCTIONS
|
-- MAP FUNCTIONS
|
||||||
-- All map wrappers
|
-- All map wrappers
|
||||||
|
|
||||||
|
@ -114,6 +146,7 @@ end
|
||||||
|
|
||||||
function BaseWorld:update(dt)
|
function BaseWorld:update(dt)
|
||||||
self:updateMap(dt)
|
self:updateMap(dt)
|
||||||
|
self:sendInputToPlayers(dt)
|
||||||
self:updateActors(dt)
|
self:updateActors(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue