samples/04_physics_and_collisions/03_entities/app/main.rb
# Moves bullets across screen
# Sets definition of the bullets
Moves bullets across screen
Sets definition of the bullets
Moves bullets across screen Sets definition of the bullets
def move_bullets args
  args.state.bullets.each do |bullet| 
    bullet.x += bullet.speed 
    bullet.y += bullet.speed.*(0.25).randomize(:ratio, :sign)
    bullet.rect = [bullet.x, bullet.y, bullet.size, bullet.size] 
  end
end
def move_bullets args args . state . bullets . each do | bullet | bullet . x += bullet . speed bullet . y += bullet . speed . * ( 0.25 ) . randomize ( :ratio , :sign ) bullet . rect = [ bullet . x , bullet . y , bullet . size , bullet . size ] end end
Moves bullets across screen
Sets definition of the bullets
Moves bullets across screen Sets definition of the bullets
# perform action on each bullet in collection # increment x by speed (bullets fly horizontally across screen) # By randomizing the value that increments bullet.y, the bullet does not fly straight up and out # of the scope of the screen. Try removing what follows bullet.speed, or changing 0.25 to 1.25 to # see what happens to the bullet's movement. # sets definition of bullet's rect
args