mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-01 10:15:46 +00:00
Added constructors
This commit is contained in:
parent
81a8c11823
commit
3cc9f26674
2 changed files with 18 additions and 67 deletions
|
|
@ -16,6 +16,12 @@ local Cirno = MovableActor:new()
|
|||
Cirno.spriteIndex = 65
|
||||
Cirno.crosshair_index=82
|
||||
|
||||
function Cirno:new(x,y)
|
||||
local obj = Actor:new(x,y)
|
||||
|
||||
return setmetatable(obj, {__index=self})
|
||||
end
|
||||
|
||||
function Cirno:update()
|
||||
if (btn(0)) self.move_x -= self.speed self.hflip = true
|
||||
if (btn(1)) self.move_x += self.speed self.hflip = false
|
||||
|
|
|
|||
|
|
@ -14,27 +14,12 @@ weapon = {
|
|||
shoot=function(self)
|
||||
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
Particle = Actor:new()
|
||||
Particle.life=4
|
||||
Particle.spriteIndex=81
|
||||
|
||||
-- particle = {
|
||||
-- x=0,
|
||||
-- y=0,
|
||||
-- life=4,
|
||||
-- spriteIndex=81
|
||||
-- }
|
||||
--particle.__index = particle
|
||||
-- function Particle:new(x,y)
|
||||
-- local o = setmetatable({}, particle)
|
||||
-- o.x=x
|
||||
-- o.y=y
|
||||
-- return o
|
||||
-- end
|
||||
|
||||
function Particle:update()
|
||||
self.life-=1
|
||||
if self.life<=0 then
|
||||
|
|
@ -51,30 +36,21 @@ Bullet = Actor:new()
|
|||
--function Bullet:new()
|
||||
--
|
||||
--end
|
||||
Bullet.dx=0
|
||||
Bullet.dy=0
|
||||
--Bullet.dx=0
|
||||
--Bullet.dy=0
|
||||
Bullet.spriteIndex = 80
|
||||
Bullet.damage=1
|
||||
|
||||
-- bullet = {
|
||||
-- x=0,
|
||||
-- y=0,
|
||||
-- dx=0,
|
||||
-- dy=0,
|
||||
-- spriteIndex=80,
|
||||
-- destroy_sprite_index=66,
|
||||
-- life=100,
|
||||
-- damage=1,
|
||||
-- }
|
||||
-- bullet.__index = bullet
|
||||
-- function bullet:new(x, y, dx, dy)
|
||||
-- local o = setmetatable({}, bullet)
|
||||
-- o.x = x
|
||||
-- o.y = y
|
||||
-- o.dx = dx
|
||||
-- o.dy = dy
|
||||
-- return o
|
||||
-- end
|
||||
function Bullet:new(x,y,dir_x,dir_y)
|
||||
local obj = Actor:new(x,y)
|
||||
|
||||
obj.dx = dir_x
|
||||
obj.dy = dir_y
|
||||
|
||||
-- 'obj' has 'Actor' as a prototype at the moment
|
||||
-- which isn't what we want so we just change it.
|
||||
return setmetatable(obj, {__index=self})
|
||||
end
|
||||
|
||||
function Bullet:destroy()
|
||||
|
||||
|
|
@ -125,37 +101,6 @@ function M.create_bullet(new_x, new_y, dir_x, dir_y)
|
|||
|
||||
add(bullets, b)
|
||||
|
||||
-- add(bullets, {
|
||||
-- x=new_x,
|
||||
-- y=new_y,
|
||||
-- dx=normalized_dir_x * 2,
|
||||
-- dy=normalized_dir_y * 2,
|
||||
-- spriteIndex=80,
|
||||
-- destroy_sprite_index=66,
|
||||
-- life=100,
|
||||
-- damage=1,
|
||||
-- draw=function(self)
|
||||
-- --pset(self.x,self.y,8)
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
-- end,
|
||||
-- update=function(self)
|
||||
-- self.x+=self.dx
|
||||
-- self.y+=self.dy
|
||||
|
||||
-- self.life-=1
|
||||
-- if self.life<0 then
|
||||
-- del(bullets,self)
|
||||
-- -- TODO: Create particle
|
||||
-- end
|
||||
|
||||
-- self.check_collision(self)
|
||||
-- end,
|
||||
-- check_collision=function(self)
|
||||
-- -- If Collide with wall destroy self and create particle
|
||||
|
||||
-- end
|
||||
-- })
|
||||
|
||||
end
|
||||
|
||||
function M.init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue