Compare commits

..

2 Commits

Author SHA1 Message Date
bad8452f3c
migrate ships to mknew style 2023-09-30 14:24:31 -07:00
f49407baca
move ship typedefs before ship impls 2023-09-30 14:11:36 -07:00

View File

@ -153,7 +153,7 @@ function init_hpcols()
end
function wipe_level()
primary_ship = new_p1()
primary_ship = player.new()
init_hpcols()
pships = linked_list.new()
pships:push_back(primary_ship)
@ -440,258 +440,6 @@ function grab_p1_butts()
}
end
-->8
--ships, including player
-- XXX BOOKMARK XXX
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"
smokespark = split"13, 13, 5, 5"
player = {
--shape
sprite = 1, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
hurt = { -- hurtbox - where this ship can be hit
x_off = 3, -- upper left corner
y_off = 2, -- relative to ship ulc
width = 1,
height = 3
},
sparks = firespark, -- see tab 9
sparkodds = 2,
boss = true, -- dramatic special effects
-- health and power
hp = 3, -- current health, non-regenerating
maxhp = 3, -- player only; other ships never heal
shield = 2, -- regenerates, using power
maxshield = 2,
shieldcost = 300, -- power cost to refill shield
generator = 1.5, -- 1 feels too slow
-- gun
main_gun = nil, -- assign at spawn time
special_gun = nil,
fire_off_x = 4, -- offset where bullets come from
fire_off_y = 0,
-- position
x=52, -- x and y are for upper left corner
y=96,
xmomentum = 0,
ymomentum = 0,
maxspd = 2.5, -- momentum cap
thrust = 0.25, -- momentum added from button
drag = 0.125, -- momentum lost per frame
slip = false, -- does not slide down screen
grab_butts = function(self) -- fetch buttons
local butts = grab_p1_butts()
if butts[0] == butts[1] then
self.sprite = 1
elseif butts[0] > 0 then
self.sprite = 17
else
self.sprite = 18
end
return butts
end
}
player_t = {
__index = player
}
function new_p1()
p = {
main_gun = new_gun_of(zap_gun_t, false)
}
setmetatable(p, player_t)
return p
end
frownie = {
--shape
sprite = 3, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
hurt = { -- hurtbox - where this ship can be hit
x_off = 0, -- upper left corner
y_off = 1, -- relative to ship ulc
width = 8,
height = 6
},
sparks = smokespark,
sparkodds = 8,
-- health and power
hp = 1, -- enemy ships need no max hp
-- position
x=60, -- x and y are for upper left corner
y=8,
xmomentum = 0,
ymomentum = 0,
maxspd = 2, -- momentum cap
thrust = 0.12, -- momentum added from button
drag = 0.07, -- momentum lost per frame
slip = true,
grab_butts = function(discard_self)
-- buttons are effectively analog
-- and negative buttons work just fine!
local butts = {}
local tstate = (1 + flr(4*t() + 0.5)) % 6
butts[0] = ((tstate==1 or tstate==2) and 1) or 0
butts[1] = ((tstate==4 or tstate==5) and 1) or 0
for b=2, 5 do
butts[b]=0
end
return butts
end, -- button fetch algorithm
}
frownie_t = {
__index = frownie
}
blocky = {
sprite = 10,
hp = 2,
hurt = {
x_off = 0,
y_off = 0,
width = 8,
height = 7
},
ow = function(self)
if self.hp <= 1 then
self.sprite = 11
else
self.sprite = 10
end
ship_t.__index.ow(self)
end
}
blocky_t = {
__index = blocky
}
function spawn_spewy_at(x, y)
local spewy = {
x = x,
y = y,
sprite = 26,
power = -20,
hurt = {
x_off = 0,
y_off = 1,
width = 8,
height = 5
},
hp = 1,
maxpower = 70,
generator = 0.5,
main_gun = new_gun_of(protron_gun_t, true),
fire_off_x = 4,
fire_off_y = 7,
grab_butts = function()
local butts = frownie.grab_butts()
butts[5] = 1
return butts
end,
}
setmetatable(spewy, frownie_t)
eships:push_back(spewy)
return spewy
end
chasey = {
sprite = 5,
size = 1,
hurt = {
x_off = 1,
y_off = 2,
width = 6,
height = 5,
},
sparks = smokespark,
sparkodds = 8,
hp = 2,
shield = 1,
maxshield = 1,
shieldcost = 180,
fire_off_x = 4,
fire_off_y = 7,
maxspd = 2,
thrust = 0.2,
drag = 0.075,
slip = true,
grab_butts = function(self)
local butts = {0,0,0,0,0}
butts[0] = 0
if (self.x < primary_ship.x) butts[1] = 1
if (self.x > primary_ship.x) butts[0] = 1
if (self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x) butts[5] = 1
return butts
end,
}
chasey_t = {
__index = chasey
}
function spawn_chasey_at(x, y)
local c = {
x = x,
y = y,
main_gun = new_gun_of(zap_gun_t, true)
}
setmetatable(c, chasey_t)
eships:push_back(c)
return c
end
function spawn_xl_chasey_at(x, y)
local c = {
x = x,
y = y,
size = 2,
maxspd = 1.25,
hurt = {
x_off = 2,
y_off = 4,
width = 12,
height = 10
},
hp = 20,
shield = 5,
boss = true,
slip = false,
main_gun = new_gun_of(zap_gun_t, true),
grab_butts = function(self)
local butts = chasey.grab_butts(self)
if (self.y < 4) butts[3] = 1
return butts
end,
draw = function(self)
if(self.fx_pal) pal(self.fx_pal)
sspr(40, 0, 8, 8, self.x, self.y, 16, 16)
pal()
end,
}
setmetatable(c, chasey_t)
eships:push_back(c)
return c
end
-->8
--ship behavior
@ -718,10 +466,7 @@ ship_m = {
xmomentum = 0,
ymomentum = 0,
}
ship_t = {
__index = ship_m,
}
mknew(ship_m)
function ship_m:die()
self.dead = true
@ -766,8 +511,8 @@ end
function ship_m:draw()
if(self.fx_pal) pal(self.fx_pal)
spr(self.sprite, self.x, self.y, self.size, self.size)
pal()
spr(self.sprite, self.x, self.y, self.size, self.size)
pal()
end
function hurtbox(ship)
@ -831,6 +576,234 @@ function ship_m:refresh_shield()
self.power -= self.shieldcost
self.shield_refresh_ready = lframe + self.shieldcooldown
end
-->8
--ships, including player
firespark = split"9, 8, 2, 5, 1"
smokespark = split"13, 13, 5, 5"
player = ship_m.new{
--shape
sprite = 1, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
hurt = { -- hurtbox - where this ship can be hit
x_off = 3, -- upper left corner
y_off = 2, -- relative to ship ulc
width = 1,
height = 3
},
sparks = firespark, -- see tab 9
sparkodds = 2,
boss = true, -- dramatic special effects
-- health and power
hp = 3, -- current health, non-regenerating
maxhp = 3, -- player only; other ships never heal
shield = 2, -- regenerates, using power
maxshield = 2,
shieldcost = 300, -- power cost to refill shield
generator = 1.5, -- 1 feels too slow
-- gun
main_gun = nil, -- assign at spawn time
special_gun = nil,
fire_off_x = 4, -- offset where bullets come from
fire_off_y = 0,
-- position
x=52, -- x and y are for upper left corner
y=96,
xmomentum = 0,
ymomentum = 0,
maxspd = 2.5, -- momentum cap
thrust = 0.25, -- momentum added from button
drag = 0.125, -- momentum lost per frame
slip = false, -- does not slide down screen
grab_butts = function(self) -- fetch buttons
local butts = grab_p1_butts()
if butts[0] == butts[1] then
self.sprite = 1
elseif butts[0] > 0 then
self.sprite = 17
else
self.sprite = 18
end
return butts
end
}
mknew(player,
function(p)
p.main_gun = new_gun_of(zap_gun_t, false)
end
)
frownie = ship_m.new{
--shape
sprite = 3, --index of ship sprite
size = 1, --all ships are square; how many 8x8 sprites?
hurt = { -- hurtbox - where this ship can be hit
x_off = 0, -- upper left corner
y_off = 1, -- relative to ship ulc
width = 8,
height = 6
},
sparks = smokespark,
sparkodds = 8,
-- health and power
hp = 1, -- enemy ships need no max hp
-- position
x=60, -- x and y are for upper left corner
y=8,
xmomentum = 0,
ymomentum = 0,
maxspd = 2, -- momentum cap
thrust = 0.12, -- momentum added from button
drag = 0.07, -- momentum lost per frame
slip = true,
grab_butts = function(discard_self)
-- buttons are effectively analog
-- and negative buttons work just fine!
local butts = {}
local tstate = (1 + flr(4*t() + 0.5)) % 6
butts[0] = ((tstate==1 or tstate==2) and 1) or 0
butts[1] = ((tstate==4 or tstate==5) and 1) or 0
for b=2, 5 do
butts[b]=0
end
return butts
end, -- button fetch algorithm
}
mknew(frownie)
blocky = frownie.new{
sprite = 10,
hp = 2,
hurt = {
x_off = 0,
y_off = 0,
width = 8,
height = 7
},
ow = function(self)
if self.hp <= 1 then
self.sprite = 11
else
self.sprite = 10
end
ship_m.ow(self)
end
}
mknew(blocky)
function spawn_spewy_at(x, y)
local spewy = frownie.new{
x = x,
y = y,
sprite = 26,
power = -20,
hurt = {
x_off = 0,
y_off = 1,
width = 8,
height = 5
},
hp = 1,
maxpower = 70,
generator = 0.5,
main_gun = new_gun_of(protron_gun_t, true),
fire_off_x = 4,
fire_off_y = 7,
grab_butts = function()
local butts = frownie.grab_butts()
butts[5] = 1
return butts
end,
}
eships:push_back(spewy)
return spewy
end
chasey = ship_m.new{
sprite = 5,
size = 1,
hurt = {
x_off = 1,
y_off = 2,
width = 6,
height = 5,
},
sparks = smokespark,
sparkodds = 8,
hp = 2,
shield = 1,
maxshield = 1,
shieldcost = 180,
fire_off_x = 4,
fire_off_y = 7,
maxspd = 2,
thrust = 0.2,
drag = 0.075,
slip = true,
grab_butts = function(self)
local butts = {0,0,0,0,0}
butts[0] = 0
if (self.x < primary_ship.x) butts[1] = 1
if (self.x > primary_ship.x) butts[0] = 1
if (self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x) butts[5] = 1
return butts
end,
}
mknew(chasey)
function spawn_chasey_at(x, y)
local c = chasey.new{
x = x,
y = y,
main_gun = new_gun_of(zap_gun_t, true)
}
eships:push_back(c)
return c
end
function spawn_xl_chasey_at(x, y)
local c = chasey.new{
x = x,
y = y,
size = 2,
maxspd = 1.25,
hurt = {
x_off = 2,
y_off = 4,
width = 12,
height = 10
},
hp = 20,
shield = 5,
boss = true,
slip = false,
main_gun = new_gun_of(zap_gun_t, true),
grab_butts = function(self)
local butts = chasey.grab_butts(self)
if (self.y < 4) butts[3] = 1
return butts
end,
draw = function(self)
if(self.fx_pal) pal(self.fx_pal)
sspr(40, 0, 8, 8, self.x, self.y, 16, 16)
pal()
end,
}
eships:push_back(c)
return c
end
-->8
-- collisions
@ -963,19 +936,18 @@ end
-->8
-- example level
function spawn_rnd_x(mt)
s = {
function spawn_rnd_x(typ)
s = typ.new{
x = rnd(104),
y = -(mt.__index.size * 8 - 1)
}
setmetatable(s, mt)
eships:push_back(s)
return s
end
function spawn_blocking_rnd_x(mt)
function spawn_blocking_rnd_x(typ)
freeze += 1
s = {
s = typ.new{
x = rnd(104),
y = -7,
ice = 1,
@ -985,25 +957,24 @@ function spawn_blocking_rnd_x(mt)
mt.__index.die(self)
end
}
setmetatable(s, mt)
eships:push_back(s)
return s
end
function spawn_frownie()
return spawn_rnd_x(frownie_t)
return spawn_rnd_x(frownie)
end
function spawn_blocking_frownie()
spawn_blocking_rnd_x(frownie_t)
spawn_blocking_rnd_x(frownie)
end
function spawn_blocky()
spawn_rnd_x(blocky_t)
spawn_rnd_x(blocky)
end
function spawn_blocking_blocky()
spawn_blocking_rnd_x(blocky_t)
spawn_blocking_rnd_x(blocky)
end
function spawn_spewy()
@ -1021,7 +992,7 @@ function spawn_blocking_spewy()
s.die = function(self)
freeze -= self.ice
self.ice = 0
frownie_t.__index.die(self)
frownie.die(self)
end
end
@ -1030,7 +1001,7 @@ function spawn_bonus_frownie()
f.sprite = 7
f.die = function(self)
spawn_repair_at(self.x+4, self.y+4)
frownie_t.__index.die(self)
frownie.die(self)
end
end
@ -1062,7 +1033,7 @@ function spawn_blocking_boss_chasey()
c.die = function(self)
freeze -= self.ice
self.ice = 0
chasey_t.__index.die(self)
chasey.die(self)
end
local nextspawn = lframe + 120