mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-10 04:35:54 +00:00
Self contained weapons
This commit is contained in:
parent
e2ab6ee3e9
commit
9afa5195b9
4 changed files with 54 additions and 20 deletions
|
|
@ -20,6 +20,10 @@ Cirno.weapon=nil
|
|||
function Cirno:new(x,y)
|
||||
local obj = Actor:new(x,y)
|
||||
|
||||
local weapon = weapons_manager.make_weapon(weapons_manager.get_weapons().ICE_BLASTER)
|
||||
|
||||
obj.weapon = weapon
|
||||
|
||||
return setmetatable(obj, {__index=self})
|
||||
end
|
||||
|
||||
|
|
@ -32,8 +36,7 @@ function Cirno:update()
|
|||
self:move()
|
||||
|
||||
if (btn(4)) then
|
||||
--create_bullet(self.x,self.y,self.move_x,self.move_Y)
|
||||
weapons_manager.shoot(self.weapon,self.x+8,self.y+8,self.move_x,self.move_y)
|
||||
self.weapon:shoot(self.x+8,self.y+8,self.move_x,self.move_y)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -60,8 +63,8 @@ M = {}
|
|||
function M.init()
|
||||
--return cirno_init()
|
||||
local c = Cirno:new(128,128)
|
||||
local weapon = weapons_manager.get_weapons().ICE_BLASTER
|
||||
c.weapon = weapon
|
||||
--local weapon = weapons_manager.get_default_weapon()
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ function _update()
|
|||
{"text_box",{text=string.format("Actors: %d", count(actors)),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"text_box",{text=string.format("%.4f %dfps",stat(1),stat(7)),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"text_box",{text=string.format("Bullets: %d", count(bullets)),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"text_box",{text=string.format("Weapon: %s", cirnoInstance.weapon.name),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"sprite_box",{sprite=cirnoInstance.weapon.spriteIndex,margin=2,stroke=true,active=false,hover=false}},
|
||||
{"text_box",{text=string.format("Weapon: %s", cirnoInstance.weapon.data.name),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"sprite_box",{sprite=cirnoInstance.weapon.data.spriteIndex,margin=2,stroke=true,active=false,hover=false}},
|
||||
}})
|
||||
|
||||
--pgui:component("text_box",{text=string.format("Actors: %d", count(actors)),margin=2,stroke=true,active=false,hover=false})
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ local weapons_list = {
|
|||
--shoot=function(self,x,y,dir_x,dir_y)
|
||||
-- create_bullet(self.bullet, x, y, dir_x, dir_y)
|
||||
--end
|
||||
},
|
||||
SPAGHETTI={
|
||||
name = "Spaghetti",
|
||||
rate_of_fire = 0.2,
|
||||
bullet=bullets_list.BASIC,
|
||||
spriteIndex=105,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +37,25 @@ function shoot(weapon, x, y, dir_x, dir_y)
|
|||
create_bullet(weapon.bullet, x, y, dir_x, dir_y)
|
||||
end
|
||||
|
||||
-- local particles = {}
|
||||
-- Weapon
|
||||
|
||||
Weapon = {}
|
||||
|
||||
function Weapon:new(data)
|
||||
local we = {
|
||||
data = data,
|
||||
timer = 0
|
||||
}
|
||||
|
||||
return setmetatable(we, {__index=self})
|
||||
end
|
||||
|
||||
function Weapon:shoot(x,y,dir_x,dir_y)
|
||||
|
||||
create_bullet(self.data.bullet, x, y, dir_x, dir_y)
|
||||
end
|
||||
|
||||
-- Particle
|
||||
|
||||
Particle = Actor:new()
|
||||
Particle.life=4
|
||||
|
|
@ -125,9 +149,9 @@ function create_bullet(bullet, new_x, new_y, dir_x, dir_y)
|
|||
|
||||
end
|
||||
|
||||
function M.shoot(weapon, new_x, new_y, dir_x, dir_y)
|
||||
return shoot(weapon, new_x,new_y,dir_x,dir_y)
|
||||
end
|
||||
--function M.shoot(weapon, new_x, new_y, dir_x, dir_y)
|
||||
-- return shoot(weapon, new_x,new_y,dir_x,dir_y)
|
||||
--end
|
||||
|
||||
function M.get_weapons()
|
||||
return weapons_list
|
||||
|
|
@ -165,4 +189,10 @@ function M.debug_draw()
|
|||
--print(string.format("Bullets: %d", count(bullets)), 0,32,1)
|
||||
end
|
||||
|
||||
function M.make_weapon(bullet_type)
|
||||
return Weapon:new(bullet_type)
|
||||
--local w = Weapon:new(weapons_list.SPAGHETTI)
|
||||
--return w
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue