Class: RDGC::Map::Block
- Inherits:
-
Area
- Object
- Area
- RDGC::Map::Block
show all
- Defined in:
- lib/rdgc/map/block.rb
Constant Summary
Constants included
from TileType
TileType::OUT, TileType::ROAD, TileType::ROOM, TileType::WALL
Instance Attribute Summary
Attributes inherited from Area
#bottom, #left, #right, #top
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Area
#blind_level, #blind_level_blind?, #blind_level_dark?, #blind_level_none?, #blind_level_open?, #coordinates, #each, #each_tile, #each_x, #each_y, #fill_tile, #has_xy?, #height, #random_point, #set_blind, #set_tile, #tile, #width
Class Method Details
.create(top, bottom, left, right) ⇒ Object
6
7
8
9
|
# File 'lib/rdgc/map/block.rb', line 6
def self.create(top, bottom, left, right)
super(top, bottom, left, right)
end
|
Instance Method Details
#add_road(road) ⇒ Object
67
68
69
70
|
# File 'lib/rdgc/map/block.rb', line 67
def add_road(road)
@roads ||= []
@roads << road
end
|
#cling_direction_to(b) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/rdgc/map/block.rb', line 147
def cling_direction_to(b)
case
when cling_to_top?(b)
:top
when cling_to_bottom?(b)
:bottom
when cling_to_left?(b)
:left
when cling_to_right?(b)
:right
end
end
|
#cling_to_bottom?(b) ⇒ Boolean
126
127
128
129
130
131
|
# File 'lib/rdgc/map/block.rb', line 126
def cling_to_bottom?(b)
return false unless bottom == b.top-1
return false if left > b.right
return false if right < b.left
true
end
|
#cling_to_left?(b) ⇒ Boolean
133
134
135
136
137
138
|
# File 'lib/rdgc/map/block.rb', line 133
def cling_to_left?(b)
return false unless left == b.right+1
return false if top > b.bottom
return false if bottom < b.top
true
end
|
#cling_to_right?(b) ⇒ Boolean
140
141
142
143
144
145
|
# File 'lib/rdgc/map/block.rb', line 140
def cling_to_right?(b)
return false unless right == b.left-1
return false if top > b.bottom
return false if bottom < b.top
true
end
|
#cling_to_top?(b) ⇒ Boolean
119
120
121
122
123
124
|
# File 'lib/rdgc/map/block.rb', line 119
def cling_to_top?(b)
return false unless top == b.bottom+1
return false if left > b.right
return false if right < b.left
true
end
|
#create_cross_point ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/rdgc/map/block.rb', line 92
def create_cross_point
x_min = self.left + 1
x_max = self.right - 2
y_min = self.top + 1
y_max = self.bottom - 2
x = range_rand(x_min, x_max)
y = range_rand(y_min, y_max)
@cross_point = [x, y]
@cross_point
end
|
#create_room(opt = nil) ⇒ Object
57
58
59
60
|
# File 'lib/rdgc/map/block.rb', line 57
def create_room(opt = nil)
@room = Room.create_from_block(self, opt)
@room
end
|
#cross_point ⇒ Object
80
81
82
|
# File 'lib/rdgc/map/block.rb', line 80
def cross_point
@cross_point
end
|
#empty? ⇒ Boolean
113
114
115
116
117
|
# File 'lib/rdgc/map/block.rb', line 113
def empty?
return false if has_room?
return false if has_road?
true
end
|
#fill ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/rdgc/map/block.rb', line 11
def fill
fill_tile TileType::WALL
fill_room
fill_roads
self
end
|
#fill_roads ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/rdgc/map/block.rb', line 30
def fill_roads
return unless has_road?
roads.each do |r|
r.each_tile do |x, y, t|
set_tile(x, y, t)
end
end
self
end
|
#fill_room ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/rdgc/map/block.rb', line 21
def fill_room
return unless has_room?
room.each_tile do |x, y, t|
set_tile(x, y, t)
end
self
end
|
#has_cross_point? ⇒ Boolean
88
89
90
|
# File 'lib/rdgc/map/block.rb', line 88
def has_cross_point?
@cross_point ? true : false
end
|
#has_road? ⇒ Boolean
76
77
78
|
# File 'lib/rdgc/map/block.rb', line 76
def has_road?
roads.empty? ? false : true
end
|
#has_room? ⇒ Boolean
53
54
55
|
# File 'lib/rdgc/map/block.rb', line 53
def has_room?
@room ? true : false
end
|
#remove_all ⇒ Object
106
107
108
109
110
111
|
# File 'lib/rdgc/map/block.rb', line 106
def remove_all
remove_room
remove_roads
remove_cross_point
self
end
|
#remove_cross_point ⇒ Object
84
85
86
|
# File 'lib/rdgc/map/block.rb', line 84
def remove_cross_point
@cross_point = nil
end
|
#remove_roads ⇒ Object
72
73
74
|
# File 'lib/rdgc/map/block.rb', line 72
def remove_roads
@roads = []
end
|
#remove_room ⇒ Object
49
50
51
|
# File 'lib/rdgc/map/block.rb', line 49
def remove_room
@room = nil
end
|
#roads ⇒ Object
62
63
64
65
|
# File 'lib/rdgc/map/block.rb', line 62
def roads
@roads ||= []
@roads
end
|
#room ⇒ Object
41
42
43
|
# File 'lib/rdgc/map/block.rb', line 41
def room
@room
end
|
#room=(r) ⇒ Object
45
46
47
|
# File 'lib/rdgc/map/block.rb', line 45
def room=(r)
@room = r
end
|