complete conversion to new

This commit is contained in:
Kistaro Windrider 2023-09-30 15:01:39 -07:00
parent 8d5f697961
commit 6f9517cee1
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -118,10 +118,8 @@ function linked_list:pop_front()
end end
function _init() function _init()
init_bullet_mt()
init_powerup_mt()
wipe_level() wipe_level()
primary_ship.main_gun = new_gun_of(zap_gun_t) primary_ship.main_gun = zap_gun.new()
load_level(example_level) load_level(example_level)
state = game state = game
pal(2,129) pal(2,129)
@ -214,7 +212,7 @@ function updategame()
-- many bullets and many enemy ships; -- many bullets and many enemy ships;
-- use bucket collider for efficiency -- use bucket collider for efficiency
local pbullet_collider = new_collider() local pbullet_collider = collider.new()
local p, n = pbullets, pbullets.next local p, n = pbullets, pbullets.next
while n do while n do
n.prev = p n.prev = p
@ -633,7 +631,7 @@ player = ship_m.new{
} }
mknew(player, mknew(player,
function(p) function(p)
p.main_gun = new_gun_of(zap_gun_t, false) p.main_gun = zap_gun.new()
end end
) )
@ -714,7 +712,7 @@ function spawn_spewy_at(x, y)
hp = 1, hp = 1,
maxpower = 70, maxpower = 70,
generator = 0.5, generator = 0.5,
main_gun = new_gun_of(protron_gun_t, true), main_gun = protron_gun.new{enemy=true},
fire_off_x = 4, fire_off_x = 4,
fire_off_y = 7, fire_off_y = 7,
grab_butts = function() grab_butts = function()
@ -766,7 +764,7 @@ function spawn_chasey_at(x, y)
local c = chasey.new{ local c = chasey.new{
x = x, x = x,
y = y, y = y,
main_gun = new_gun_of(zap_gun_t, true) main_gun = zap_gun.new{enemy=true},
} }
eships:push_back(c) eships:push_back(c)
return c return c
@ -788,7 +786,7 @@ function spawn_xl_chasey_at(x, y)
shield = 5, shield = 5,
boss = true, boss = true,
slip = false, slip = false,
main_gun = new_gun_of(zap_gun_t, true), main_gun = zap_gun.new{enemy=true},
grab_butts = function(self) grab_butts = function(self)
local butts = chasey.grab_butts(self) local butts = chasey.grab_butts(self)
if (self.y < 4) butts[3] = 1 if (self.y < 4) butts[3] = 1
@ -817,16 +815,12 @@ function collides(box1, box2)
end end
collider = { } collider = { }
collider_t = { mknew(collider,
__index = collider function(x)
} x.suppress = {}
function new_collider()
local c = { }
setmetatable(c, collider_t)
c.suppress = { }
return c
end end
)
function collider_indexes(box) function collider_indexes(box)
local ret = {} local ret = {}
for x = box.x\8, (box.x+box.width)\8 do for x = box.x\8, (box.x+box.width)\8 do
@ -1007,9 +1001,9 @@ end
function spawn_bonus_vulcan_chasey() function spawn_bonus_vulcan_chasey()
local c = spawn_chasey() local c = spawn_chasey()
c.main_gun=new_gun_of(vulcan_gun_t, true) c.main_gun=vulcan_gun.new{enemy=true}
c.die = function(self) c.die = function(self)
spawn_main_gun_at(self.x-1, self.y-1, vulcan_gun_t) spawn_main_gun_at(self.x-1, self.y-1, vulcan_gun)
chasey.die(self) chasey.die(self)
end end
c.sprite=4 c.sprite=4
@ -1060,7 +1054,7 @@ example_level = {
[200]=spawn_chasey, [200]=spawn_chasey,
[250]=spawn_blocking_blocky, [250]=spawn_blocking_blocky,
[285]=function() [285]=function()
spawn_spec_gun_at(35, -11, blast_gun_t) spawn_spec_gun_at(35, -11, blast_gun)
end, end,
[310]=function() [310]=function()
spawn_blocking_blocky() spawn_blocking_blocky()
@ -1069,7 +1063,7 @@ example_level = {
end, end,
[311]=spawn_frownie, [311]=spawn_frownie,
[350]=function() [350]=function()
spawn_main_gun_at(70, -11, protron_gun_t) spawn_main_gun_at(70, -11, protron_gun)
end, end,
[401]=spawn_frownie, [401]=spawn_frownie,
[420]=spawn_blocking_frownie, [420]=spawn_blocking_frownie,
@ -1096,26 +1090,7 @@ example_level = {
-->8 -->8
-- bullets and guns -- bullets and guns
function init_bullet_mt() zap = bullet_base.new{
setmetatable(zap, bullet_t)
setmetatable(zap_gun, gun_t)
setmetatable(blast, bullet_t)
setmetatable(blast_gun, gun_t)
setmetatable(protron, bullet_t)
setmetatable(protron_gun, gun_t)
setmetatable(vulcan, bullet_t)
setmetatable(vulcan_gun, gun_t)
end
function new_gun_of(mt, is_enemy)
local g = {
enemy = is_enemy
}
setmetatable(g, mt)
return g
end
zap = {
--shape --shape
psprite = 8, --index of player ammo sprite psprite = 8, --index of player ammo sprite
esprite = 9, -- index of enemy ammo sprite esprite = 9, -- index of enemy ammo sprite
@ -1139,23 +1114,18 @@ zap = {
return true return true
end end
} }
zap_t = { mknew(zap)
__index = zap
}
zap_gun = { zap_gun = gun_base.new{
enemy = false, enemy = false,
power = 20, -- power consumed per shot power = 20, -- power consumed per shot
cooldown = 10, -- frames between shots cooldown = 10, -- frames between shots
ammo = nil, -- unlimited ammo - main gun ammo = nil, -- unlimited ammo - main gun
t = zap_t -- metatable of bullet to fire t = zap -- metatable of bullet to fire
} }
mknew(zap_gun)
zap_gun_t = { blast = bullet_base.new{
__index = zap_gun
}
blast = {
--shape --shape
psprite = 12, --index of player ammo sprite psprite = 12, --index of player ammo sprite
esprite = 3, -- index of enemy ammo sprite esprite = 3, -- index of enemy ammo sprite
@ -1200,25 +1170,20 @@ blast = {
end end
end end
} }
blast_t = { mknew(blast)
__index = blast
}
blast_gun = { blast_gun = gun_base.new{
icon = 13, icon = 13,
enemy = false, enemy = false,
power = 0, -- ammo, not power power = 0, -- ammo, not power
cooldown = 30, -- frames between shots cooldown = 30, -- frames between shots
ammo = 5, ammo = 5,
maxammo = 5, maxammo = 5,
t = blast_t -- metatable of bullet to fire t = blast -- type of bullet to fire
} }
mknew(blast_gun)
blast_gun_t = { protron = bullet_base.new{
__index = blast_gun
}
protron = {
--shape --shape
psprite = 23, --index of player ammo sprite psprite = 23, --index of player ammo sprite
esprite = 24, -- index of enemy ammo sprite esprite = 24, -- index of enemy ammo sprite
@ -1238,11 +1203,9 @@ protron = {
dx = 0, -- px/frame dx = 0, -- px/frame
dy = 3, dy = 3,
} }
protron_t = { mknew(protron)
__index = protron
}
protron_gun = { protron_gun = gun_base.new{
icon = 25, icon = 25,
enemy = false, enemy = false,
power = 35, power = 35,
@ -1253,38 +1216,32 @@ protron_gun = {
local sprite = protron.psprite local sprite = protron.psprite
if (self.enemy) sprite=protron.esprite if (self.enemy) sprite=protron.esprite
for i=1,3 do for i=1,3 do
local b = { local b = protron.new{
enemy=self.enemy, enemy=self.enemy,
sprite=sprite, sprite=sprite,
dx = i, dx = i,
dy = 4-i dy = 4-i
} }
setmetatable(b, protron_t)
b:spawn_at(x,y) b:spawn_at(x,y)
local b2 = { local b2 = protron.new{
enemy=self.enemy, enemy=self.enemy,
sprite=sprite, sprite=sprite,
dx = -i, dx = -i,
dy = 4-i dy = 4-i
} }
setmetatable(b2, protron_t)
b2:spawn_at(x,y) b2:spawn_at(x,y)
end end
local bup = { local bup = protron.new{
enemy=self.enemy, enemy=self.enemy,
sprite=sprite, sprite=sprite,
dy=4 dy=4
} }
setmetatable(bup, protron_t)
bup:spawn_at(x,y) bup:spawn_at(x,y)
end end
} }
mknew(protron_gun)
protron_gun_t = { vulcan = bullet_base.new{
__index = protron_gun
}
vulcan = {
--shape --shape
psprite = 22, --index of player ammo sprite psprite = 22, --index of player ammo sprite
esprite = 21, -- index of enemy ammo sprite esprite = 21, -- index of enemy ammo sprite
@ -1304,10 +1261,9 @@ vulcan = {
dx = 0, -- px/frame dx = 0, -- px/frame
dy = 4, dy = 4,
} }
vulcan_t = { mknew(vulcan)
__index = vulcan
} vulcan_gun = gun_base.new{
vulcan_gun = {
icon = 37, icon = 37,
enemy = false, enemy = false,
power = 8, power = 8,
@ -1319,20 +1275,17 @@ vulcan_gun = {
dxidx = 1, dxidx = 1,
actually_shoot = function(self, x, y) actually_shoot = function(self, x, y)
local sprite = self.enemy and vulcan.esprite or vulcan.psprite local sprite = self.enemy and vulcan.esprite or vulcan.psprite
local b = { local b = vulcan.new{
enemy=self.enemy, enemy=self.enemy,
sprite=sprite, sprite=sprite,
dx = self.dxs[self.dxidx], dx = self.dxs[self.dxidx],
} }
setmetatable(b, vulcan_t)
b:spawn_at(self.xoffs[self.dxidx]+x,y) b:spawn_at(self.xoffs[self.dxidx]+x,y)
self.dxidx += 1 self.dxidx += 1
if (self.dxidx > #self.dxs) self.dxidx = 1 if (self.dxidx > #self.dxs) self.dxidx = 1
end end
} }
vulcan_gun_t = { mknew(vulcan_gun)
__index = vulcan_gun
}
-->8 -->8
-- bullet and gun behaviors -- bullet and gun behaviors
@ -1340,20 +1293,13 @@ vulcan_gun_t = {
bullet_base = { bullet_base = {
enemyspd = 0.5 enemyspd = 0.5
} }
mknew(bullet_base)
bullet_t = {
__index = bullet_base
}
gun_base = { gun_base = {
shoot_ready = -32768, shoot_ready = -32768,
icon = 20 icon = 20
} }
mknew(gun_base)
gun_t = {
__index = gun_base
}
function bullet_base:hitship(_) function bullet_base:hitship(_)
self:die() self:die()
@ -1410,15 +1356,11 @@ function gun_base:shoot(x, y)
end end
function gun_base:actually_shoot(x, y) function gun_base:actually_shoot(x, y)
b = { } local typ = self.t
setmetatable(b, self.t) local b = typ.new{
if self.enemy then enemy = self.enemy,
b.enemy = true sprite = self.enemy and typ.esprite or typ.psprite,
b.sprite = b.esprite }
else
b.enemy = false
b.sprite = b.psprite
end
b:spawn_at(x, y) b:spawn_at(x, y)
return true return true
end end
@ -1885,12 +1827,8 @@ function spark(sprs, x, y, butts, thrust, odds, fg)
end end
-->8 -->8
-- powerups -- powerups
function init_powerup_mt()
setmetatable(powerup, bullet_t)
setmetatable(gun_swap, powerup_t)
end
powerup = { powerup = bullet_base.new{
-- animated sprite array: "sprites" -- animated sprite array: "sprites"
-- to draw under or over anim, -- to draw under or over anim,
-- override draw, draw the -- override draw, draw the
@ -1912,14 +1850,11 @@ powerup = {
anim_speed = 2, anim_speed = 2,
loop_pause = 30 -- affected by animspeed loop_pause = 30 -- affected by animspeed
} }
mknew(powerup)
-- sprite indexes for "sheen" animation -- sprite indexes for "sheen" animation
sheen8x8 = split"2,54,55,56,57,58,59,60,61" sheen8x8 = split"2,54,55,56,57,58,59,60,61"
powerup_t = {
__index = powerup
}
-- todo: draw two sprites -- todo: draw two sprites
-- on top of each other here -- on top of each other here
-- so all powerups can share -- so all powerups can share
@ -1935,8 +1870,7 @@ function powerup:draw()
self.width, self.height) self.width, self.height)
end end
function spawn_repair_at(x, y) repair = powerup.new{
local repair = {
hurt = { hurt = {
x_off = -2, x_off = -2,
y_off = -2, y_off = -2,
@ -1957,18 +1891,20 @@ function spawn_repair_at(x, y)
powerup.draw(self) powerup.draw(self)
end end
} }
setmetatable(repair, powerup_t) mknew(repair)
repair:spawn_at(x, y)
function spawn_repair_at(x, y)
repair.new():spawn_at(x, y)
end end
gun_swap = { gun_swap = powerup.new{
hurt = { hurt = {
x_off = -2, x_off = -2,
y_off = -2, y_off = -2,
width = 16, width = 16,
height = 16 height = 16
}, },
-- gun = new_gun_of(t, false) -- gun = gun_type.new{}
center_x_off = 6, center_x_off = 6,
top_y_off = 0, top_y_off = 0,
bottom_y_off = 4, bottom_y_off = 4,
@ -1985,15 +1921,12 @@ gun_swap = {
spr(self.gun.icon, self.x+2, self.y+2, 1, 1) spr(self.gun.icon, self.x+2, self.y+2, 1, 1)
end end
} }
gun_swap_t = { mknew(gun_swap)
__index=gun_swap
}
function spawn_main_gun_at(x, y, mt) function spawn_main_gun_at(x, y, gunt)
local gun_p = { local gun_p = gun_swap.new{
gun = new_gun_of(mt, false) gun = gunt.new()
} }
setmetatable(gun_p, gun_swap_t)
gun_p:spawn_at(x, y) gun_p:spawn_at(x, y)
end end
@ -2003,9 +1936,9 @@ spec_gun_pl = {
[2] = 14 [2] = 14
} }
function spawn_spec_gun_at(x, y, mt) function spawn_spec_gun_at(x, y, gunt)
local gun_p = { local gun_p = gun_swap.new{
gun = new_gun_of(mt, false), gun = gunt.new(),
hitship = function(self, ship) hitship = function(self, ship)
if (ship ~= primary_ship) return false if (ship ~= primary_ship) return false
ship.special_gun = self.gun ship.special_gun = self.gun
@ -2018,7 +1951,6 @@ function spawn_spec_gun_at(x, y, mt)
spr(self.gun.icon, self.x+2, self.y+2, 1, 1) spr(self.gun.icon, self.x+2, self.y+2, 1, 1)
end end
} }
setmetatable(gun_p, gun_swap_t)
gun_p:spawn_at(x, y) gun_p:spawn_at(x, y)
end end
__gfx__ __gfx__