Compare commits

..

No commits in common. "main" and "do_rearm" have entirely different histories.

View File

@ -126,7 +126,8 @@ end
function _init()
mode = game_mode
init_blip_pals()
wipe_game() -- redundant?
wipe_level()
primary_ship.main_gun = zap_gun_p.new() -- redundant?
load_level(example_level_csv)
game_state = game
pal(2,129)
@ -156,7 +157,7 @@ function init_hpcols()
hpcols = hpcols_lut[min(primary_ship.maxhp,6)]
end
function wipe_game()
function wipe_level()
xpwhoosh = nil
primary_ship = player.new()
init_hpcols()
@ -169,8 +170,6 @@ function wipe_game()
intangibles_bg = linked_list.new()
events = linked_list.new()
new_events = linked_list.new()
primary_ship.main_gun = zap_gun_p.new()
primary_ship.main_gun:peel()
end
function _update60()
@ -364,8 +363,8 @@ function drawhud()
line(127,1,127,127,5)
line(113,127)
draw_gun_info("❎",1,116,3,1)
draw_gun_info("🅾️",1,116,29,2)
draw_gun_info("❎",1,116,3,primary_ship.main_gun)
draw_gun_info("🅾️",1,116,29,primary_ship.special_gun)
inset(114,57,119,118)
rectfill(119,57,124,58,13)
@ -405,13 +404,11 @@ function drawhud()
fillp(0)
end
function draw_gun_info(lbl,fgc,x,y,gn)
function draw_gun_info(lbl,fgc,x,y,gun)
dropshadow(lbl,x,y,fgc)
inset(114,y+7,125,y+18)
inset(114,y+20,125,y+24)
if (not primary_ship.special_guns) return
local gun = primary_ship.special_guns[gn]
if (not gun) return
if(gun) then
spr(gun.icon,116,y+9,1,1)
--115 to 124 - ammo bar. round up
if gun.ammo == nil then
@ -426,6 +423,7 @@ function draw_gun_info(lbl,fgc,x,y,gn)
else
line(118, y+22, 121, y+22, 2)
end
end
end
function vertmeter(x0,y0,x1,y1,val,maxval,cols)
@ -503,14 +501,14 @@ function ship_m:die()
-- overage XP, min 100
spawn_xp_at(cx, cy, 0, xp-0x0.018f)
xp = 0x0.018f -- dec 399
z += 2
z += 1
end
-- 100, 25, 5, 1
for gsz in all{0x0.0064, 0x0.0019, 0x0.0005, 0x0.0001} do
while xp >= gsz do
spawn_xp_at(cx, cy, z, gsz)
xp -= gsz
z += 2
z += 1
end
end
end
@ -556,12 +554,11 @@ end
function ship_m:move()
self:refresh_shield()
local dx, dy, shoot_spec1, shoot_spec2 = self:act()
local dx, dy, shoot_spec, shoot_main = self:act()
dx = self:constrain(self.x, self.xmomentum, self.xmin, self.xmax, dx)
dy = self:constrain(self.y, self.ymomentum, self.ymin, self.ymax, dy)
self:maybe_shoot(self.main_gun)
if (shoot_spec1 and self.special_guns) self:maybe_shoot(self.special_guns[1])
if (shoot_spec2 and self.special_guns) self:maybe_shoot(self.special_guns[2])
if (shoot_main) self:maybe_shoot(self.main_gun)
if (shoot_spec) self:maybe_shoot(self.special_gun)
if (dx ~= 0 or dy ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds)
self.xmomentum = self:calc_velocity(self.xmomentum, dx)
self.ymomentum = self:calc_velocity(self.ymomentum, dy)
@ -612,25 +609,30 @@ end
function ship_m:hitsomething(dmg)
if (dmg <= 0) return false
self.shield_refresh_ready = lframe + self.shieldpenalty
if self.shield > 0 then
if self.shield >= dmg then
self.shield -= dmg
if self.shield > 0 then
blip(self,12)
else
self.shield = 0
blip(self,8)
end
self:ow(true)
return false
end
dmg -= self.shield
self.shield = 0
self.hp -= dmg
if self.hp < 0 then
self:die()
return true
end
blip(self, 7)
self:ow(false)
return false
end
function ship_m:ow(shielded)
if (shielded) then
blip(self,12,3)
return
end
blip(self, 7, 3)
end
function ship_m:refresh_shield()
if (self.shield >= self.maxshield) return
if (lframe < self.shield_refresh_ready) return
@ -679,34 +681,6 @@ gun_base = mknew{
icon = 20
}
-- gun_base subtypes are
-- level-up options that,
-- as an action, assign
-- themselves to the player
function gun_base:action()
local item = self.new()
item:peel()
item.ammo = item.maxammo
if not primary_ship.special_guns then
primary_ship.special_guns = {item}
else
add(primary_ship.special_guns, item)
end
end
-- make shot type unique so
-- stat modifications do not
-- damage base data
function gun_base:peel()
self.munition = mknew(self.munition.new())
end
-- default firing behavior:
-- single shot
function gun_base:actually_shoot(x, y)
self.munition.new{}:spawn_at(x, y)
end
function bullet_base:hitship(_)
self:die()
return true
@ -730,6 +704,14 @@ function bullet_base:draw()
spr(self.sprite, self.x, self.y, self.width, self.height)
end
-- An `actually_shoot` factory
-- for trivial guns
function spawn_one(t)
return function(gun, x, y)
t.new{}:spawn_at(x, y)
end
end
function bullet_base:spawn_at(x, y)
self.x = x - self.x_off
self.y = y - self.y_off
@ -781,14 +763,13 @@ zap_p = mknew(zap_e.new{
})
zap_gun_e = mknew(gun_base.new{
cooldown = 0x0.0020, -- frames between shots
munition = zap_e,
cooldown = 0x0.000a, -- frames between shots
ammo = nil, -- unlimited ammo - main gun
actually_shoot = spawn_one(zap_e),
})
zap_gun_p = mknew(zap_gun_e.new{
icon = 19,
munition = zap_p,
hdr = "mAIN gUN",
actually_shoot = spawn_one(zap_p),
})
blast = mknew(bullet_base.new{
@ -807,22 +788,17 @@ blast = mknew(bullet_base.new{
damage = 4,
dx = 0, -- px/frame
dy = -1,
dy = -2,
awaitcancel = false,
-- disable damage for 4 frames
-- disable damage for 2 frames
-- when hitting something
-- todo: rewrite all ship hit
-- logic so i can avoid
-- repeating hits to the
-- same ship instead of
-- using a cooldown
hitship = function(self, _)
if self.damage > 0 and not self.awaitcancel then
self.awaitcancel = true
once_next_frame(function()
new_events:push_back{
wait = 4,
wait = 2,
obj = self,
saved_dmg = self.damage,
move = function(self)
@ -843,20 +819,10 @@ blast = mknew(bullet_base.new{
blast_gun = mknew(gun_base.new{
icon = 13,
cooldown = 0x0.0078, -- 120 frames between shots
cooldown = 0x0.0020, -- frames between shots
ammo = 5,
maxammo = 5,
munition = blast,
hdr = "bLASTER",
body= [[plasma orb
cuts through
enemies.
slow.
ammo: 5
rate: 1/2sec
dmg: 4
]],
actually_shoot = spawn_one(blast),
})
protron_e = mknew(bullet_base.new{
@ -888,7 +854,7 @@ protron_p = mknew(protron_e.new{
protron_gun_e = mknew(gun_base.new{
icon = 25,
cooldown = 0x0.0040, -- frames between shots
cooldown = 0x0.000f, -- frames between shots
ammo = nil,
maxammo = nil,
munition = protron_e
@ -917,17 +883,6 @@ end
protron_gun_p = mknew(protron_gun_e.new{
munition = protron_p,
maxammo = 20,
cooldown = 0x0.0018,
hdr = "pROTRON",
body = [[spray shots
in a dense
arc.
ammo: 20
rate: 2/sec
dmg: 1
]],
})
vulcan_e = mknew(bullet_base.new{
@ -960,7 +915,7 @@ vulcan_p = mknew(vulcan_e.new{
vulcan_gun_e = mknew(gun_base.new{
icon = 37,
enemy = false,
cooldown = 0x0.0003, -- frames between shots
cooldown = 0x0.0002, -- frames between shots
ammo = nil,
maxammo = nil,
munition=vulcan_e,
@ -979,16 +934,6 @@ vulcan_gun_e = mknew(gun_base.new{
vulcan_gun_p = mknew(vulcan_gun_e.new{
munition=vulcan_p,
maxammo = 100,
hdr = "vULCAN",
body = [[rapid fire
in a v
shape.
ammo: 100
rate: 20/sec
dmg: 0.5
]],
})
-->8
@ -1022,11 +967,10 @@ player = mknew(ship_m.new{
xptarget = 0x0.0004,
last_xp_frame = 0,
level = 1,
magnet = 10,
-- gun
main_gun = nil, -- assign at spawn time
special_guns = nil,
special_gun = nil,
fire_off_x = 4, -- offset where bullets come from
fire_off_y = 0,
@ -1035,10 +979,10 @@ player = mknew(ship_m.new{
y=96,
xmomentum = 0,
ymomentum = 0,
maxspd = 1.5, -- momentum cap
thrust = 0.1875, -- momentum added from button
maxspd = 2.5, -- momentum cap
thrust = 0.25, -- momentum added from button
ymin = 0, ymax = 120, -- stay on screen
drag = 0.0625, -- momentum lost per frame
drag = 0.125, -- momentum lost per frame
slip = false, -- does not slide down screen
act = function(self) -- fetch buttons
local b,th = btn(),self.thrust
@ -1065,86 +1009,6 @@ player = mknew(ship_m.new{
end,
})
function player:small_upgrade_opts()
local cdr, pr = (self.shieldcooldown - 0x0.000f) / 8, (self.shieldpenalty - 0x0.003c) / 9
if (cdr == 0 and self.shieldcooldown > 0x0.000f) cdr = 0x0.0001
if (pr == 0 and self.shieldpenalty > 0x0.003c) pr = 0x0.0001
local ret = {{
icon=53,
hdr="hull",
body=[[ armor
+2 hp]],
action=function()
self.maxhp += 2
self.hp += 2
end,
},{
icon=52,
hdr="shield",
body=[[ capacity
+1 hp]],
action=function()
self.maxshield += 1
self.shield += 1
end,
},{
icon=1,
hdr="thrusters",
body=[[performance
move faster,
steer faster]],
action=function()
--maxspd thrust drag
self.maxspd += 0.5
self.thrust += 0.0625
self.drag += 0.03125
end,
},{
icon=20,
hdr="hull",
body=[[ magnet
pick up xp
from further
away]],
action=function ()
self.magnet += 2
end,
}}
if cdr > 0 then
add(ret, {
icon = 6,
hdr = "shield",
body=[[charge rate
]] .. tostr(ceil(100 * cdr / self.shieldcooldown)) .. "% faster",
action = function()
self.shieldcooldown -= cdr
end
})
end
if pr > 0 then
add(ret, {
icon = 6,
hdr = "shield",
body=[[disruption
]] .. tostr(ceil(100 * pr / self.shieldpenalty)) .. "% shorter",
action = function()
self.shieldpenalty -= pr
end
})
end
return ret
end
frownie = mknew(ship_m.new{
--shape
sprite = 3, --index of ship sprite
@ -1249,7 +1113,6 @@ chasey = mknew(ship_m.new{
end
})
-- todo: use constraints
function chasey:act()
self.xmin = max(primary_ship.x-8, 0)
self.xmax = min(primary_ship.x + 8, 112 - 8*self.size)
@ -1482,9 +1345,32 @@ function spawn_blocking_spewy()
end
end
function spawn_vulcan_chasey()
function spawn_bonus_frownie()
local f = spawn_frownie()
f.sprite = 7
f.die = function(self)
spawn_repair_at(self.x+4, self.y+4)
frownie.die(self)
end
end
function spawn_bonus_vulcan_chasey()
local c = spawn_chasey()
c.main_gun=vulcan_gun_e.new{enemy=true}
c.die = function(self)
spawn_main_gun_at(self.x-1, self.y-1, vulcan_gun_p)
chasey.die(self)
end
c.sprite=4
return c
end
function spawn_bonus_shield_chasey()
local c = spawn_chasey()
c.die = function(self)
spawn_shield_upgrade_at(self.x-1, self.y-1)
chasey.die(self)
end
c.sprite=4
return c
end
@ -1533,6 +1419,7 @@ function spawn_rnd(typ, blocking, goodie,altspr)
freeze -= self.ice
self.ice=0
typ.die(self)
spawn_goodie(goodie, self.x, self.y, self.size)
end,
}
if (altspr) s.spr = altspr
@ -1540,6 +1427,14 @@ function spawn_rnd(typ, blocking, goodie,altspr)
return s
end
-- TODO: spawn_goodie compatible versions of gun drops
-- TODO: goodie table
function spawn_goodie(goodie_name, x, y, sz)
if (not goodie_name or #goodie_name == 0) return
local sh = sz and sz/2 or 0
_ENV[goodie_name].new{}:spawn_at(x+sh,y+sh)
end
function multi(times, interval, fnm, ...)
local f,irm,vargs = _ENV[fnm],interval,pack(...)
assert(type(f) == "function", fnm.." not a function")
@ -1562,29 +1457,31 @@ end
-- where offset,eol is a special case.
example_level_csv=[[1,spawn_frownie
60,spawn_vulcan_chasey
60,spawn_bonus_vulcan_chasey
61,spawn_blocky
85,spawn_spewy
100,spawn_spewy
115,spawn_spewy
130,spawn_frownie
145,spawn_frownie
180,spawn_spewy
230,spawn_chasey
130,spawn_bonus_frownie
145,spawn_spewy
200,spawn_bonus_shield_chasey
250,spawn_blocking_blocky
285,spawn_spec_gun_at,35,-11,blast_gun
310,spawn_blocking_blocky
310,spawn_blocking_blocky
310,spawn_blocking_blocky
311,spawn_frownie
350,spawn_main_gun_at,70,-11,protron_gun_p
401,spawn_frownie
420,spawn_blocking_frownie
430,spawn_vulcan_chasey
430,spawn_bonus_vulcan_chasey
450,spawn_frownie
465,spawn_frownie
465,spawn_bonus_frownie
480,spawn_chasey
500,multi,20,12,spawn_blocking_blocky
501,spawn_frownie
501,spawn_bonus_frownie
620,spawn_blocking_blocky
630,spawn_vulcan_chasey
630,spawn_bonus_shield_chasey
720,spawn_blocking_boss_chasey
721,eol]]
@ -1620,10 +1517,10 @@ function init_blip_pals()
end
end
function blip(obj, col)
function blip(obj, col, frames)
obj.fx_pal = blip_pals[col]
if (obj.___fx_pal_event) obj.___fx_pal_event:abort()
events:push_back(blip_fx.new{frames=3, obj=obj})
events:push_back(blip_fx.new{frames=frames, obj=obj})
end
bossspark = split"7,7,10,10,9,9,9,8,8,8,2,2,5,5"
@ -1706,22 +1603,11 @@ function xp_gem:draw()
)
end
function xp_gem:move()
if not primary_ship.dead and abs(self.x + 1 - primary_ship.x - primary_ship.hurt.x_off) <= primary_ship.magnet and abs(self.y + 1 - primary_ship.y - primary_ship.hurt.y_off) <= primary_ship.magnet then
if (self.x < primary_ship.x + 3) self.x += 1
if (self.x > primary_ship.x + 5) self.x -= 1
if (self.y < primary_ship.y + 3) self.y += 1
if (self.y > primary_ship.y + 5) self.y -= 1
end
return bullet_base.move(self)
end
-- todo: "magnetic" behavior
-- when near player ship
function xp_gem:hitship(ship)
if (ship ~= primary_ship or primary_ship.dead) return false
if (ship ~= primary_ship) return false
primary_ship.xp += self.val
primary_ship.last_xp_frame = lframe
return true
@ -1738,63 +1624,137 @@ function spawn_xp_at(x, y, off, amt)
}:spawn_at(mid(x, 0, 124),mid(y,-4,125))
end
-->8
-- upgrade options
powerup = mknew(bullet_base.new{
-- animated sprite array: "sprites"
-- to draw under or over anim,
-- override draw, draw the
-- under-part, call into
-- powerup.draw(self), then
-- draw the over-part
width = 1,
height = 1,
-- note: make hurtboxes larger
-- than sprite by 2px per side
-- since ship hitbox is tiny
-- but powerups should feel
-- easy to pick up
dx = 0,
dy = 0.75,
category = enemy_blt_cat, -- collides with player ship
damage = 0,
-- all these return
-- a [2] of rearm_t:
--
-- icon: sprite id
-- hdr: title text
-- body: text
-- action: callback
-- (method)
anim_speed = 2,
loop_pause = 30 -- affected by animspeed
})
spec_gunt = {
protron_gun_p,
vulcan_gun_p,
blast_gun,
-- sprite indexes for "sheen" animation
sheen8x8 = split"2,54,55,56,57,58,59,60,61"
function powerup:draw()
spr(self.sprites[max(1,
((lframe<<16)\self.anim_speed)
%(#self.sprites+self.loop_pause)
-self.loop_pause
+1)],
self.x, self.y,
self.width, self.height)
end
repair = mknew(powerup.new{
hurt = {
x_off = -2,
y_off = -2,
width = 12,
height = 12
},
x_off = 4,
y_off = 0,
sprites = sheen8x8,
icon = 53,
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(self.icon, self.x, self.y, self.width, self.height)
powerup.draw(self)
end
})
function spawn_repair_at(x, y)
repair.new():spawn_at(x, y)
end
shield_upgrade = mknew(repair.new{
icon=52
})
function shield_upgrade:hitship(ship)
if (ship ~= primary_ship) return false
primary_ship.maxshield += 1
return true
end
function spawn_shield_upgrade_at(x, y)
shield_upgrade.new():spawn_at(x,y)
end
gun_swap = mknew(powerup.new{
hurt = {
x_off = -2,
y_off = -2,
width = 16,
height = 16
},
-- gun = gun_type.new{}
x_off = 6,
y_off = 0,
width = 2,
height = 2,
sprites = {64, 66, 68, 70, 72, 74, 76, 78},
hitship = function(self, ship)
if (ship ~= primary_ship) return false
ship.main_gun = self.gun
return true
end,
draw = function(self)
powerup.draw(self)
spr(self.gun.icon, self.x+2, self.y+2, 1, 1)
end
})
function spawn_main_gun_at(x, y, gunt)
if (type(gunt)=="string") gunt=_ENV[gunt]
local gun_p = gun_swap.new{
gun = gunt.new()
}
gun_p:spawn_at(x, y)
end
spec_gun_pl = {
[1] = 2,
[14] = 6,
[2] = 14
}
-- picks n random items from
-- tbl; permutes tbl, selected
-- items at end
function pick(tbl, n)
local ret, top={}, #tbl
for x=top,top-n,-1 do
local idx = 1+rnd(x)\1
add(ret, tbl[idx])
tbl[idx]=tbl[x]
tbl[x]=ret[#ret]
function spawn_spec_gun_at(x, y, gunt)
if (type(gunt)=="string") gunt=_ENV[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
return true
end,
draw = function(self)
pal(spec_gun_pl)
powerup.draw(self)
pal()
spr(self.gun.icon, self.x+2, self.y+2, 1, 1)
end
return ret
end
-- add a new gun
function spec_gun_opts()
return pick(spec_gunt, 2)
end
-- major upgrades
function big_opts()
return {{
icon=1,
hdr="placeholder",
body="placeholder",
action = function() end,
},
{
icon=1,
hdr="placeholder",
body="placeholder",
action = function() end,
}}
end
-- ordinary upgrades
function small_opts()
-- todo: include gun opts
return pick(primary_ship:small_upgrade_opts(), 2)
}
gun_p:spawn_at(x, y)
end
-->8
@ -1851,7 +1811,7 @@ end
function rearm_mode:draw_option(id)
local rec = self.options[id]
self:glow_box(0,0,55,100,self:frame_col(self.sel == id),1)
spr(rec.icon,5, 5)
spr(rec.s,5, 5)
print(rec.hdr, 13, 8, 7)
print(rec.body, 5, 15, 6)
end
@ -1868,14 +1828,17 @@ function rearm_mode:shuffle()
-- these will be placeholders
-- until the upgrade deck
-- is a thing that exists
local lev = primary_ship.level
if lev == 4 or lev == 12 then
self.options = spec_gun_opts()
elseif lev % 4 == 0 then
self.options = big_opts()
else
self.options = small_opts()
end
self.options = {{
s=1,
hdr=" hull",
body = "\n +1\n max\n health",
action = function() end,
},{
s=37,
hdr=" vulc",
body = "\nplaceholder",
action = function() end,
}}
end
function rearm_mode:draw()
@ -1931,11 +1894,7 @@ function rearm_mode:update()
-- todo: sound: rearm
primary_ship.shield = primary_ship.maxshield
-- todo: rewrite for three guns
local specs = primary_ship.special_guns
if specs then
specs[1].ammo = specs[1].maxammo
if (specs[2]) specs[2].ammo = specs[2].maxammo
end
if (primary_ship.special_gun) primary_ship.special_gun.ammo = primary_ship.special_gun.max_ammo
primary_ship.hp = min(primary_ship.maxhp, primary_ship.hp + primary_ship.maxhp/2)
primary_ship.xp -= primary_ship.xptarget / 2
else
@ -1962,14 +1921,14 @@ __gfx__
0070070065666765000000000ddddd100b33355009444220c000000c03333350b7000000a800000008888820048488203bbaabb3288aa8820000000000000000
000000006506506500000000001111000b0b5050090920200c0000c00055550037000000a2000000008882000048420003bbbb30028888200000000000000000
00000000650000650000000000000000000b50000009200000c0cc00000000003b00000082000000000820000008200000333300002222000000000000000000
0000000000065000000650000003b0000070070080000000700000000bb0000008800000000000000009200000000000cccccccd000650000000000000000000
000000000067500000076500000370000005500080000000b0000000b76300008a920000000000009009200200000000c111111d006765000000000000000000
00000000006d6500006d6500000b7000700660079000000030000000b663000089920000000550009994444200000000c111111d006d65000000000000000000
00000000067c6650067c6650000b7000056ccd50a000000030000000033000000220000000576d009446544200000000c111111d067c66500000000000000000
00000000067d6650067d6650000b7000056ccd500000000000000000000000000000000000566d009244442200000000c111111d067d66500000000000000000
000000005666657576667650000b7000700dd00700000000000000000000000000000000000dd0009092220200000000c111111d656667650000000000000000
000000005656506666565650000370000005500000000000000000000000000000000000000000000090020000000000c111111d650650650000000000000000
0000000056500056650006500003b00000700700000000000000000000000000000000000000000000a00a0000000000cddddddd650000650000000000000000
00000000000650000006500000000000b000000b80000000700000000bb0000008800000000000000009200000000000cccccccd000650000000000000000000
0000000000675000000765000000000000bbbb0080000000b0000000b76300008a920000000000009009200200000000c111111d006765000000000000000000
00000000006d6500006d6500000000000b0000b09000000030000000b663000089920000000550009994444200000000c111111d006d65000000000000000000
00000000067c6650067c6650000000000b0bb0b0a000000030000000033000000220000000576d009446544200000000c111111d067c66500000000000000000
00000000067d6650067d6650000000000b0bb0b00000000000000000000000000000000000566d009244442200000000c111111d067d66500000000000000000
000000005666657576667650000000000b0000b000000000000000000000000000000000000dd0009092220200000000c111111d656667650000000000000000
0000000056565066665656500000000000bbbb0000000000000000000000000000000000000000000090020000000000c111111d650650650000000000000000
00000000565000566500065000000000b000000b000000000000000000000000000000000000000000a00a0000000000cddddddd650000650000000000000000
060007000600070006600770766c777c0000000000a0008000000000000000000000000000000000000000000000000000000000000000000000000000000000
6cd07cd06cd07cd06ccd7ccd6ccd7ccd000000000090008000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d000d006cd07cd06ccd7ccd6ccd7ccd0000000000800a0000000000000000000000000000000000000000000000000000000000000000000000000000000000