pawker/app/actors/bug.rb
def generate_non_colliding_start_position(args, wall: nil)
      # @target =
      #   while true do
      #     target = generate_start_target(args, wall: wall)
      #     break target unless controller.actors.any? { |other| other.index != index && other.collision?(target.slice(*POSITION_KEYS)) }
      #   end

      @target = generate_start_target(args, wall: wall)



      # Set the starting position with a random starting speed
      @position = @target.slice(*POSITION_KEYS).merge(speed: 10)
      @position[:angle_anchor_x] = 0.5
      @position[:angle_anchor_y] = 0.5
      @position[:tile_w] = WIDTH
      @position[:tile_h] = HEIGHT
      @position[:flip_horizontally] = [true, false].sample

      # Get rid of the angle
      @target.delete(:angle)

      # Set a speed on the target to get to it
      @target[:speed] = Ease.new(from: 0, to: 25, ticks: 50)

      # Now make the bug take a few steps back so that they can work their way
      # towards the starting position.
      update_position_x(args, move: -1 * HEIGHT)
      update_position_y(args, move: -1 * HEIGHT)
    end
# This can take quite a few goes to figure out a non-colliding starting
# position but we're just going to be okay with that.
This can take quite a few goes to figure out a non-colliding starting
position but we're just going to be okay with that.
This can take quite a few goes to figure out a non - colliding starting position but we ' re just going to be okay with that .
def generate_non_colliding_start_position(args, wall: nil)
      @target = generate_start_target(args, wall: wall)
      @position = @target.slice(*POSITION_KEYS).merge(speed: 10)
      @position[:angle_anchor_x] = 0.5
      @position[:angle_anchor_y] = 0.5
      @position[:tile_w] = WIDTH
      @position[:tile_h] = HEIGHT
      @position[:flip_horizontally] = [true, false].sample
      @target.delete(:angle)
      @target[:speed] = Ease.new(from: 0, to: 25, ticks: 50)
      update_position_x(args, move: -1 * HEIGHT)
      update_position_y(args, move: -1 * HEIGHT)
    end
def generate_non_colliding_start_position ( args , wall : nil ) @target = generate_start_target ( args , wall : wall ) @position = @target . slice ( * POSITION_KEYS ) . merge ( speed : 10 ) @position [ :angle_anchor_x ] = 0.5 @position [ :angle_anchor_y ] = 0.5 @position [ :tile_w ] = WIDTH @position [ :tile_h ] = HEIGHT @position [ :flip_horizontally ] = [ true , false ] . sample @target . delete ( :angle ) @target [ :speed ] = Ease . new ( from : 0 , to : 25 , ticks : 50 ) update_position_x ( args , move : - 1 * HEIGHT ) update_position_y ( args , move : - 1 * HEIGHT ) end
This can take quite a few goes to figure out a non-colliding starting
position but we're just going to be okay with that.
This can take quite a few goes to figure out a non - colliding starting position but we ' re just going to be okay with that .
# @target = #   while true do #     target = generate_start_target(args, wall: wall) #     break target unless controller.actors.any? { |other| other.index != index && other.collision?(target.slice(*POSITION_KEYS)) } #   end # Set the starting position with a random starting speed # Get rid of the angle # Set a speed on the target to get to it # Now make the bug take a few steps back so that they can work their way # towards the starting position.
args
wall