Remove power mechanics. Replace with XP stub.
Also a few random comments and cleanups along the way.
This commit is contained in:
		
							
								
								
									
										123
									
								
								vacuum_gambit.p8
									
									
									
									
									
								
							
							
						
						
									
										123
									
								
								vacuum_gambit.p8
									
									
									
									
									
								
							| @@ -342,7 +342,7 @@ function drawhud() | ||||
|  dropshadow("p h",114,59,1) | ||||
|  inset(114,66,119,125) | ||||
|  fillp(0x5a5a) | ||||
|  vertmeter(115,67,118,124,primary_ship.power, primary_ship.max_power, powcols) | ||||
|  vertmeter(115,67,118,124,primary_ship.xp, primary_ship.xptarget, powcols) | ||||
|  | ||||
|  inset(120,66,125,125) | ||||
|  -- 57 px vertically | ||||
| @@ -425,14 +425,9 @@ 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, | ||||
| @@ -492,7 +487,6 @@ 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) | ||||
| @@ -534,9 +528,7 @@ end | ||||
|  | ||||
| function ship_m:maybe_shoot(gun) | ||||
|  if (not gun) return | ||||
|  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 | ||||
|  return gun:shoot(self.x + self.fire_off_x, self.y + self.fire_off_y) | ||||
| end | ||||
|  | ||||
| function ship_m:hitship(other) | ||||
| @@ -577,10 +569,8 @@ 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 | ||||
|  | ||||
| @@ -595,6 +585,28 @@ 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{  | ||||
| @@ -613,7 +625,8 @@ end | ||||
| function bullet_base:move() | ||||
|  self.x += self.dx | ||||
|  self.y += self.dy | ||||
|  if (self.y > 128) or (self.y < -8 * self.height) then | ||||
|  if (self.f) self.f -= 1 | ||||
|  if (self.y > 128) or (self.y < -8 * self.height) or (self.f and self.f < 0) then | ||||
|   self:die() | ||||
|   return true | ||||
|  end | ||||
| @@ -654,7 +667,7 @@ end | ||||
|  | ||||
| zap_e = mknew(bullet_base.new{ | ||||
|  --shape | ||||
|  sprite = 9, --index of enemy ammo sprite | ||||
|  sprite = 9, --index of ammo sprite | ||||
|  width = 1, --in 8x8 blocks | ||||
|  height = 1, | ||||
|  hurt = { -- hurtbox - where this ship can be hit | ||||
| @@ -683,7 +696,6 @@ 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), | ||||
| @@ -740,7 +752,6 @@ 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, | ||||
| @@ -776,7 +787,6 @@ 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, | ||||
| @@ -838,7 +848,6 @@ 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, | ||||
| @@ -880,13 +889,16 @@ player = mknew(ship_m.new{ | ||||
|  sparkodds = 2, | ||||
|  boss = true,  -- dramatic special effects | ||||
|   | ||||
|  -- health and power | ||||
|  -- health | ||||
|  hp = 3, -- current health, non-regenerating | ||||
|  maxhp = 3, -- player only; other ships never heal | ||||
|  shield = 2, -- regenerates, using power | ||||
|  shield = 2, -- regenerates | ||||
|  maxshield = 2, | ||||
|  shieldcost = 60, -- power cost to refill shield | ||||
|  generator = 2,  | ||||
|  | ||||
|  -- xp, increments of 0x0.01 | ||||
|  xp = 0, | ||||
|  xptarget = 0x0.05, | ||||
|  level = 1, | ||||
|  | ||||
|  -- gun | ||||
|  main_gun = nil, -- assign at spawn time | ||||
| @@ -942,7 +954,7 @@ frownie = mknew(ship_m.new{ | ||||
|  sparks = smokespark, | ||||
|  sparkodds = 8, | ||||
|   | ||||
|  -- health and power | ||||
|  -- health | ||||
|  hp = 0.5, -- enemy ships need no max hp | ||||
|  | ||||
|  -- position | ||||
| @@ -984,7 +996,6 @@ blocky = mknew(frownie.new{ | ||||
|  | ||||
| spewy = mknew(frownie.new{ | ||||
|  sprite=26, | ||||
|  power=-20, | ||||
|  hurt = { | ||||
|   x_off=0, | ||||
|   y_off=1, | ||||
| @@ -992,13 +1003,11 @@ 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, true | ||||
|   return dx, dy, shoot_spec, self.y > 10 | ||||
|  end, | ||||
|  init = function(ship) | ||||
|   ship.main_gun=ship.main_gun or protron_gun_e.new{} | ||||
| @@ -1019,7 +1028,6 @@ chasey = mknew(ship_m.new{ | ||||
|  hp = 1.5, | ||||
|  shield = 1, | ||||
|  maxshield = 1, | ||||
|  shieldcost = 180, | ||||
|  | ||||
|  fire_off_x = 4, | ||||
|  fire_off_y = 7, | ||||
| @@ -1037,7 +1045,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.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x | ||||
|  return 0, 0, false, self.y > 10 and self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x | ||||
| end | ||||
|  | ||||
| xl_chasey=mknew(chasey.new{ | ||||
| @@ -1455,10 +1463,6 @@ 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. | ||||
| @@ -1486,11 +1490,6 @@ 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. | ||||
| @@ -1577,39 +1576,19 @@ or less hp calls self:die() and | ||||
| tells the main game loop to | ||||
| remove it. | ||||
|  | ||||
| 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. | ||||
| 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 do not repair hp on their | ||||
| own. negative-damage bullets | ||||
|   | ||||
		Reference in New Issue
	
	Block a user