Class: RDGC::Map::Block

Inherits:
Area
  • Object
show all
Defined in:
lib/rdgc/map/block.rb

Direct Known Subclasses

RDGC::Maker::TempBlock

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)
  # fillはしない
  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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_pointObject



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_pointObject



80
81
82
# File 'lib/rdgc/map/block.rb', line 80

def cross_point
  @cross_point
end

#empty?Boolean

Returns:

  • (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

#fillObject



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_roadsObject



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_roomObject



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

Returns:

  • (Boolean)


88
89
90
# File 'lib/rdgc/map/block.rb', line 88

def has_cross_point?
  @cross_point ? true : false
end

#has_road?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rdgc/map/block.rb', line 76

def has_road?
  roads.empty? ? false : true
end

#has_room?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/rdgc/map/block.rb', line 53

def has_room?
  @room ? true : false
end

#remove_allObject



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_pointObject



84
85
86
# File 'lib/rdgc/map/block.rb', line 84

def remove_cross_point
  @cross_point = nil
end

#remove_roadsObject



72
73
74
# File 'lib/rdgc/map/block.rb', line 72

def remove_roads
  @roads = []
end

#remove_roomObject



49
50
51
# File 'lib/rdgc/map/block.rb', line 49

def remove_room
  @room = nil
end

#roadsObject



62
63
64
65
# File 'lib/rdgc/map/block.rb', line 62

def roads
  @roads ||= []
  @roads
end

#roomObject



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