Compare commits

...

2 Commits

Author SHA1 Message Date
a4590821be
pre-initialize palettes for blip. costs tokens, saves time 2023-09-30 19:45:07 -07:00
cf1e1153a3
lframe increment is now 0x0.0001
avoids time rollover! not doing this for `distance` because I don't intend any level script to exceed five minutes, but freeze time could be much longer
2023-09-30 19:30:21 -07:00

View File

@ -118,6 +118,7 @@ function linked_list:pop_front()
end end
function _init() function _init()
init_blip_pals()
wipe_level() wipe_level()
primary_ship.main_gun = zap_gun.new() primary_ship.main_gun = zap_gun.new()
load_level(example_level) load_level(example_level)
@ -426,15 +427,13 @@ ship_m = {
shield = 0, shield = 0,
maxshield = 0, maxshield = 0,
shieldcost = 32767.9, shieldcost = 32767.9,
shieldcooldown = 180, shieldcooldown = 0x0.00a0,
-- default generator behavior: -- default generator behavior:
-- 10 seconds for a full charge -- 10 seconds for a full charge
max_power = 600, max_power = 600,
power = 600, power = 600,
generator = 1, -- power gen per frame generator = 1, -- power gen per frame
invincible_until = -32768,
slip = true, -- most enemies slide slip = true, -- most enemies slide
@ -517,7 +516,6 @@ end
function ship_m:hitsomething(dmg) function ship_m:hitsomething(dmg)
if (dmg <= 0) return false if (dmg <= 0) return false
if (lframe < self.invincible_until) return false
self.shield_refresh_ready = lframe + self.shieldcooldown self.shield_refresh_ready = lframe + self.shieldcooldown
if self.shield >= dmg then if self.shield >= dmg then
self.shield -= dmg self.shield -= dmg
@ -864,7 +862,7 @@ end
-- effective frame -- effective frame
distance = 0 distance = 0
-- actual frame count since -- actual frame count since
-- start of level -- start of level times 0x0.0001
lframe = 0 lframe = 0
-- do not advance distance when -- do not advance distance when
@ -888,7 +886,7 @@ function load_level(lvltbl)
end end
function level_frame() function level_frame()
lframe += 1 lframe += 0x0.0001
if (current_level == nil) return true if (current_level == nil) return true
if freeze == 0 then if freeze == 0 then
distance += 1 distance += 1
@ -1008,11 +1006,11 @@ function spawn_blocking_boss_chasey()
chasey.die(self) chasey.die(self)
end end
local nextspawn = lframe + 120 local nextspawn = lframe + 0x0.0080
events:push_back{move=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 += 0x0.0040
end end
return c.dead return c.dead
end} end}
@ -1055,7 +1053,7 @@ example_level = {
events:push_back{move=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 + 0x0.000c
remain -= 1 remain -= 1
return (remain <= 0) return (remain <= 0)
end} end}
@ -1176,7 +1174,7 @@ mknew(zap)
zap_gun = gun_base.new{ zap_gun = gun_base.new{
enemy = false, enemy = false,
power = 20, -- power consumed per shot power = 20, -- power consumed per shot
cooldown = 10, -- frames between shots cooldown = 0x0.000a, -- frames between shots
ammo = nil, -- unlimited ammo - main gun ammo = nil, -- unlimited ammo - main gun
t = zap -- metatable of bullet to fire t = zap -- metatable of bullet to fire
} }
@ -1233,7 +1231,7 @@ blast_gun = gun_base.new{
icon = 13, icon = 13,
enemy = false, enemy = false,
power = 0, -- ammo, not power power = 0, -- ammo, not power
cooldown = 30, -- frames between shots cooldown = 0x0.0020, -- frames between shots
ammo = 5, ammo = 5,
maxammo = 5, maxammo = 5,
t = blast -- type of bullet to fire t = blast -- type of bullet to fire
@ -1266,7 +1264,7 @@ protron_gun = gun_base.new{
icon = 25, icon = 25,
enemy = false, enemy = false,
power = 35, power = 35,
cooldown = 15, -- frames between shots cooldown = 0x0.000f, -- frames between shots
ammo = nil, ammo = nil,
maxammo = nil, maxammo = nil,
actually_shoot = function(self, x, y) actually_shoot = function(self, x, y)
@ -1324,7 +1322,7 @@ vulcan_gun = gun_base.new{
icon = 37, icon = 37,
enemy = false, enemy = false,
power = 8, power = 8,
cooldown = 2, -- frames between shots cooldown = 0x0.0002, -- frames between shots
ammo = nil, ammo = nil,
maxammo = nil, maxammo = nil,
dxs = {0.35, -0.35, -0.7, 0.7, 0.35, -0.35}, dxs = {0.35, -0.35, -0.7, 0.7, 0.35, -0.35},
@ -1573,21 +1571,22 @@ it sets lframe ("level frame")
and distance to 0. and distance to 0.
every frame, level_frame every frame, level_frame
increments lframe. then if the increments lframe by 0x0.0001.
level is not frozen (more on then if the level is not frozen,
that later), it increments it increments distance by 1.0
distance and runs the function and runs the function in the
in the level table for exactly level table for exactly that
that frame number (if any). frame number (if any). distance
distance is therefore "nonfrozen is therefore "nonfrozen frames",
frames", and is used to trigger and is used to trigger level
level progress. lframe always progress. lframe always
increments. ships are encouraged increments. ships are encouraged
to use lframe to control to use lframe to control
animation and movement, and may animation and movement, and may
use distance to react to level use distance to react to level
progress separately from overall progress separately from overall
time. time. remember to multiply
lframe-related stuff by 0x0001.
a special sentinel value, eol, a special sentinel value, eol,
marks the end of the level. marks the end of the level.
@ -1754,10 +1753,19 @@ end
mknew(blip_fx) mknew(blip_fx)
blip_pals = {}
function init_blip_pals()
for i=0,15 do
local pp = {[0]=0}
for j=1,15 do
pp[j] = i
end
blip_pals[i]=pp
end
end
function blip(obj, col, frames) function blip(obj, col, frames)
local p = {[0]=0} obj.fx_pal = blip_pals[col]
obj.fx_pal = p
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()
events:push_back(blip_fx.new{frames=frames, obj=obj}) events:push_back(blip_fx.new{frames=frames, obj=obj})
end end
@ -1842,7 +1850,7 @@ sheen8x8 = split"2,54,55,56,57,58,59,60,61"
function powerup:draw() function powerup:draw()
spr(self.sprites[max(1, spr(self.sprites[max(1,
(lframe\self.anim_speed) ((lframe<<16)\self.anim_speed)
%(#self.sprites+self.loop_pause) %(#self.sprites+self.loop_pause)
-self.loop_pause -self.loop_pause
+1)], +1)],