Class: GamesAndRpgParadise::Mages

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

Overview

GamesAndRpgParadise::Mages

Instance Method Summary collapse

Constructor Details

#initialize(colliders_name) ⇒ Mages

initialize



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mages.rb', line 10

def initialize(colliders_name)
	@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}"
			@mages_data_from_tiled =  x["objects"]
		end
	end
	@mage_head_image = Gosu::Image.new("images/mage_head.png", :tileable => true)
end

Instance Method Details

#collision_checker(player_x, player_y) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mages.rb', line 21

def collision_checker(player_x, player_y)
	@player_x = player_x
	@player_y = player_y
	@mage_collision = false
	@mages_data_from_tiled.each do |data|
		centre_x = data["x"] + (data["width"]/2)
		centre_y = data["y"] + (data["height"]/2)
		if Gosu.distance(@player_x,@player_y,centre_x,centre_y) < 10
			@mage_collision = true
			if data["name"] == "mage_1"
				@mage_text = Gosu::Image.from_text("The shrooms here taste great." + "\n" + "They also contain anti-venom.", 16, {})
			elsif data["name"] == "mage_2"
				@mage_text = Gosu::Image.from_text("Blue shrooms only grow" + "\n" + "behind trees.", 16, {})
			elsif data["name"] == "mage_3"
				@mage_text = Gosu::Image.from_text("The prophecy tells of king who can" + "\n" + "complete levels by opening chests.", 16, {})
			end
		end
	end
end

#drawObject



40
41
42
43
44
45
# File 'lib/games_and_rpg_paradise/gui/gosu/final_fantasy/mages.rb', line 40

def draw
	if @mage_collision
		@mage_head_image.draw(16,176,10)
		@mage_text.draw(96, 176, 10)
	end
end