gridmap 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/gridmap.rb +46 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWI3MjAwZmM4MTgyNmQ3MDljYzE1MzI5NTc2NTQzOTYyMTlhZmM2Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWM1OGU4Y2RmNWJlMzljMzUxZWIxYTU1OWM2OGY2NTdkY2IzZmMwZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODBhNjI2ZTlmNjZkOTRkYTkyNTY3OTNkZTUyMjZkM2U5YjQxYzRhOWE0ZmM4
|
10
|
+
MDRlOWQ2NGJhZDFmMmQ5ZDc0ZWIyNDIxY2I2MGYxNTBjZjgzNGU4ZWQ2OWE2
|
11
|
+
YzJlZTYzNmQyZWYwMGZjOTEwNWVjYTJjNzY1ZGIzZmIyYzc4MzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmNmYTMxYTc5ZWQzYjAxODM3N2MzNzZlYTNlMTRlZjliMjQ4MGI5ODNjYmZi
|
14
|
+
NGI4Yzk2Mzg5MjFhMGExNWUzMWY1NjdiZjQxNjE0M2MyMDhkOWYxMzhkYjBk
|
15
|
+
YTNiMWI5NGIxOTE0ZTc4Y2EyOWI2ZTRmMGU0ODNiN2FmZTgzODg=
|
data/lib/gridmap.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
|
1
3
|
class Gridmap < Array
|
2
4
|
attr_reader :tile_size, :grid_width, :grid_height, :pixel_width, :pixel_height, :connected_tiles, :orientated_tiles
|
3
|
-
def initialize(map_path, symbol_details, tile_size)
|
4
|
-
@
|
5
|
-
@
|
6
|
-
@
|
5
|
+
def initialize(window, map_path, symbol_details, images, tile_size)
|
6
|
+
@window = window
|
7
|
+
@map_path = map_path
|
8
|
+
@symbol_details = symbol_details
|
9
|
+
@images = images
|
10
|
+
@tile_size = tile_size
|
11
|
+
|
12
|
+
make_map
|
13
|
+
define_tiles
|
14
|
+
end
|
7
15
|
|
8
|
-
|
16
|
+
def make_map
|
17
|
+
@connected_tiles = []
|
18
|
+
@orientated_tiles = []
|
19
|
+
IO.readlines(@map_path).each_with_index do |line, y|
|
9
20
|
gridline = []
|
10
21
|
line.chomp.split("").each_with_index do |symbol, x|
|
11
|
-
t = Tile.new(x, y, tile_size, symbol_details[symbol])
|
22
|
+
t = Tile.new(x, y, @tile_size, @symbol_details[symbol])
|
12
23
|
gridline << t
|
13
24
|
@connected_tiles << t if t.details[:connected]
|
14
25
|
@orientated_tiles << t if t.details[:orientated]
|
@@ -16,15 +27,20 @@ class Gridmap < Array
|
|
16
27
|
self << gridline
|
17
28
|
end
|
18
29
|
|
30
|
+
#Checks to make sure all lines are the same length.
|
31
|
+
line_count = self.first.count
|
32
|
+
self.each {|line| if line.count != line_count
|
33
|
+
raise StandardError, "The lines in your map file are not all the same length." end}
|
34
|
+
|
19
35
|
#Since all lines should contain the same number of characters, the width is set by counting the number of characters in the first line.
|
20
36
|
@grid_width = self.first.count - 1
|
21
37
|
@grid_height = self.count - 1
|
22
38
|
|
23
|
-
@pixel_width = (@grid_width + 1) * tile_size
|
24
|
-
@pixel_height = (@grid_height + 1) * tile_size
|
39
|
+
@pixel_width = (@grid_width + 1) * @tile_size
|
40
|
+
@pixel_height = (@grid_height + 1) * @tile_size
|
25
41
|
end
|
26
42
|
|
27
|
-
def define_tiles
|
43
|
+
def define_tiles
|
28
44
|
#The check method checks a tile with the given grid co-ordinates to see if it is connected or not.
|
29
45
|
#The logic here prevents a tile from being checked if it lies outside the grid.
|
30
46
|
def check(x, y)
|
@@ -85,7 +101,7 @@ class Gridmap < Array
|
|
85
101
|
img_key = :quad
|
86
102
|
end
|
87
103
|
|
88
|
-
tile.image = Gosu::Image.new(window, images[img_key], true)
|
104
|
+
tile.image = Gosu::Image.new(@window, @images[img_key], true)
|
89
105
|
end
|
90
106
|
|
91
107
|
angle_orientated_tiles
|
@@ -96,7 +112,7 @@ class Gridmap < Array
|
|
96
112
|
unless tile.details[:connected]
|
97
113
|
#img_key is inferred from the tile's type!
|
98
114
|
img_key = tile.details[:type].to_sym
|
99
|
-
tile.image = Gosu::Image.new(window, images[img_key], true)
|
115
|
+
tile.image = Gosu::Image.new(@window, @images[img_key], true)
|
100
116
|
end
|
101
117
|
end
|
102
118
|
end
|
@@ -129,13 +145,30 @@ class Gridmap < Array
|
|
129
145
|
def find_tile(x, y)
|
130
146
|
self[(y / @tile_size).floor][(x / @tile_size).floor]
|
131
147
|
end
|
148
|
+
|
149
|
+
def change_level(new_map, *p)
|
150
|
+
puts "changing level"
|
151
|
+
#Clears the current grid
|
152
|
+
self.count.times { self.pop }
|
153
|
+
|
154
|
+
@map_path = new_map
|
155
|
+
#Replaces instance variables with param variables if they exist.
|
156
|
+
@symbol_details = p[0] if p[0]
|
157
|
+
@images = p[1] if p[1]
|
158
|
+
@tile_size = p[2] if p[2]
|
159
|
+
|
160
|
+
make_map
|
161
|
+
define_tiles
|
162
|
+
end
|
132
163
|
end
|
133
164
|
|
134
165
|
class Tile
|
135
|
-
attr_reader :x, :y
|
136
|
-
attr_accessor :angle, :
|
166
|
+
attr_reader :x, :y, :pixel_x, :pixel_y, :centre_point
|
167
|
+
attr_accessor :angle, :details, :image, :z, :connections
|
137
168
|
def initialize(x, y, size, details)
|
138
169
|
@x, @y, @size, @details = x, y, size, details
|
170
|
+
@pixel_x = @x * size
|
171
|
+
@pixel_y = @y * size
|
139
172
|
|
140
173
|
@offset_x = details[:offset_x] if details[:offset_x]
|
141
174
|
@offset_y = details[:offset_y] if details[:offset_y]
|