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