Class: GamesParadise::Chest
- Inherits:
-
Object
- Object
- GamesParadise::Chest
- Defined in:
- lib/games_paradise/gui/gosu/final_fantasy/chest.rb
Instance Method Summary collapse
- #collision_checker(player_x, player_y) ⇒ Object
- #draw ⇒ Object
-
#initialize(colliders_name) ⇒ Chest
constructor
A new instance of Chest.
Constructor Details
#initialize(colliders_name) ⇒ Chest
Returns a new instance of Chest.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/chest.rb', line 9 def initialize(colliders_name) @closed_chest_image = Gosu::Image.new("images/chest_closed_trans.png", :tileable => true) @open_chest_image = Gosu::Image.new("images/chest_open_trans.png", :tileable => true) @win_text = Gosu::Image.from_text("You win!", 16, {}) @width = 16 @height = 14 @colliders_name = colliders_name file = File.read("map.json") data_hash = JSON.parse(file) data_hash["layers"].each do |x| if x["name"] == "#{@colliders_name}" @chest_data_from_tiled = x["objects"] end end @all_chests = [] @chest_data_from_tiled.each do |data| centre_x = data["x"] + (data["width"]/2) centre_y = data["y"] + (data["height"]/2) @all_chests.push ({chest_image: @closed_chest_image, centre_x: centre_x, centre_y: centre_y, closed: true}) end @win = false end |
Instance Method Details
#collision_checker(player_x, player_y) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/chest.rb', line 32 def collision_checker(player_x, player_y) @player_x = player_x @player_y = player_y @all_chests.each do |chest| if Gosu.distance(@player_x,@player_y,chest[:centre_x],chest[:centre_y]) < 17 chest[:chest_image] = @open_chest_image @win = true end end end |
#draw ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/chest.rb', line 43 def draw @all_chests.each do |chest| if @player_y > chest[:centre_y] chest_depth = 1 else chest_depth = 10 end chest[:chest_image].draw(chest[:centre_x] - @width/2, chest[:centre_y] - @height/2, chest_depth) end if @win @win_text.draw(96, 176, 51) end end |