-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapas.rb
156 lines (139 loc) · 3.1 KB
/
mapas.rb
1
2
3
4
5
6
7
8
9
10
11
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
require 'gosu'
require 'fuel'
require 'spike'
class Mapa
attr_reader :largura, :altura, :spikes
attr_accessor :fuels
def initialize(window, filename, estado)
@bloco = Gosu::Image.new(window, "media/Tileoficial.png", true)
@spikes = []
spike_img = Gosu::Image.new(window, "media/spike.png", false)
@fuels = []
fuel_img = Gosu::Image.new(window, "media/Fuel.png", false)
@jogador = Astronautinha.new(window, @x, @y)
lines = File.readlines(filename).map do |line|
line.chomp
end
@estado = estado
@altura = lines.size
@largura = lines[0].size
@tiles = Array.new(@largura) do |x|
Array.new(@altura) do |y|
case lines[y][x,1]
when "."
@bloco
when "x"
@spikes.push(Spike.new(spike_img, x * 50, y * 50))
nil
when "?"
nil
when "!"
@fuels.push(Fuel.new(fuel_img, x * 50, y * 50))
nil
else
nil
end
end
end
@reserva = @fuels.dup
end
def reset_fuels
@fuels = @reserva.dup
end
def draw
draw_fase1 if @estado == "FASE_1"
draw_fase2 if @estado == "FASE_2"
draw_fase3 if @estado == "FASE_3"
draw_fase4 if @estado == "FASE_4"
draw_fase5 if @estado == "FASE_5"
draw_fase6 if @estado == "FASE_6"
draw_fase7 if @estado == "FASE_7"
end
def draw_fase1
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase2
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase3
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase4
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase5
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase6
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def draw_fase7
@altura.times do |y|
@largura.times do |x|
tile = @tiles[x][y]
if tile then
tile.draw(x * 50 , y * 50, 0)
end
end
end
@fuels.each do |combustivel| combustivel.draw end
@spikes.each do |spike| spike.draw end
end
def solid? (x,y)
y < 0 or @tiles [x/50][y/50] or x < 0 or x > 950 or y > 650
end
end