Compare commits

..

No commits in common. "804eb62ae74343892047994e31b9c2afd1d0e3ae" and "b379e47dbf69bbdcc1646ce662851a9ff67aa7bc" have entirely different histories.

View File

@ -339,10 +339,10 @@ function drawhud()
draw_gun_info("❎",1,116,3,primary_ship.main_gun)
draw_gun_info("🅾️",1,116,31,primary_ship.special_gun)
dropshadow("x h",114,59,1)
dropshadow("p h",114,59,1)
inset(114,66,119,125)
fillp(0x5a5a)
vertmeter(115,67,118,124,primary_ship.xp, primary_ship.xptarget, powcols)
vertmeter(115,67,118,124,primary_ship.power, primary_ship.max_power, powcols)
inset(120,66,125,125)
-- 57 px vertically
@ -425,9 +425,14 @@ ship_m = mknew{
-- ships have no shield by default
shield = 0,
maxshield = 0,
shieldcost = 32767.9,
shieldcooldown = 0x0.003c,--1s
shieldpenalty = 0x0.012c, --5s
max_power = 120,
power = 120,
generator = 2, -- power gen per frame
slip = true, -- most enemies slide
xmomentum = 0,
@ -487,6 +492,7 @@ end
function ship_m:move()
self:refresh_shield()
self.power = min(self.max_power, self.power + self.generator)
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)
@ -528,7 +534,9 @@ end
function ship_m:maybe_shoot(gun)
if (not gun) return
return gun:shoot(self.x + self.fire_off_x, self.y + self.fire_off_y)
if (self.power < gun.power) return
if (not gun:shoot(self.x + self.fire_off_x, self.y + self.fire_off_y)) return
self.power -= gun.power
end
function ship_m:hitship(other)
@ -569,8 +577,10 @@ end
function ship_m:refresh_shield()
if (self.shield >= self.maxshield) return
if (lframe < self.shield_refresh_ready) return
if (self.power < self.shieldcost) return
self.shield += 1
self.shield = min(self.shield, self.maxshield)
self.power -= self.shieldcost
self.shield_refresh_ready = lframe + self.shieldcooldown
end
@ -585,28 +595,6 @@ function enemy_blt_cat()
return ebullets
end
-- x, y: position
-- dx, dy: movement (linear)
-- f: frames remaining; nil for no limit
-- sprite: what sprite to draw
-- hurt -- hurtbox
-- width, height -- in sprites
-- x_off, y_off -- how to
-- initially position relative
-- to firing point. weird
-- details, check impl
-- damage -- damage to do to
-- a ship that gets hit
-- category -- function that
-- returns which bullet list
-- to spawn onto
-- hitship -- event handler,
-- takes ship as argument.
-- default: die, return true.
-- returns whether to delete
-- the bullet
-- die -- on-removal event,
-- default no-op
bullet_base = mknew{ }
gun_base = mknew{
@ -625,8 +613,7 @@ end
function bullet_base:move()
self.x += self.dx
self.y += self.dy
if (self.f) self.f -= 1
if (self.y > 128) or (self.y < -8 * self.height) or (self.f and self.f < 0) then
if (self.y > 128) or (self.y < -8 * self.height) then
self:die()
return true
end
@ -667,7 +654,7 @@ end
zap_e = mknew(bullet_base.new{
--shape
sprite = 9, --index of ammo sprite
sprite = 9, --index of enemy ammo sprite
width = 1, --in 8x8 blocks
height = 1,
hurt = { -- hurtbox - where this ship can be hit
@ -696,6 +683,7 @@ zap_p = mknew(zap_e.new{
})
zap_gun_e = mknew(gun_base.new{
power = 20, -- power consumed per shot
cooldown = 0x0.000a, -- frames between shots
ammo = nil, -- unlimited ammo - main gun
actually_shoot = spawn_one(zap_e),
@ -752,6 +740,7 @@ blast = mknew(bullet_base.new{
blast_gun = mknew(gun_base.new{
icon = 13,
power = 0, -- only cost is ammo
cooldown = 0x0.0020, -- frames between shots
ammo = 5,
maxammo = 5,
@ -787,6 +776,7 @@ protron_p = mknew(protron_e.new{
protron_gun_e = mknew(gun_base.new{
icon = 25,
power = 60,
cooldown = 0x0.000f, -- frames between shots
ammo = nil,
maxammo = nil,
@ -848,6 +838,7 @@ vulcan_p = mknew(vulcan_e.new{
vulcan_gun_e = mknew(gun_base.new{
icon = 37,
enemy = false,
power = 8,
cooldown = 0x0.0002, -- frames between shots
ammo = nil,
maxammo = nil,
@ -889,16 +880,13 @@ player = mknew(ship_m.new{
sparkodds = 2,
boss = true, -- dramatic special effects
-- health
-- health and power
hp = 3, -- current health, non-regenerating
maxhp = 3, -- player only; other ships never heal
shield = 2, -- regenerates
shield = 2, -- regenerates, using power
maxshield = 2,
-- xp, increments of 0x0.01
xp = 0,
xptarget = 0x0.05,
level = 1,
shieldcost = 60, -- power cost to refill shield
generator = 2,
-- gun
main_gun = nil, -- assign at spawn time
@ -954,7 +942,7 @@ frownie = mknew(ship_m.new{
sparks = smokespark,
sparkodds = 8,
-- health
-- health and power
hp = 0.5, -- enemy ships need no max hp
-- position
@ -996,6 +984,7 @@ blocky = mknew(frownie.new{
spewy = mknew(frownie.new{
sprite=26,
power=-20,
hurt = {
x_off=0,
y_off=1,
@ -1003,11 +992,13 @@ spewy = mknew(frownie.new{
height=5
},
hp=0.5,
maxpower=70,
generator=0.5,
fire_off_x=4,
fire_off_y=7,
fire_off_y = 7,
act=function(self)
local dx,dy,shoot_spec=frownie.act(self)
return dx, dy, shoot_spec, self.y > 10
return dx, dy, shoot_spec, true
end,
init = function(ship)
ship.main_gun=ship.main_gun or protron_gun_e.new{}
@ -1028,6 +1019,7 @@ chasey = mknew(ship_m.new{
hp = 1.5,
shield = 1,
maxshield = 1,
shieldcost = 180,
fire_off_x = 4,
fire_off_y = 7,
@ -1045,7 +1037,7 @@ chasey = mknew(ship_m.new{
function chasey:act()
self.xmin = max(primary_ship.x-8, 0)
self.xmax = min(primary_ship.x + 8, 112 - 8*self.size)
return 0, 0, false, self.y > 10 and self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x
return 0, 0, false, self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x
end
xl_chasey=mknew(chasey.new{
@ -1463,6 +1455,10 @@ algorithm expressed.
guns
----
* power - cost in generator
power to fire. may be 0.
field directly read by ships;
required in all guns.
* t - metatable for bullet type.
fired once in the bullet's
default direction per shot.
@ -1490,6 +1486,11 @@ actually_shoot to change
projectile logic while keeping
cooldown and ammo logic.
ships manage generator power
before asking the gun to shoot.
this behavior is in
ship_m:maybe_shoot.
bullets
-------
* dx, dy - movement per frame.
@ -1576,19 +1577,39 @@ or less hp calls self:die() and
tells the main game loop to
remove it.
shieldcooldown is the interval
between restoring shield points.
shieldpenalty is the delay
before restoring points after
any damage, reset to this value
on every damaging hit (whether
it is absorbed by the shield or
not) -- shield behaves like
halo and other shooters in its
heritage, where it recovers if
you avoid damage for a while.
not that there is any safe cover
in this kind of game.
ships have power, from 0 to
ship.maxpower, increasing by
ship.generator per frame.
in maybe_shoot, ships check that
they have power to fire before
trying to fire (the gun itself
checks ammo and cooldown), and
spend that power if they fire.
power is also used to restore
shields - ship.shieldcost per
point of shields. shieldcooldown
is the interval between
restoring shield points, which
is reset to shieldpenalty when a
ship takes damage (regardless of
whether that damage is stopped
by the shield or not).
shieldpenalty is much worse than
shieldcooldown (hALO shield).
therefore:
* damaged ships spend power
repairing shields, which may
affect ability to fire guns.
this looks like a slow firing
rate because the ship will
eventually recover enough
energy to fire.
* a ship firing nonstop will
typically be unable to recover
any shields because it will
not have energy to do so.
ships do not repair hp on their
own. negative-damage bullets