Class: Miyako::FixedMap::FixedMapLayer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Animation, SpriteBase
Defined in:
lib/Miyako/API/fixedmap.rb

Overview

あとで書く

Constant Summary collapse

@@use_chip_list =
Hash.new(nil)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Animation

[], []=, anim_hash, #reset, reset, start, #start, #stop, stop, update, update_animation, #update_animation

Methods included from SpriteBase

#bitmap, #hide, #image_rect, #image_size, #oh, #oh=, #ow, #ow=, #ox, #ox=, #oy, #oy=, #part_rect, #rect, #render_d, #render_xy, #render_xy_to, #show, #to_sprite, #to_unit, #update

Constructor Details

#initialize(mapchip, mapdat, layer_size) ⇒ FixedMapLayer

:nodoc:



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
# File 'lib/Miyako/API/fixedmap.rb', line 59

def initialize(mapchip, mapdat, layer_size) #:nodoc:
  @mapchip = mapchip
  @pos = Point.new(0, 0)
  @size = layer_size.dup
  @ow = @mapchip.chip_size.w
  @oh = @mapchip.chip_size.h
  @real_size = Size.new(@size.w * @ow, @size.h * @oh)
  @mapdat = mapdat
  @baseimg = nil
  @baseimg = @mapchip.chip_image
  @units = nil
  @visible = true
  @divpx = get_div_array(0, @real_size.w, @ow)
  @divpy = get_div_array(0, @real_size.h, @oh)
  @modpx = get_mod_array(0, @real_size.w, @ow)
  @modpy = get_mod_array(0, @real_size.h, @oh)
  @modpx2 = get_mod_array(0, @size.w * 2 + 1, @size.w)
  @modpy2 = get_mod_array(0, @size.h * 2 + 1, @size.h)
  @cdivsx = get_div_array(0, @mapchip.chips, @mapchip.size.w)
  @cmodsx = get_mod_array(0, @mapchip.chips, @mapchip.size.w)
  @cdivsy = get_div_array(0, @mapchip.chips, @mapchip.size.h)
  @cmodsy = get_mod_array(0, @mapchip.chips, @mapchip.size.h)
  @cdivsx = @cdivsx.map{|v| v * @ow }
  @cdivsy = @cdivsy.map{|v| v * @oh }
  @cmodsx = @cmodsx.map{|v| v * @ow }
  @cmodsy = @cmodsy.map{|v| v * @oh }
  @mapchip_units = Array.new(@mapchip.chips){|idx|
    SpriteUnitFactory.create(:bitmap=>@baseimg.bitmap,
                             :ox => (idx % @mapchip.size.w) * @ow, :oy => (idx / @mapchip.size.w) * @oh,
                             :ow => @ow, :oh => @oh)
  }
  @def_ignore = -1
  @ignore_list = []
  reSize
end

Instance Attribute Details

#ignore_listObject (readonly)

Returns the value of attribute ignore_list.



46
47
48
# File 'lib/Miyako/API/fixedmap.rb', line 46

def ignore_list
  @ignore_list
end

#mapchipObject

Returns the value of attribute mapchip.



45
46
47
# File 'lib/Miyako/API/fixedmap.rb', line 45

def mapchip
  @mapchip
end

#mapchip_unitsObject

Returns the value of attribute mapchip_units.



45
46
47
# File 'lib/Miyako/API/fixedmap.rb', line 45

def mapchip_units
  @mapchip_units
end

#posObject (readonly)

Returns the value of attribute pos.



46
47
48
# File 'lib/Miyako/API/fixedmap.rb', line 46

def pos
  @pos
end

#visibleObject

レンダリングの可否(true->描画 false->非描画)



44
45
46
# File 'lib/Miyako/API/fixedmap.rb', line 44

def visible
  @visible
end

Instance Method Details

#can_access?(type, inout, pos, dx, dy, *ignores) ⇒ Boolean

キャラクタとマップチップが重なっているかどうか問い合わせる

指定の位置と方向で、指定の位置のマップチップ上で移動できるかどうか問い合わせる 指定の位置のマップチップ番号が以下の時はtrueを返す 1)-1(未定義)のとき 2)FixexMapLayer#ignore_listに含まれているとき 3)引数ignoresに含まれているとき また、dx==0, dy==0のときもtrueを返す

type

移動形式(0以上の整数)

inout

入退形式(:in もしくは :out)

pos

調査対象のマップチップの位置

dx

移動量(x座標)

dy

移動量(y座標)

ignores

チェックの対象にしないマップチップ番号のリスト。番号に含まれているときはtrueを返す

返却値

移動可能ならばtrueを返す

Returns:

  • (Boolean)


238
239
240
241
242
243
244
245
# File 'lib/Miyako/API/fixedmap.rb', line 238

def can_access?(type, inout, pos, dx, dy, *ignores)
  return true if dx == 0 and dy == 0
  code = get_code(pos[0]+dx, pos[1]+dy)
  return true if (code == @def_ignore or @ignore_list.include?(code) or ignores.flatten.include?(code))
  index = MapDir.index2(inout, dx, dy)
  return true if index == -1
  return @mapchip.access_table[type][code][index]
end

#collision?(type, pos, collision, cpos, *ignores) ⇒ Boolean

キャラクタとマップチップが重なっているかどうか問い合わせる

指定の矩形のキャラクタが、指定の位置のマップチップのコリジョンと重なっているかどうか問い合わせる 引数は、Rect(x,y,w,h)形式(Rect構造体、の配列)で渡す 指定の位置のマップチップ番号が以下の時はfalseを返す 1)-1(未定義)のとき 2)FixexMapLayer#ignore_listに含まれているとき 3)引数ignoresに含まれているとき

type

移動形式(0以上の整数)

pos

調査対象のマップチップの位置

collision

キャラクタのコリジョン

cpos

キャラクタの位置

ignores

コリジョンの対象にしないマップチップ番号のリスト

返却値

コリジョンが重なっていればtrueを返す

Returns:

  • (Boolean)


180
181
182
183
184
# File 'lib/Miyako/API/fixedmap.rb', line 180

def collision?(type, pos, collision, cpos, *ignores)
  code = get_code(*pos.to_a)
  return false if (code == @def_ignore or @ignore_list.include?(code) or ignores.flatten.include?(code))
  return @mapchip.collision_table[type][code].collision?(pos, collision, cpos)
end

#convert_position(x, y) ⇒ Object

:nodoc:



127
128
129
130
# File 'lib/Miyako/API/fixedmap.rb', line 127

def convert_position(x, y) #:nodoc:
  return Point.new(@modpx2[round(x, @size.w)],
                   @modpy2[round(y, @size.h)])
end

#cover?(type, pos, collision, rect, *ignores) ⇒ Boolean

キャラクタとマップチップが覆い被さっているかどうか問い合わせる

指定の矩形のキャラクタが、指定の位置のマップチップのコリジョンを覆い被さっているかどうか問い合わせる 引数は、Rect(x,y,w,h)形式(Rect構造体、の配列)で渡す 指定の位置のマップチップ番号が以下の時はfalseを返す 1)-1(未定義)のとき 2)FixexMapLayer#ignore_listに含まれているとき 3)引数ignoresに含まれているとき

type

移動形式(0以上の整数)

pos

調査対象のマップチップの位置

collision

キャラクタのコリジョン

cpos

キャラクタの位置

ignores

コリジョンの対象にしないマップチップ番号のリスト

返却値

どちらかのコリジョンが覆い被さっていればtrueを返す

Returns:

  • (Boolean)


218
219
220
221
222
# File 'lib/Miyako/API/fixedmap.rb', line 218

def cover?(type, pos, collision, rect, *ignores)
  code = get_code(*pos.to_a)
  return false if (code == @def_ignore or @ignore_list.include?(code) or ignores.flatten.include?(code))
  return @mapchip.collision_table[type][code].cover?(pos, collision, cpos)
end

#disposeObject

:nodoc:



247
248
249
250
251
252
# File 'lib/Miyako/API/fixedmap.rb', line 247

def dispose #:nodoc:
  @mapdat = nil
  @baseimg = nil
  @ignore_list.clear
  @ignore_list = []
end

#get_code(x, y) ⇒ Object

実座標を使用して、指定のレイヤー・位置のマップチップ番号を取得

イベントレイヤーでの番号はイベント番号と一致する

x

マップチップ単位での位置(ピクセル単位)

y

マップチップ単位での位置(ピクセル単位)

返却値

マップチップ番号(マップチップが設定されている時は0以上の整数、設定されていない場合は-1が返る)



162
163
164
165
# File 'lib/Miyako/API/fixedmap.rb', line 162

def get_code(x, y)
  pos = convert_position(x / @mapchip.chip_size[0], y / @mapchip.chip_size[1])
  return @mapdat[pos.y][pos.x]
end

#get_div_array(s, t, v) ⇒ Object

:nodoc:



115
116
117
118
119
# File 'lib/Miyako/API/fixedmap.rb', line 115

def get_div_array(s, t, v) #:nodoc:
  a = Array.new
  (s..t).each{|i| a.push(i / v)}
  return a
end

#get_mod_array(s, t, v) ⇒ Object

:nodoc:



121
122
123
124
125
# File 'lib/Miyako/API/fixedmap.rb', line 121

def get_mod_array(s, t, v) #:nodoc:
  a = Array.new
  (s..t).each{|i| a.push(i % v)}
  return a
end

#initialize_copy(obj) ⇒ Object

:nodoc:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/Miyako/API/fixedmap.rb', line 95

def initialize_copy(obj) #:nodoc:
  @mapchip = @mapchip.dup
  @size = @size.dup
  @mapchip_unit = @mapchip_unit.dup
  @divpx = get_div_array(0, @real_size.w, @ow)
  @divpy = get_div_array(0, @real_size.h, @oh)
  @modpx = get_mod_array(0, @real_size.w, @ow)
  @modpy = get_mod_array(0, @real_size.h, @oh)
  @modpx2 = get_mod_array(0, @size.w * 2 + 1, @size.w)
  @modpy2 = get_mod_array(0, @size.h * 2 + 1, @size.h)
  @cdivsx = get_div_array(0, @mapchip.chips, @mapchip.size.w)
  @cmodsx = get_mod_array(0, @mapchip.chips, @mapchip.size.w)
  @cdivsy = get_div_array(0, @mapchip.chips, @mapchip.size.h)
  @cmodsy = get_mod_array(0, @mapchip.chips, @mapchip.size.h)
  @cdivsx = @cdivsx.map{|v| v * @ow }
  @cdivsy = @cdivsy.map{|v| v * @oh }
  @cmodsx = @cmodsx.map{|v| v * @ow }
  @cmodsy = @cmodsy.map{|v| v * @oh }
end

#layerObject

レイヤー配列を取得する

レイヤーを構成している配列を取得する 取得した配列にアクセスするときの書式は、以下のようになる。 layer[x]

返却値

所持しているレイヤー配列



137
138
139
# File 'lib/Miyako/API/fixedmap.rb', line 137

def layer
  @mapdat
end

#meet?(type, pos, collision, rect, *ignores) ⇒ Boolean

キャラクタとマップチップが隣り合っているかどうか問い合わせる

指定の矩形のキャラクタが、指定の位置のマップチップのコリジョンと隣り合っているかどうか問い合わせる 引数は、Rect(x,y,w,h)形式(Rect構造体、の配列)で渡す 指定の位置のマップチップ番号が以下の時はfalseを返す 1)-1(未定義)のとき 2)FixexMapLayer#ignore_listに含まれているとき 3)引数ignoresに含まれているとき

type

移動形式(0以上の整数)

pos

調査対象のマップチップの位置

collision

キャラクタのコリジョン

cpos

キャラクタの位置

ignores

コリジョンの対象にしないマップチップ番号のリスト

返却値

コリジョンが隣り合っていればtrueを返す

Returns:

  • (Boolean)


199
200
201
202
203
# File 'lib/Miyako/API/fixedmap.rb', line 199

def meet?(type, pos, collision, rect, *ignores)
  code = get_code(*pos.to_a)
  return false if (code == @def_ignore or @ignore_list.include?(code) or ignores.flatten.include?(code))
  return @mapchip.collision_table[type][code].meet?(pos, collision, cpos)
end

#product_position(rect) ⇒ Object

指定の矩形のキャラクタに掛かるマップチップの左上位置の組み合わせを返す

但し、引数には、Rect(x,y,w,h)形式のインスタンスを渡す

rect

キャラクタの矩形

返却値

マップチップ左上位置の配列(キャラクタに掛かる位置の組み合わせ)



145
146
147
# File 'lib/Miyako/API/fixedmap.rb', line 145

def product_position(rect)
  return Utility.product_position(rect, @mapchip.chip_size)
end

#product_position_by_square(square) ⇒ Object

指定の矩形のキャラクタに掛かるマップチップの左上位置の組み合わせを返す

但し、引数には、Square()形式のインスタンスを渡す

square

キャラクタの矩形

返却値

マップチップ左上位置の配列(キャラクタに掛かる位置の組み合わせ)



153
154
155
# File 'lib/Miyako/API/fixedmap.rb', line 153

def product_position_by_square(square)
  return Utility.product_position_by_square(square, @mapchip.chip_size)
end

#renderObject

マップレイヤーを画面に描画する

すべてのマップチップを画面に描画する ブロック付きで呼び出し可能(レシーバに対応したSpriteUnit構造体が引数として得られるので、補正をかけることが出来る) (ブロック引数のインスタンスは複写しているので、メソッドの引数として渡した値が持つSpriteUnitには影響しない) ブロックの引数は、|画面のSpriteUnit|となる。 visibleメソッドの値がfalseのときは描画されない。

返却値

自分自身を返す



261
262
# File 'lib/Miyako/API/fixedmap.rb', line 261

def render
end

#render_to(dst) ⇒ Object

マップを画像に描画する

すべてのマップチップを画像に描画する 各レイヤ-を、レイヤーインデックス番号の若い順に描画する 但し、マップイベントは描画しない ブロック付きで呼び出し可能(レシーバに対応したSpriteUnit構造体が引数として得られるので、補正をかけることが出来る) (ブロック引数のインスタンスは複写しているので、メソッドの引数として渡した値が持つSpriteUnitには影響しない) ブロックの引数は、|転送先のSpriteUnit|となる。 visibleメソッドの値がfalseのときは描画されない。

dst

転送先ビットマップ(to_unitメソッドを呼び出すことが出来る/値がnilではないインスタンス)

返却値

自分自身を返す



274
275
# File 'lib/Miyako/API/fixedmap.rb', line 274

def render_to(dst)
end

#reSizeObject

:nodoc:



54
55
56
57
# File 'lib/Miyako/API/fixedmap.rb', line 54

def reSize #:nodoc:
  @cw = @real_size.w % @ow == 0 ? @real_size.w / @ow : (@real_size.w + @ow - 1)/ @ow + 1
  @ch = @real_size.h % @oh == 0 ? @real_size.h / @oh : (@real_size.h + @oh - 1)/ @oh + 1
end

#round(v, max) ⇒ Object

:nodoc:



48
49
50
51
52
# File 'lib/Miyako/API/fixedmap.rb', line 48

def round(v, max) #:nodoc:
  v = max + (v % max) if v < 0
  v %= max if v >= max
  return v
end