mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-08 15:15:55 +00:00
Refactoring
This commit is contained in:
parent
0e0a458949
commit
8ecf21aba3
8 changed files with 193 additions and 160 deletions
17
src/box.lua
17
src/box.lua
|
|
@ -1,12 +1,27 @@
|
|||
local Actor = require(make_path("actor2"))
|
||||
|
||||
local Box = Actor:new()
|
||||
Box.spriteIndex = 4
|
||||
|
||||
function Box:new(x,y)
|
||||
local b = Actor:new(x,y)
|
||||
|
||||
b.life = 8
|
||||
b.shootable = true
|
||||
b.spriteIndex = 4
|
||||
|
||||
return setmetatable(b, {__index=self})
|
||||
end
|
||||
|
||||
--Box.spriteIndex = 4
|
||||
|
||||
function Box:update()
|
||||
|
||||
end
|
||||
|
||||
function Box:destroy()
|
||||
del(actors,self)
|
||||
end
|
||||
|
||||
--function Barrel:draw()
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
--end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ 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)
|
||||
local weapon = weapons_manager.make_weapon(weapons_list.ICE_BLASTER)
|
||||
|
||||
obj.weapon = weapon
|
||||
|
||||
|
|
|
|||
79
src/game.lua
79
src/game.lua
|
|
@ -61,6 +61,65 @@ local Box = require(make_path("box"))
|
|||
|
||||
include(make_path("pgui" .. ".lua"))
|
||||
|
||||
particles_list = {
|
||||
BLINK={
|
||||
life=4,
|
||||
spriteIndex=81
|
||||
},
|
||||
EXPLOSION={
|
||||
life=8,
|
||||
spriteIndex=83
|
||||
}
|
||||
}
|
||||
|
||||
bullets_list = {
|
||||
BASIC={
|
||||
spriteIndex=80,
|
||||
damage=1,
|
||||
speed=2,
|
||||
life=100,
|
||||
radius=4,
|
||||
particle=particles_list.BLINK
|
||||
}
|
||||
}
|
||||
|
||||
weapons_list = {
|
||||
ICE_BLASTER={
|
||||
name = "Ice Blaster",
|
||||
rate_of_fire = 8,
|
||||
bullet=bullets_list.BASIC,
|
||||
spriteIndex=104,
|
||||
--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 = 80,
|
||||
bullet=bullets_list.BASIC,
|
||||
spriteIndex=105,
|
||||
}
|
||||
}
|
||||
|
||||
LAYERS = {
|
||||
{index=4, name="background", render=true, render_objects=false, spawn_objects=false},
|
||||
{index=3, name="solid", render=true, render_objects=true, spawn_objects=false},
|
||||
{index=2, name="foreground", render=true, render_objects=false, spawn_objects=false},
|
||||
{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=Box},
|
||||
{name="alarm",sprite=19,actor=nil},
|
||||
{name="fan",sprite=16,actor=nil}
|
||||
}
|
||||
|
||||
|
||||
|
||||
tile_width = 16
|
||||
tile_height = 16
|
||||
|
||||
|
|
@ -101,6 +160,7 @@ 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("Particles: %d", count(particles)),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}},
|
||||
{"text_box",{text=string.format("Weapon timer: %d", cirnoInstance.weapon.timer),margin=2,stroke=true,active=false,hover=false}},
|
||||
{"sprite_box",{sprite=cirnoInstance.weapon.data.spriteIndex,margin=2,stroke=true,active=false,hover=false}},
|
||||
|
|
@ -109,22 +169,7 @@ function _update()
|
|||
--pgui:component("text_box",{text=string.format("Actors: %d", count(actors)),margin=2,stroke=true,active=false,hover=false})
|
||||
end
|
||||
|
||||
LAYERS = {
|
||||
{index=4, name="background", render=true, render_objects=false, spawn_objects=false},
|
||||
{index=3, name="solid", render=true, render_objects=true, spawn_objects=false},
|
||||
{index=2, name="foreground", render=true, render_objects=false, spawn_objects=false},
|
||||
{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=Box},
|
||||
{name="alarm",sprite=19,actor=nil},
|
||||
{name="fan",sprite=16,actor=nil}
|
||||
}
|
||||
|
||||
actors = {}
|
||||
bullets = {}
|
||||
|
|
@ -165,6 +210,7 @@ include(make_path("error_explorer") .. ".lua")
|
|||
|
||||
function spawn_objects()
|
||||
|
||||
-- Map width and height, TODO: unhardcode
|
||||
local width = 32
|
||||
local height = 32
|
||||
|
||||
|
|
@ -177,6 +223,7 @@ function spawn_objects()
|
|||
if (a) then
|
||||
local ai = a:new(x*tile_width,y*tile_height)
|
||||
--local ai = Barrel:new(x*tile_width,y*tile_height)
|
||||
--error("ads")
|
||||
add(actors,ai)
|
||||
end
|
||||
|
||||
|
|
@ -256,7 +303,7 @@ function check_collisions()
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
--local player = require(make_path("cirno"))
|
||||
|
||||
M = {}
|
||||
local M = {}
|
||||
|
||||
local tile_width = 16
|
||||
local tile_height = 16
|
||||
|
|
|
|||
31
src/particle.lua
Normal file
31
src/particle.lua
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
local Actor = require(make_path("actor2"))
|
||||
|
||||
Particle = Actor:new()
|
||||
|
||||
function Particle:new(x,y,type)
|
||||
local p = Actor:new(x,y)
|
||||
|
||||
p.life = type.life
|
||||
p.spriteIndex = type.spriteIndex
|
||||
p.shootable = false
|
||||
|
||||
return setmetatable(p, {__index=self})
|
||||
end
|
||||
--Particle.life=4
|
||||
--Particle.spriteIndex=81
|
||||
|
||||
function Particle:update()
|
||||
self.life-=1
|
||||
if self.life<=0 then
|
||||
del(particles,self)
|
||||
end
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
function M:create(x,y,type)
|
||||
return Particle:new(x,y,type)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
0
src/typeLists.lua
Normal file
0
src/typeLists.lua
Normal file
|
|
@ -1,38 +1,10 @@
|
|||
--[[pod_format="raw",created="2024-04-24 07:17:14",modified="2024-04-24 20:33:05",revision=11]]
|
||||
local map_manager = require(make_path("map"))
|
||||
local Actor = require(make_path("actor2"))
|
||||
local Particle = require(make_path("particle"))
|
||||
--local actor = require("actor2")
|
||||
|
||||
M = {}
|
||||
|
||||
local bullets_list = {
|
||||
BASIC={
|
||||
spriteIndex=80,
|
||||
damage=1,
|
||||
speed=2,
|
||||
life=100,
|
||||
radius=2
|
||||
}
|
||||
}
|
||||
|
||||
local weapons_list = {
|
||||
ICE_BLASTER={
|
||||
name = "Ice Blaster",
|
||||
rate_of_fire = 8,
|
||||
bullet=bullets_list.BASIC,
|
||||
spriteIndex=104,
|
||||
--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 = 80,
|
||||
bullet=bullets_list.BASIC,
|
||||
spriteIndex=105,
|
||||
}
|
||||
}
|
||||
|
||||
function shoot(weapon, x, y, dir_x, dir_y)
|
||||
-- handle cooldown
|
||||
create_bullet(weapon.bullet, x, y, dir_x, dir_y)
|
||||
|
|
@ -64,34 +36,6 @@ function Weapon:update()
|
|||
end
|
||||
end
|
||||
|
||||
-- Particle
|
||||
|
||||
Particle = Actor:new()
|
||||
|
||||
function Particle:new(x,y)
|
||||
local p = Actor:new(x,y)
|
||||
|
||||
p.life=4
|
||||
p.spriteIndex=81
|
||||
p.shootable = false
|
||||
|
||||
return setmetatable(p, {__index=self})
|
||||
end
|
||||
--Particle.life=4
|
||||
--Particle.spriteIndex=81
|
||||
|
||||
function Particle:update()
|
||||
self.life-=1
|
||||
if self.life<=0 then
|
||||
del(particles,self)
|
||||
end
|
||||
end
|
||||
|
||||
-- function Particle:draw()
|
||||
-- spr(self.spriteIndex,self.x,self.y)
|
||||
-- end
|
||||
|
||||
|
||||
Bullet = Actor:new()
|
||||
--function Bullet:new()
|
||||
--
|
||||
|
|
@ -109,6 +53,7 @@ function Bullet:new(bullet_data,x,y,dir_x,dir_y)
|
|||
obj.life = bullet_data.life
|
||||
obj.speed = bullet_data.speed
|
||||
obj.radius = bullet_data.radius
|
||||
obj.particle = bullet_data.particle
|
||||
|
||||
obj.dx = dir_x * obj.speed
|
||||
obj.dy = dir_y * obj.speed
|
||||
|
|
@ -121,7 +66,7 @@ end
|
|||
function Bullet:destroy()
|
||||
|
||||
-- Create particle
|
||||
local p = Particle:new(self.x, self.y)
|
||||
local p = Particle:create(self.x, self.y,self.particle)
|
||||
|
||||
add(particles, p)
|
||||
|
||||
|
|
@ -176,14 +121,6 @@ end
|
|||
-- return shoot(weapon, new_x,new_y,dir_x,dir_y)
|
||||
--end
|
||||
|
||||
function M.get_weapons()
|
||||
return weapons_list
|
||||
end
|
||||
|
||||
function M.get_bullets()
|
||||
return bullets_list
|
||||
end
|
||||
|
||||
function M.init()
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue