mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-10 14:45:54 +00:00
Proper actors implementation
This commit is contained in:
parent
4407ce108b
commit
6a7e938a39
5 changed files with 88 additions and 68 deletions
|
|
@ -1,24 +1,27 @@
|
|||
--M = {}
|
||||
|
||||
actor = {}
|
||||
actor.__index = actor
|
||||
function actor:new(x,y)
|
||||
local o = setmetatable({}, actor)
|
||||
o.x=x
|
||||
o.y=y
|
||||
o.life=100
|
||||
o.spriteIndex=0
|
||||
return o
|
||||
Actor = {
|
||||
life=100,
|
||||
spriteIndex=0,
|
||||
}
|
||||
--actor.__index = actor
|
||||
function Actor:new(new_x,new_y)
|
||||
local o = {
|
||||
x=new_x,
|
||||
y=new_y,
|
||||
}
|
||||
|
||||
return setmetatable(o, {__index=self})
|
||||
end
|
||||
|
||||
function actor:update()
|
||||
function Actor:update()
|
||||
|
||||
end
|
||||
|
||||
function actor:draw()
|
||||
function Actor:draw()
|
||||
spr(self.spriteIndex,self.x,self.y)
|
||||
end
|
||||
|
||||
--M.actor = actor
|
||||
|
||||
return actor
|
||||
return Actor
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
--local actor = require("actor2")
|
||||
local Actor = require(make_path("actor2"))
|
||||
|
||||
-- barrel = setmetatable({}, {__index = actor})
|
||||
-- function barrel:new(actor)
|
||||
|
|
@ -9,25 +9,18 @@
|
|||
|
||||
-- return barrel
|
||||
|
||||
barrel = {}
|
||||
barrel.__index = barrel
|
||||
function barrel:new(x,y)
|
||||
local o = setmetatable({}, barrel)
|
||||
o.x=x
|
||||
o.y=y
|
||||
o.life=100
|
||||
o.spriteIndex=0
|
||||
return o
|
||||
end
|
||||
Barrel = Actor:new()
|
||||
Barrel.spriteIndex = 3
|
||||
|
||||
function barrel:update()
|
||||
|
||||
function Barrel:update()
|
||||
|
||||
end
|
||||
|
||||
function barrel:draw()
|
||||
spr(self.spriteIndex,self.x,self.y)
|
||||
end
|
||||
--function Barrel:draw()
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
--end
|
||||
|
||||
--M.actor = actor
|
||||
|
||||
return barrel
|
||||
return Barrel
|
||||
|
|
@ -44,6 +44,7 @@ function cirno_init()
|
|||
cm=true, -- Collide with map tiles
|
||||
cb=true, -- Collide with world bounds
|
||||
draw=function(self)
|
||||
camera(self.x - 240, self.y - 135)
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f",self.x,self.y,
|
||||
self.move_x,self.move_y),0,0,1)
|
||||
|
|
@ -101,7 +102,7 @@ end
|
|||
|
||||
function cirno_draw()
|
||||
--cls(0)
|
||||
--camera(x - 240, y - 135)
|
||||
|
||||
|
||||
--drawMap()
|
||||
|
||||
|
|
|
|||
15
src/game.lua
15
src/game.lua
|
|
@ -55,11 +55,13 @@ local cirno = require(make_path("cirno"))
|
|||
local mouse_debug = require(make_path("mouse_debug"))
|
||||
local map_manager = require(make_path("map"))
|
||||
local weapons_manager = require(make_path("weapons"))
|
||||
local Barrel = require(make_path("barrel"))
|
||||
|
||||
tile_width = 16
|
||||
tile_height = 16
|
||||
|
||||
function _init()
|
||||
spawn_objects()
|
||||
cirno.init()
|
||||
end
|
||||
|
||||
|
|
@ -76,6 +78,8 @@ LAYERS = {
|
|||
{index=1, name="objects", render=false, render_objects=false, spawn_objects=true}
|
||||
}
|
||||
|
||||
actors = {}
|
||||
|
||||
function _draw()
|
||||
cls(0)
|
||||
|
||||
|
|
@ -85,6 +89,11 @@ function _draw()
|
|||
weapons_manager.debug_draw()
|
||||
end
|
||||
|
||||
function spawn_objects()
|
||||
local b = Barrel:new(32,32)
|
||||
add(actors,b)
|
||||
end
|
||||
|
||||
function render_layer(layer)
|
||||
if (layer.render) then
|
||||
-- todo move function in map manager
|
||||
|
|
@ -96,7 +105,11 @@ function render_layer(layer)
|
|||
cirno.draw()
|
||||
|
||||
weapons_manager.draw()
|
||||
|
||||
|
||||
for b in all(actors) do
|
||||
b:draw()
|
||||
end
|
||||
|
||||
-- for b in all(bullets) do
|
||||
-- b:draw()
|
||||
-- end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue