migrate ships to mknew style

This commit is contained in:
Kistaro Windrider 2023-09-30 14:24:31 -07:00
parent f49407baca
commit bad8452f3c
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -153,7 +153,7 @@ function init_hpcols()
end end
function wipe_level() function wipe_level()
primary_ship = new_p1() primary_ship = player.new()
init_hpcols() init_hpcols()
pships = linked_list.new() pships = linked_list.new()
pships:push_back(primary_ship) pships:push_back(primary_ship)
@ -466,10 +466,7 @@ ship_m = {
xmomentum = 0, xmomentum = 0,
ymomentum = 0, ymomentum = 0,
} }
mknew(ship_m)
ship_t = {
__index = ship_m,
}
function ship_m:die() function ship_m:die()
self.dead = true self.dead = true
@ -583,17 +580,10 @@ end
-->8 -->8
--ships, including player --ships, including player
function init_ship_mt()
setmetatable(player, ship_t)
setmetatable(frownie, ship_t)
setmetatable(blocky, frownie_t)
setmetatable(chasey, ship_t)
end
firespark = split"9, 8, 2, 5, 1" firespark = split"9, 8, 2, 5, 1"
smokespark = split"13, 13, 5, 5" smokespark = split"13, 13, 5, 5"
player = { player = ship_m.new{
--shape --shape
sprite = 1, --index of ship sprite sprite = 1, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites? size = 1, --all ships are square; how many 8x8 sprites?
@ -642,20 +632,13 @@ player = {
return butts return butts
end end
} }
mknew(player,
function(p)
p.main_gun = new_gun_of(zap_gun_t, false)
end
)
player_t = { frownie = ship_m.new{
__index = player
}
function new_p1()
p = {
main_gun = new_gun_of(zap_gun_t, false)
}
setmetatable(p, player_t)
return p
end
frownie = {
--shape --shape
sprite = 3, --index of ship sprite sprite = 3, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites? size = 1, --all ships are square; how many 8x8 sprites?
@ -693,11 +676,9 @@ frownie = {
return butts return butts
end, -- button fetch algorithm end, -- button fetch algorithm
} }
frownie_t = { mknew(frownie)
__index = frownie
}
blocky = { blocky = frownie.new{
sprite = 10, sprite = 10,
hp = 2, hp = 2,
hurt = { hurt = {
@ -713,16 +694,13 @@ blocky = {
else else
self.sprite = 10 self.sprite = 10
end end
ship_t.__index.ow(self) ship_m.ow(self)
end end
} }
mknew(blocky)
blocky_t = {
__index = blocky
}
function spawn_spewy_at(x, y) function spawn_spewy_at(x, y)
local spewy = { local spewy = frownie.new{
x = x, x = x,
y = y, y = y,
sprite = 26, sprite = 26,
@ -746,12 +724,11 @@ function spawn_spewy_at(x, y)
return butts return butts
end, end,
} }
setmetatable(spewy, frownie_t)
eships:push_back(spewy) eships:push_back(spewy)
return spewy return spewy
end end
chasey = { chasey = ship_m.new{
sprite = 5, sprite = 5,
size = 1, size = 1,
hurt = { hurt = {
@ -784,22 +761,20 @@ chasey = {
return butts return butts
end, end,
} }
chasey_t = { mknew(chasey)
__index = chasey
}
function spawn_chasey_at(x, y) function spawn_chasey_at(x, y)
local c = { local c = chasey.new{
x = x, x = x,
y = y, y = y,
main_gun = new_gun_of(zap_gun_t, true) main_gun = new_gun_of(zap_gun_t, true)
} }
setmetatable(c, chasey_t)
eships:push_back(c) eships:push_back(c)
return c return c
end end
function spawn_xl_chasey_at(x, y) function spawn_xl_chasey_at(x, y)
local c = { local c = chasey.new{
x = x, x = x,
y = y, y = y,
size = 2, size = 2,
@ -826,7 +801,6 @@ function spawn_xl_chasey_at(x, y)
pal() pal()
end, end,
} }
setmetatable(c, chasey_t)
eships:push_back(c) eships:push_back(c)
return c return c
end end
@ -962,19 +936,18 @@ end
-->8 -->8
-- example level -- example level
function spawn_rnd_x(mt) function spawn_rnd_x(typ)
s = { s = typ.new{
x = rnd(104), x = rnd(104),
y = -(mt.__index.size * 8 - 1) y = -(mt.__index.size * 8 - 1)
} }
setmetatable(s, mt)
eships:push_back(s) eships:push_back(s)
return s return s
end end
function spawn_blocking_rnd_x(mt) function spawn_blocking_rnd_x(typ)
freeze += 1 freeze += 1
s = { s = typ.new{
x = rnd(104), x = rnd(104),
y = -7, y = -7,
ice = 1, ice = 1,
@ -984,25 +957,24 @@ function spawn_blocking_rnd_x(mt)
mt.__index.die(self) mt.__index.die(self)
end end
} }
setmetatable(s, mt)
eships:push_back(s) eships:push_back(s)
return s return s
end end
function spawn_frownie() function spawn_frownie()
return spawn_rnd_x(frownie_t) return spawn_rnd_x(frownie)
end end
function spawn_blocking_frownie() function spawn_blocking_frownie()
spawn_blocking_rnd_x(frownie_t) spawn_blocking_rnd_x(frownie)
end end
function spawn_blocky() function spawn_blocky()
spawn_rnd_x(blocky_t) spawn_rnd_x(blocky)
end end
function spawn_blocking_blocky() function spawn_blocking_blocky()
spawn_blocking_rnd_x(blocky_t) spawn_blocking_rnd_x(blocky)
end end
function spawn_spewy() function spawn_spewy()
@ -1020,7 +992,7 @@ function spawn_blocking_spewy()
s.die = function(self) s.die = function(self)
freeze -= self.ice freeze -= self.ice
self.ice = 0 self.ice = 0
frownie_t.__index.die(self) frownie.die(self)
end end
end end
@ -1029,7 +1001,7 @@ function spawn_bonus_frownie()
f.sprite = 7 f.sprite = 7
f.die = function(self) f.die = function(self)
spawn_repair_at(self.x+4, self.y+4) spawn_repair_at(self.x+4, self.y+4)
frownie_t.__index.die(self) frownie.die(self)
end end
end end
@ -1061,7 +1033,7 @@ function spawn_blocking_boss_chasey()
c.die = function(self) c.die = function(self)
freeze -= self.ice freeze -= self.ice
self.ice = 0 self.ice = 0
chasey_t.__index.die(self) chasey.die(self)
end end
local nextspawn = lframe + 120 local nextspawn = lframe + 120