samples/04_physics_and_collisions/03_entities/app/main.rb
def fire_bullet args
  return unless args.inputs.mouse.click # return unless mouse is clicked
  args.state.bullets << args.state.new_entity(:bullet) do |bullet| # new bullet is declared a new entity
    bullet.y = args.inputs.mouse.click.point.y # set to the y value of where the mouse was clicked
    bullet.x = 0 # starts on the left side of the screen
    bullet.size = 10
    bullet.speed = 10 * rand + 2 # speed of a bullet is randomized
    bullet.rect = [bullet.x, bullet.y, bullet.size, bullet.size] # definition is set
  end
end
# Once mouse is clicked by the user to fire a bullet, a new bullet is added to bullets collection
Once mouse is clicked by the user to fire a bullet, a new bullet is added to bullets collection
Once mouse is clicked by the user to fire a bullet a new bullet is added to bullets collection
def fire_bullet args
  return unless args.inputs.mouse.click 
  args.state.bullets << args.state.new_entity(:bullet) do |bullet| 
    bullet.y = args.inputs.mouse.click.point.y 
    bullet.x = 0 
    bullet.size = 10
    bullet.speed = 10 * rand + 2 
    bullet.rect = [bullet.x, bullet.y, bullet.size, bullet.size] 
  end
end
def fire_bullet args return unless args . inputs . mouse . click args . state . bullets << args . state . new_entity ( :bullet ) do | bullet | bullet . y = args . inputs . mouse . click . point . y bullet . x = 0 bullet . size = 10 bullet . speed = 10 * rand + 2 bullet . rect = [ bullet . x , bullet . y , bullet . size , bullet . size ] end end
Once mouse is clicked by the user to fire a bullet, a new bullet is added to bullets collection
Once mouse is clicked by the user to fire a bullet a new bullet is added to bullets collection
# return unless mouse is clicked # new bullet is declared a new entity # set to the y value of where the mouse was clicked # starts on the left side of the screen # speed of a bullet is randomized # definition is set
args