Class: GamesAndRpgParadise::Mushrooms
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::Mushrooms
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb
Overview
GamesAndRpgParadise::Mushrooms
Instance Attribute Summary collapse
-
#eaten_shroom_blue ⇒ Object
readonly
Returns the value of attribute eaten_shroom_blue.
-
#eaten_shroom_red ⇒ Object
readonly
Returns the value of attribute eaten_shroom_red.
Instance Method Summary collapse
- #collision_checker(player_x, player_y) ⇒ Object
-
#draw ⇒ Object
draw.
-
#initialize(colliders_name) ⇒ Mushrooms
constructor
A new instance of Mushrooms.
Constructor Details
#initialize(colliders_name) ⇒ Mushrooms
Returns a new instance of Mushrooms.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb', line 12 def initialize(colliders_name) @eaten_shroom_blue = false @eaten_shroom_red = false @blue_shroom_image = Gosu::Image.new("images/blue_mushrooom_big.png", :tileable => true) @red_shroom_image = Gosu::Image.new("images/red_mushroom2_big.png", :tileable => true) @colliders_name = colliders_name @width = 16 @height = 16 file = File.read("map.json") data_hash = JSON.parse(file) data_hash["layers"].each do |x| if x["name"] == "#{@colliders_name}" @shroom_data_from_tiled = x["objects"] end end @all_mushrooms = [] @shroom_data_from_tiled.each do |data| centre_x = data["x"] + (data["width"]/2) centre_y = data["y"] + (data["height"]/2) if data["name"] == "red" @all_mushrooms.push ({shroom_type: "red", shroom_image: Gosu::Image.new("images/red_mushroom2.png"), centre_x: centre_x, centre_y: centre_y}) end if data["name"] == "blue" @all_mushrooms.push ({shroom_type: "blue", shroom_image: Gosu::Image.new("images/blue_mushrooom.png"), centre_x: centre_x, centre_y: centre_y}) end end end |
Instance Attribute Details
#eaten_shroom_blue ⇒ Object (readonly)
Returns the value of attribute eaten_shroom_blue.
9 10 11 |
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb', line 9 def eaten_shroom_blue @eaten_shroom_blue end |
#eaten_shroom_red ⇒ Object (readonly)
Returns the value of attribute eaten_shroom_red.
10 11 12 |
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb', line 10 def eaten_shroom_red @eaten_shroom_red end |
Instance Method Details
#collision_checker(player_x, player_y) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb', line 40 def collision_checker(player_x, player_y) @player_x = player_x @player_y = player_y @all_mushrooms.each do |shroom| if Gosu.distance(@player_x,@player_y,shroom[:centre_x],shroom[:centre_y]) < 16 @all_mushrooms.delete(shroom) if shroom[:shroom_type] == "red" @eaten_shroom_red = true end if shroom[:shroom_type] == "blue" @eaten_shroom_blue = true end end end end |
#draw ⇒ Object
draw
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mushrooms.rb', line 57 def draw @all_mushrooms.each do |mushroom| mushroom[:shroom_image].draw(mushroom[:centre_x] - @width/2, mushroom[:centre_y] - @height/2, 2) end if @eaten_shroom_red @red_shroom_image.draw(320, 176, 1) end if @eaten_shroom_blue @blue_shroom_image.draw(320, 208, 1) end end |