methodize ship stuff, convert remaining add calls
This commit is contained in:
parent
3b8e86d0e7
commit
814149ceec
132
updatedshmup.p8
132
updatedshmup.p8
@ -176,7 +176,7 @@ end
|
|||||||
function updategame()
|
function updategame()
|
||||||
leveldone = level_frame()
|
leveldone = level_frame()
|
||||||
new_events = new_linked()
|
new_events = new_linked()
|
||||||
events:strip(call_f)
|
events:strip(call_move)
|
||||||
events:vore(new_events)
|
events:vore(new_events)
|
||||||
for _, lst in ipairs{intangibles_bg, pships, eships, pbullets, ebullets} do
|
for _, lst in ipairs{intangibles_bg, pships, eships, pbullets, ebullets} do
|
||||||
lst:strip(call_move)
|
lst:strip(call_move)
|
||||||
@ -239,7 +239,7 @@ function updategame()
|
|||||||
|
|
||||||
intangibles_fg:strip(call_move)
|
intangibles_fg:strip(call_move)
|
||||||
|
|
||||||
if leveldone and ((#eships + #ebullets + #events) == 0) then
|
if leveldone and not eships.next and not ebullets.next and not events.next then
|
||||||
state = win
|
state = win
|
||||||
end
|
end
|
||||||
if #pships == 0 then
|
if #pships == 0 then
|
||||||
@ -580,7 +580,7 @@ function spawn_spewy_at(x, y)
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
setmetatable(spewy, frownie_t)
|
setmetatable(spewy, frownie_t)
|
||||||
add(eships, spewy)
|
eships:push_back(spewy)
|
||||||
return spewy
|
return spewy
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ function spawn_chasey_at(x, y)
|
|||||||
main_gun = new_gun_of(zap_gun_t, true)
|
main_gun = new_gun_of(zap_gun_t, true)
|
||||||
}
|
}
|
||||||
setmetatable(c, chasey_t)
|
setmetatable(c, chasey_t)
|
||||||
add(eships, c)
|
eships:push_back(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -660,7 +660,7 @@ function spawn_xl_chasey_at(x, y)
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
setmetatable(c, chasey_t)
|
setmetatable(c, chasey_t)
|
||||||
add(eships, c)
|
eships:push_back(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
-->8
|
-->8
|
||||||
@ -694,50 +694,50 @@ ship_t = {
|
|||||||
__index = ship_m,
|
__index = ship_m,
|
||||||
}
|
}
|
||||||
|
|
||||||
function ship_m.die(s)
|
function ship_m:die()
|
||||||
s.dead = true
|
self.dead = true
|
||||||
if (s.hp <= 0) boom(s.x+s.size*4, s.y+s.size*4,12*s.size, s.boss)
|
if (self.hp <= 0) boom(self.x+self.size*4, self.y+self.size*4,12*self.size, self.boss)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ship_m.move(ship)
|
function ship_m:move()
|
||||||
ship:refresh_shield()
|
self:refresh_shield()
|
||||||
ship.power = min(ship.max_power, ship.power + ship.generator)
|
self.power = min(self.max_power, self.power + self.generator)
|
||||||
butt = ship:grab_butts()
|
butt = self:grab_butts()
|
||||||
if (butt[5] > 0) ship:maybe_shoot(ship.main_gun)
|
if (butt[5] > 0) self:maybe_shoot(self.main_gun)
|
||||||
if (butt[4] > 0) ship:maybe_shoot(ship.special_gun)
|
if (butt[4] > 0) self:maybe_shoot(self.special_gun)
|
||||||
if (butt[0]-butt[1] ~= 0 or butt[2]-butt[3] ~= 0) spark(ship.sparks, ship.x + 4*ship.size, ship.y + 4*ship.size, butt, ship.thrust, ship.sparkodds)
|
if (butt[0]-butt[1] ~= 0 or butt[2]-butt[3] ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, butt, self.thrust, self.sparkodds)
|
||||||
ship.xmomentum += (ship.thrust * butt[1]) - (ship.thrust * butt[0])
|
self.xmomentum += (self.thrust * butt[1]) - (self.thrust * butt[0])
|
||||||
ship.ymomentum += (ship.thrust * butt[3]) - (ship.thrust * butt[2])
|
self.ymomentum += (self.thrust * butt[3]) - (self.thrust * butt[2])
|
||||||
ship.xmomentum = mid(-ship.maxspd, ship.maxspd, ship.xmomentum)
|
self.xmomentum = mid(-self.maxspd, self.maxspd, self.xmomentum)
|
||||||
ship.ymomentum = mid(-ship.maxspd, ship.maxspd, ship.ymomentum)
|
self.ymomentum = mid(-self.maxspd, self.maxspd, self.ymomentum)
|
||||||
|
|
||||||
ship.x += ship.xmomentum
|
self.x += self.xmomentum
|
||||||
ship.y += ship.ymomentum
|
self.y += self.ymomentum
|
||||||
|
|
||||||
if ship == primary_ship then
|
if self == primary_self then
|
||||||
ship.x = mid(0, 112 - 8 * ship.size, ship.x)
|
self.x = mid(0, 112 - 8 * self.size, self.x)
|
||||||
ship.y = mid(0, 128 - 8 * ship.size, ship.y)
|
self.y = mid(0, 128 - 8 * self.size, self.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
--friction
|
--friction
|
||||||
local d = ship.drag
|
local d = self.drag
|
||||||
ship.xmomentum -= mid(d, -d, ship.xmomentum)
|
self.xmomentum -= mid(d, -d, self.xmomentum)
|
||||||
ship.ymomentum -= mid(d, -d, ship.ymomentum)
|
self.ymomentum -= mid(d, -d, self.ymomentum)
|
||||||
|
|
||||||
-- "scrolling" behavior
|
-- "scrolling" behavior
|
||||||
if ship.slip then
|
if self.slip then
|
||||||
ship.y += scrollrate
|
self.y += scrollrate
|
||||||
if ship.y >= 128 then
|
if self.y >= 128 then
|
||||||
ship:die()
|
self:die()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function ship_m.draw(ship)
|
function ship_m:draw()
|
||||||
if(ship.fx_pal) pal(ship.fx_pal)
|
if(self.fx_pal) pal(self.fx_pal)
|
||||||
spr(ship.sprite, ship.x, ship.y, ship.size, ship.size)
|
spr(self.sprite, self.x, self.y, self.size, self.size)
|
||||||
pal()
|
pal()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -940,7 +940,7 @@ function spawn_rnd_x(mt)
|
|||||||
y = -(mt.__index.size * 8 - 1)
|
y = -(mt.__index.size * 8 - 1)
|
||||||
}
|
}
|
||||||
setmetatable(s, mt)
|
setmetatable(s, mt)
|
||||||
add(eships, s)
|
eships:push_back(s)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -957,7 +957,7 @@ function spawn_blocking_rnd_x(mt)
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
setmetatable(s, mt)
|
setmetatable(s, mt)
|
||||||
add(eships, s)
|
eships:push_back(s)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1037,13 +1037,13 @@ function spawn_blocking_boss_chasey()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local nextspawn = lframe + 120
|
local nextspawn = lframe + 120
|
||||||
add(events, function()
|
events:push_back{move=function()
|
||||||
if lframe >= nextspawn then
|
if lframe >= nextspawn then
|
||||||
helpers[flr(rnd(#helpers))+1]()
|
helpers[flr(rnd(#helpers))+1]()
|
||||||
nextspawn += 60
|
nextspawn += 60
|
||||||
end
|
end
|
||||||
return c.dead
|
return c.dead
|
||||||
end)
|
end}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
@ -1080,13 +1080,13 @@ example_level = {
|
|||||||
[500]=function()
|
[500]=function()
|
||||||
local tnext = lframe
|
local tnext = lframe
|
||||||
local remain = 20
|
local remain = 20
|
||||||
add(events, function()
|
events:push_back{move=function()
|
||||||
if (lframe < tnext) return false
|
if (lframe < tnext) return false
|
||||||
spawn_blocking_blocky()
|
spawn_blocking_blocky()
|
||||||
tnext = lframe + 12
|
tnext = lframe + 12
|
||||||
remain -= 1
|
remain -= 1
|
||||||
return (remain <= 0)
|
return (remain <= 0)
|
||||||
end)
|
end}
|
||||||
end,
|
end,
|
||||||
[501]=spawn_bonus_frownie,
|
[501]=spawn_bonus_frownie,
|
||||||
[620]=spawn_blocking_blocky,
|
[620]=spawn_blocking_blocky,
|
||||||
@ -1180,15 +1180,14 @@ blast = {
|
|||||||
hitship = function(self, _)
|
hitship = function(self, _)
|
||||||
self.damage = 0
|
self.damage = 0
|
||||||
local wait = 2
|
local wait = 2
|
||||||
e = function()
|
events:push_back{move=function()
|
||||||
wait -= 1
|
wait -= 1
|
||||||
if wait <= 0 then
|
if wait <= 0 then
|
||||||
self.damage = 4
|
self.damage = 4
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end}
|
||||||
add(events, e)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
blast_t = {
|
blast_t = {
|
||||||
@ -1382,10 +1381,10 @@ function bullet_base:spawn_at(x, y)
|
|||||||
self.dx *= self.enemyspd
|
self.dx *= self.enemyspd
|
||||||
self.dy *= self.enemyspd
|
self.dy *= self.enemyspd
|
||||||
self.y = y + self.top_y_off
|
self.y = y + self.top_y_off
|
||||||
add(ebullets, self)
|
ebullets:push_back(self)
|
||||||
else
|
else
|
||||||
self.y = y - (8 * self.height) + self.bottom_y_off
|
self.y = y - (8 * self.height) + self.bottom_y_off
|
||||||
add(pbullets, self)
|
pbullets:push_back(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1829,36 +1828,30 @@ weird coding conventions
|
|||||||
-->8
|
-->8
|
||||||
-- standard events
|
-- standard events
|
||||||
|
|
||||||
blip_fx = {
|
blip_fx = {}
|
||||||
abort = function(self)
|
|
||||||
self.cancel = true
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
blip_fx_t = {
|
function blip_fx:move()
|
||||||
__index = blink_fx,
|
if (self.cancel) return true
|
||||||
__call = function(self)
|
self.frames -= 1
|
||||||
if (self.cancel) return true
|
if self.frames < 0 then
|
||||||
self.frames -= 1
|
self.obj.fx_pal = nil
|
||||||
if self.frames < 0 then
|
return true
|
||||||
self.obj.fx_pal = nil
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
}
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function blip_fx:abort()
|
||||||
|
self.cancel=true
|
||||||
|
end
|
||||||
|
|
||||||
|
mknew(blip_fx)
|
||||||
|
|
||||||
function blip(obj, col, frames)
|
function blip(obj, col, frames)
|
||||||
local p = {[0]=0}
|
local p = {[0]=0}
|
||||||
obj.fx_pal = p
|
obj.fx_pal = p
|
||||||
for i=1,15 do p[i]=col end
|
for i=1,15 do p[i]=col end
|
||||||
if (obj.___fx_pal_event) obj.___fx_pal_event:abort()
|
if (obj.___fx_pal_event) obj.___fx_pal_event:abort()
|
||||||
local e = {
|
events:push_back(blip_fx:new{frames=frames, obj=obj})
|
||||||
frames = frames,
|
|
||||||
obj = obj
|
|
||||||
}
|
|
||||||
setmetatable(e, blip_fx_t)
|
|
||||||
add(events, e)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bossspark = split"7,7,10,10,9,9,9,8,8,8,2,2,5,5"
|
bossspark = split"7,7,10,10,9,9,9,8,8,8,2,2,5,5"
|
||||||
@ -1883,7 +1876,8 @@ end
|
|||||||
function spark(sprs, x, y, butts, thrust, odds, fg)
|
function spark(sprs, x, y, butts, thrust, odds, fg)
|
||||||
if (sprs==nil or flr(rnd(odds)) ~= 0) return
|
if (sprs==nil or flr(rnd(odds)) ~= 0) return
|
||||||
thrust *= 2.5
|
thrust *= 2.5
|
||||||
add(fg and intangibles_fg or intangibles_bg, {
|
local target = fg and intangibles_fg or intangibles_bg
|
||||||
|
target:push_back{
|
||||||
x = x + rnd(4) - 2,
|
x = x + rnd(4) - 2,
|
||||||
y = y + rnd(4) - 2,
|
y = y + rnd(4) - 2,
|
||||||
sprs = sprs,
|
sprs = sprs,
|
||||||
@ -1901,7 +1895,7 @@ function spark(sprs, x, y, butts, thrust, odds, fg)
|
|||||||
self.dx -= mid(0.05,-0.05, self.dx)
|
self.dx -= mid(0.05,-0.05, self.dx)
|
||||||
self.dy -= mid(0.05,-0.05, self.dy)
|
self.dy -= mid(0.05,-0.05, self.dy)
|
||||||
end
|
end
|
||||||
})
|
}
|
||||||
end
|
end
|
||||||
-->8
|
-->8
|
||||||
-- powerups
|
-- powerups
|
||||||
|
Loading…
Reference in New Issue
Block a user