try using a path for a skirmisher
slightly stabilized but the length operator does not work in the presence of Lua Crimes like this so it needs more work
This commit is contained in:
		| @@ -194,7 +194,9 @@ function updategame() | |||||||
|   interlude -= 1 |   interlude -= 1 | ||||||
|  else |  else | ||||||
|   current_wave = flotilla.new() |   current_wave = flotilla.new() | ||||||
|   current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4)) |   --current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4)) | ||||||
|  |   current_wave:load(0, 0, min(ones(waves_complete)\2, 4)) | ||||||
|  |   current_wave:update() | ||||||
|  end |  end | ||||||
|  events = filtermoved(events) |  events = filtermoved(events) | ||||||
|  appendmove(events, new_events) |  appendmove(events, new_events) | ||||||
| @@ -662,7 +664,7 @@ function destination:target_from(fx, fy) | |||||||
|  if (xf > 0) rx = lerp(rx, 112, xf) |  if (xf > 0) rx = lerp(rx, 112, xf) | ||||||
|  if (yf < 0) ry = lerp(ry, 0, -yf) |  if (yf < 0) ry = lerp(ry, 0, -yf) | ||||||
|  if (yf > 0) ry = lerp(ry, 128, yf) |  if (yf > 0) ry = lerp(ry, 128, yf) | ||||||
|  return rx, ry |  return rx, ry, self.accel_frac | ||||||
| end | end | ||||||
|  |  | ||||||
| segment = mknew{ | segment = mknew{ | ||||||
| @@ -689,7 +691,7 @@ segment = mknew{ | |||||||
|   x.init = segment.reset |   x.init = segment.reset | ||||||
|   mknew(x) |   mknew(x) | ||||||
|   if not x.mirror then |   if not x.mirror then | ||||||
|    local mirrored = {mirror=x} |    local mirrored = {mirror=x, init=segment.reset} | ||||||
|    for i, v in ipairs(x) do |    for i, v in ipairs(x) do | ||||||
|     mirrored[i] = destination.new{ |     mirrored[i] = destination.new{ | ||||||
|      anchor_frac=v.anchor_frac, |      anchor_frac=v.anchor_frac, | ||||||
| @@ -698,7 +700,7 @@ segment = mknew{ | |||||||
|      y_off_frac=v.y_off_frac, |      y_off_frac=v.y_off_frac, | ||||||
|     } |     } | ||||||
|    end |    end | ||||||
|    x.mirror = x.new(mirrored) |    x.mirror = mknew(x.new(mirrored)) | ||||||
|   end |   end | ||||||
|  end |  end | ||||||
| } | } | ||||||
| @@ -712,9 +714,9 @@ function segment:reset() | |||||||
| end | end | ||||||
|  |  | ||||||
| function segment:target_from(fx, fy) | function segment:target_from(fx, fy) | ||||||
|  local rx, ry = self[self.current_idx]:target_from(fx, fy) |  local rx, ry, af = self[self.current_idx]:target_from(fx, fy) | ||||||
|  self.dest_x, self.dest_y = rx, ry |  self.dest_x, self.dest_y = rx, ry | ||||||
|  return rx, ry |  return rx, ry, af | ||||||
| end | end | ||||||
|  |  | ||||||
| function segment:update(x, y) | function segment:update(x, y) | ||||||
| @@ -1487,13 +1489,26 @@ ship_f = mknew(ship_m.new{ | |||||||
|  act = function(self) |  act = function(self) | ||||||
|   local wx,wy=self.want_x,self.want_y |   local wx,wy=self.want_x,self.want_y | ||||||
|   self.xmin,self.xmax,self.ymin,self.ymax = wx,wx,wy,wy |   self.xmin,self.xmax,self.ymin,self.ymax = wx,wx,wy,wy | ||||||
|   return 0,0,false,false |   return 0,0 | ||||||
|  end, |  end, | ||||||
|  init = function(self) |  init = function(self) | ||||||
|   if (self.gun_proto) self.main_gun = self.gun_proto.new() |   if (self.gun_proto) self.main_gun = self.gun_proto.new() | ||||||
|  |   if (self.path) self.path = self.path.new() | ||||||
|  end |  end | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | diamond_loop = segment.new{ | ||||||
|  |  destination.new{ | ||||||
|  |   x_off_frac=0.25 | ||||||
|  |  }, destination.new{ | ||||||
|  |   y_off_frac=0.25 | ||||||
|  |  }, destination.new { | ||||||
|  |   x_off_frac = -0.25 | ||||||
|  |  }, destination.new { | ||||||
|  |   y_off_frac = -0.25 | ||||||
|  |  }, | ||||||
|  | } | ||||||
|  |  | ||||||
| ship_mook = mknew(ship_f.new{ | ship_mook = mknew(ship_f.new{ | ||||||
|  sprite=103 |  sprite=103 | ||||||
| }) | }) | ||||||
| @@ -1515,12 +1530,33 @@ ship_skirmisher = mknew(ship_f.new{ | |||||||
|  fire_off_y = 7, |  fire_off_y = 7, | ||||||
|  xmin = -8, |  xmin = -8, | ||||||
|  xmax = 112, |  xmax = 112, | ||||||
|  |  path = diamond_loop, | ||||||
| }) | }) | ||||||
|  |  | ||||||
| function ship_skirmisher:reset_bounds() | function ship_skirmisher:reset_bounds() | ||||||
|  self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 120 |  self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 120 | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function ship_skirmisher:act() | ||||||
|  |  local tx, ty, af = self.path:target_from(self.want_x+4, self.want_y+4) | ||||||
|  |  tx -= 4 | ||||||
|  |  ty -= 4 | ||||||
|  |  if af <= 0 then | ||||||
|  |   self.xmin, self.xmax, self.ymin, self.ymax = tx,tx,ty,ty | ||||||
|  |   return 0,0 | ||||||
|  |  end | ||||||
|  |  self:reset_bounds() | ||||||
|  |  local ax, ay, th = tx - self.x, ty - self.y, self.thrust*af | ||||||
|  |  local ma = max(abs(ax), abs(ay)) | ||||||
|  |  return ax*th/ma, ay*th/ma | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function ship_skirmisher:move() | ||||||
|  |  if (not ship_f.move(self)) return | ||||||
|  |  if (not self.path:update(self.x+4, self.y+4)) self.path:reset() | ||||||
|  |  return true | ||||||
|  | end | ||||||
|  |  | ||||||
| function rnd_spawn_loc() | function rnd_spawn_loc() | ||||||
|  local x,y = flr(rnd(304)), flr(rnd(32)) |  local x,y = flr(rnd(304)), flr(rnd(32)) | ||||||
|  if (x<184) return x-40,-y-8 |  if (x<184) return x-40,-y-8 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user