samples/04_physics_and_collisions/03_entities/app/main.rb
# Adds enemies to the enemies collection and sets their values
Adds enemies to the enemies collection and sets their values
Adds enemies to the enemies collection and sets their values
def add_new_enemies_if_needed args
  return if args.state.enemies.length >= 10 
  return unless args.state.bullets.length == 0 
  args.state.enemies += (10 - args.state.enemies.length).map do 
    args.state.new_entity(:enemy) do |e| 
      e.x = 640 + 500 * rand 
      e.y = 600 * rand + 50
      e.rect = [e.x, e.y, 130, 30] 
    end
  end
end
def add_new_enemies_if_needed args return if args . state . enemies . length >= 10 return unless args . state . bullets . length == 0 args . state . enemies += ( 10 - args . state . enemies . length ) . map do args . state . new_entity ( :enemy ) do | e | e . x = 640 + 500 * rand e . y = 600 * rand + 50 e . rect = [ e . x , e . y , 130 , 30 ] end end end
Adds enemies to the enemies collection and sets their values
Adds enemies to the enemies collection and sets their values
# if 10 or more enemies, enemies are not added # if user has not yet shot bullet, no enemies are added # adds enemies so there are 10 total # each enemy is declared as a new entity # each enemy is given random position on screen # sets definition for enemy's rect
args