mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-05 05:35:55 +00:00
Actor spawning
This commit is contained in:
parent
89a61d6b30
commit
5d624acaea
2 changed files with 79 additions and 51 deletions
39
src/game.lua
39
src/game.lua
|
|
@ -92,6 +92,16 @@ LAYERS = {
|
|||
{index=1, name="objects", render=false, render_objects=false, spawn_objects=true}
|
||||
}
|
||||
|
||||
actors_db = {
|
||||
{name="teleporter",sprite=88,actor=nil},
|
||||
{name="barrel",sprite=3,actor=Barrel},
|
||||
{name="strawberry",sprite=72,actor=Strawberry},
|
||||
{name="player",sprite=65,actor=nil},
|
||||
{name="box",sprite=4,actor=nil},
|
||||
{name="alarm",sprite=19,actor=nil},
|
||||
{name="fan",sprite=16,actor=nil}
|
||||
}
|
||||
|
||||
actors = {}
|
||||
bullets = {}
|
||||
particles = {}
|
||||
|
|
@ -120,14 +130,21 @@ function spawn_objects()
|
|||
for y=0,height,1 do
|
||||
local tile = map_manager.get_layer_tile(x,y,1)
|
||||
|
||||
if (tile == 3) then
|
||||
local b = Barrel:new(x*tile_width,y*tile_height)
|
||||
add(actors,b)
|
||||
elseif(tile == 72) then
|
||||
local s = Strawberry:new(x*tile_width,y*tile_height)
|
||||
add(actors,s)
|
||||
local a = get_actor_from_sprite(tile)
|
||||
if (a) then
|
||||
local ai = a:new(x*tile_width,y*tile_height)
|
||||
--local ai = Barrel:new(x*tile_width,y*tile_height)
|
||||
add(actors,ai)
|
||||
end
|
||||
|
||||
-- if (tile == 3) then
|
||||
-- local b = Barrel:new(x*tile_width,y*tile_height)
|
||||
-- add(actors,b)
|
||||
-- elseif(tile == 72) then
|
||||
-- local s = Strawberry:new(x*tile_width,y*tile_height)
|
||||
-- add(actors,s)
|
||||
-- end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -135,6 +152,16 @@ function spawn_objects()
|
|||
|
||||
end
|
||||
|
||||
function get_actor_from_sprite(sprite)
|
||||
local res = nil
|
||||
for a in all(actors_db) do
|
||||
if (a.sprite == sprite) then
|
||||
res = a.actor
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function render_layer(layer)
|
||||
if (layer.render) then
|
||||
-- todo move function in map manager
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue