Class: GamesAndRpgParadise::Chest

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/final_fantasy/chest.rb

Overview

GamesAndRpgParadise::Chest

Instance Method Summary collapse

Constructor Details

#initialize(colliders_name) ⇒ Chest

initialize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/chest.rb', line 10

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 { |x|
    if x['name'] == "#{@colliders_name}"
      @chest_data_from_tiled =  x["objects"]
    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



33
34
35
36
37
38
39
40
41
42
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/chest.rb', line 33

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

#drawObject

draw



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/chest.rb', line 45

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