samples/99_genre_crafting/craft_game_starting_point/app/main.rb
# helper function that creates a visual representation of an item
helper function that creates a visual representation of an item
helper function that creates a visual representation of an item
def item_prefab args, item, should_highlight, mouse
  return nil unless item
  overlay = nil
  x = item.x
  y = item.y
  w = item.w
  h = item.h
  if should_highlight && mouse.point.inside_rect?(item)
    overlay = { x: x, y: y, w: w, h: h, path: "sprites/square-blue.png", a: 130, }
  end
  [
    { x: x,      y: y, w: args.state.sprite_size, h: args.state.sprite_size, path: item[:path], },
    { x: x + 55, y: y, w: 25, h: 25, path: "sprites/square-black.png", }, 
    { x: x + 56, y: y + 22, text: "#{item[:quantity]}", r: 255, g: 255, b: 255, },
    overlay
  ]
end
def item_prefab args , item , should_highlight , mouse return nil unless item overlay = nil x = item . x y = item . y w = item . w h = item . h if should_highlight && mouse . point . inside_rect? ( item ) overlay = { x : x , y : y , w : w , h : h , path : "sprites/square-blue.png" , a : 130 , } end [ { x : x , y : y , w : args . state . sprite_size , h : args . state . sprite_size , path : item [ :path ] , } , { x : x + 55 , y : y , w : 25 , h : 25 , path : "sprites/square-black.png" , } , { x : x + 56 , y : y + 22 , text : "#{item[:quantity]}" , r : 255 , g : 255 , b : 255 , } , overlay ] end
helper function that creates a visual representation of an item
helper function that creates a visual representation of an item
# sprites are hashes with a path property, this is the main sprite # this represents the black area in the bottom right corner of the main sprite so that the # quantity is visible # sprites are hashes with a path property # labels are hashes with a text property # this is the mouse overlay, if the overlay isn't applicable, then this value will be nil (nil values will not be rendered)
args
item
should_highlight
mouse