samples/99_genre_crafting/craft_game_starting_point/app/main.rb
# the calc method is executed after input
the calc method is executed after input
the calc method is executed after input
def calc args
  args.state.items.each do |item|
    if item[:location] == :inventory
      set_inventory_position args, item
    elsif item[:location] == :craft
      set_craft_position args, item
    elsif item[:location] == :held
      args.state.held_item.x = args.inputs.mouse.x - args.state.held_item.w.half
      args.state.held_item.y = args.inputs.mouse.y - args.state.held_item.h.half
    end
  end
  args.state.click_ripples.each do |ripple|
    delta_w = ripple.w * 1.2 - ripple.w
    delta_h = ripple.h * 1.2 - ripple.h
    ripple.x -= delta_w.half
    ripple.y -= delta_h.half
    ripple.w += delta_w
    ripple.h += delta_h
    ripple.a -= 10
  end
  args.state.click_ripples.reject! { |ripple| ripple.a <= 0 }
end
def calc args args . state . items . each do | item | if item [ :location ] == :inventory set_inventory_position args , item elsif item [ :location ] == :craft set_craft_position args , item elsif item [ :location ] == :held args . state . held_item . x = args . inputs . mouse . x - args . state . held_item . w . half args . state . held_item . y = args . inputs . mouse . y - args . state . held_item . h . half end end args . state . click_ripples . each do | ripple | delta_w = ripple . w * 1.2 - ripple . w delta_h = ripple . h * 1.2 - ripple . h ripple . x -= delta_w . half ripple . y -= delta_h . half ripple . w += delta_w ripple . h += delta_h ripple . a -= 10 end args . state . click_ripples . reject! { | ripple | ripple . a <= 0 } end
the calc method is executed after input
the calc method is executed after input
# make sure that the real position of the inventory # items are updated every frame to ensure that they # are placed correctly given their location and oridinal positions # instead of using .map, here we use .each (since we are not returning a new item and just updating the items in place) # based on the location of the item, invoke the correct pixel conversion method # if the item is held, center the item around the mouse pointer # for each hash/sprite in the click ripples queue, # expand its size by 20 percent and decrease its alpha # by 10. # remove any items from the collection where the alpha value is less than equal to # zero using the reject! method (reject with an exclamation point at the end changes the # array value in place, while reject without the exclamation point returns a new array).
args