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)
|
||||
end
|
||||
|
||||
function Actor2D:getInput(keys)
|
||||
self.keys = keys or core.input.fakekeys
|
||||
end
|
||||
|
||||
function Actor2D:update(dt)
|
||||
-- here will be update actions
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ local Sti = require(cwd .. "libs.sti")
|
|||
|
||||
function BaseWorld:new(scene, actorlist, mapfile)
|
||||
self.scene = scene
|
||||
|
||||
self:initPlayers()
|
||||
self:setActorList(actorlist)
|
||||
self:setMap(mapfile)
|
||||
self.actors = {}
|
||||
|
@ -84,6 +86,36 @@ function BaseWorld:getActors()
|
|||
return self.actors
|
||||
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
|
||||
-- All map wrappers
|
||||
|
||||
|
@ -114,6 +146,7 @@ end
|
|||
|
||||
function BaseWorld:update(dt)
|
||||
self:updateMap(dt)
|
||||
self:sendInputToPlayers(dt)
|
||||
self:updateActors(dt)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue