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