cyross-ruby-miyako 2.0.0
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.
- data/README +977 -0
- data/Rakefile +7 -0
- data/img/cursor.png +0 -0
- data/img/cursors.png +0 -0
- data/img/dice.png +0 -0
- data/img/wait_cursor.png +0 -0
- data/img/win_base.png +0 -0
- data/img/window.png +0 -0
- data/install_miyako.rb +75 -0
- data/lib/Miyako/API/audio.rb +198 -0
- data/lib/Miyako/API/basic_data.rb +431 -0
- data/lib/Miyako/API/bitmap.rb +35 -0
- data/lib/Miyako/API/choices.rb +308 -0
- data/lib/Miyako/API/collision.rb +444 -0
- data/lib/Miyako/API/diagram.rb +573 -0
- data/lib/Miyako/API/drawing.rb +110 -0
- data/lib/Miyako/API/fixedmap.rb +315 -0
- data/lib/Miyako/API/font.rb +384 -0
- data/lib/Miyako/API/input.rb +440 -0
- data/lib/Miyako/API/layout.rb +451 -0
- data/lib/Miyako/API/map.rb +403 -0
- data/lib/Miyako/API/map_event.rb +198 -0
- data/lib/Miyako/API/modules.rb +109 -0
- data/lib/Miyako/API/movie.rb +151 -0
- data/lib/Miyako/API/parts.rb +154 -0
- data/lib/Miyako/API/plane.rb +131 -0
- data/lib/Miyako/API/screen.rb +257 -0
- data/lib/Miyako/API/shape.rb +362 -0
- data/lib/Miyako/API/sprite.rb +338 -0
- data/lib/Miyako/API/sprite_animation.rb +461 -0
- data/lib/Miyako/API/spriteunit.rb +113 -0
- data/lib/Miyako/API/story.rb +224 -0
- data/lib/Miyako/API/textbox.rb +496 -0
- data/lib/Miyako/API/viewport.rb +435 -0
- data/lib/Miyako/API/yuki.rb +779 -0
- data/lib/Miyako/EXT/miyako_cairo.rb +60 -0
- data/lib/Miyako/EXT/raster_scroll.rb +138 -0
- data/lib/Miyako/EXT/slides.rb +136 -0
- data/lib/Miyako/miyako.rb +172 -0
- data/miyako.png +0 -0
- data/miyako_banner.png +0 -0
- data/miyako_no_katana/extconf.rb +34 -0
- data/miyako_no_katana/miyako_no_katana.c +3301 -0
- data/sample/Animation1/m1ku.rb +89 -0
- data/sample/Animation1/m1ku_arm_0.png +0 -0
- data/sample/Animation1/m1ku_arm_1.png +0 -0
- data/sample/Animation1/m1ku_arm_2.png +0 -0
- data/sample/Animation1/m1ku_arm_3.png +0 -0
- data/sample/Animation1/m1ku_back.jpg +0 -0
- data/sample/Animation1/m1ku_body.png +0 -0
- data/sample/Animation1/m1ku_eye_0.png +0 -0
- data/sample/Animation1/m1ku_eye_1.png +0 -0
- data/sample/Animation1/m1ku_eye_2.png +0 -0
- data/sample/Animation1/m1ku_eye_3.png +0 -0
- data/sample/Animation1/m1ku_hair_front.png +0 -0
- data/sample/Animation1/m1ku_hair_rear.png +0 -0
- data/sample/Animation1/readme.txt +72 -0
- data/sample/Animation2/lex.rb +95 -0
- data/sample/Animation2/lex_back.png +0 -0
- data/sample/Animation2/lex_body.png +0 -0
- data/sample/Animation2/lex_roadroller.png +0 -0
- data/sample/Animation2/lex_wheel_0.png +0 -0
- data/sample/Animation2/lex_wheel_1.png +0 -0
- data/sample/Animation2/lex_wheel_2.png +0 -0
- data/sample/Animation2/readme.txt +72 -0
- data/sample/Animation2/song_title.png +0 -0
- data/sample/Diagram_sample/back.png +0 -0
- data/sample/Diagram_sample/chr01.png +0 -0
- data/sample/Diagram_sample/chr02.png +0 -0
- data/sample/Diagram_sample/cursor.png +0 -0
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +283 -0
- data/sample/Diagram_sample/readme.txt +87 -0
- data/sample/Diagram_sample/wait_cursor.png +0 -0
- data/sample/Room3/blue.rb +250 -0
- data/sample/Room3/ending.rb +175 -0
- data/sample/Room3/green.rb +185 -0
- data/sample/Room3/image/akamatsu.png +0 -0
- data/sample/Room3/image/aoyama.png +0 -0
- data/sample/Room3/image/congra.png +0 -0
- data/sample/Room3/image/congratulation.png +0 -0
- data/sample/Room3/image/congratulation_bg.png +0 -0
- data/sample/Room3/image/cursor.png +0 -0
- data/sample/Room3/image/midori.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
- data/sample/Room3/image/room_blue.png +0 -0
- data/sample/Room3/image/room_green.png +0 -0
- data/sample/Room3/image/room_red.png +0 -0
- data/sample/Room3/image/start.png +0 -0
- data/sample/Room3/image/three_doors.png +0 -0
- data/sample/Room3/image/wait_cursor.png +0 -0
- data/sample/Room3/main.rb +102 -0
- data/sample/Room3/main_component.rb +58 -0
- data/sample/Room3/readme.txt +76 -0
- data/sample/Room3/red.rb +200 -0
- data/sample/Room3/room3.rb +26 -0
- data/sample/Room3/title.rb +171 -0
- data/sample/fixed_map_test/cursor.png +0 -0
- data/sample/fixed_map_test/fixed_map_sample.rb +149 -0
- data/sample/fixed_map_test/map.csv +19 -0
- data/sample/fixed_map_test/map_01.png +0 -0
- data/sample/fixed_map_test/map_sample.rb +121 -0
- data/sample/fixed_map_test/mapchip.csv +23 -0
- data/sample/fixed_map_test/monster.png +0 -0
- data/sample/fixed_map_test/readme.txt +72 -0
- data/sample/map_test/chara.rb +50 -0
- data/sample/map_test/chr1.png +0 -0
- data/sample/map_test/cursor.png +0 -0
- data/sample/map_test/main_parts.rb +48 -0
- data/sample/map_test/main_scene.rb +137 -0
- data/sample/map_test/map.png +0 -0
- data/sample/map_test/map2.png +0 -0
- data/sample/map_test/map_layer.csv +127 -0
- data/sample/map_test/map_manager.rb +92 -0
- data/sample/map_test/map_test.rb +23 -0
- data/sample/map_test/mapchip.csv +21 -0
- data/sample/map_test/oasis.rb +65 -0
- data/sample/map_test/readme.txt +87 -0
- data/sample/map_test/route.rb +144 -0
- data/sample/map_test/sea.png +0 -0
- data/sample/map_test/town.rb +68 -0
- data/sample/map_test/wait_cursor.png +0 -0
- data/sample/map_test/window.png +0 -0
- data/win/miyako_no_katana.so +0 -0
- metadata +194 -0
@@ -0,0 +1,403 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
--
|
4
|
+
Miyako v2.0
|
5
|
+
Copyright (C) 2007-2008 Cyross Makoto
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License as published by the Free Software Foundation; either
|
10
|
+
version 2.1 of the License, or (at your option) any later version.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public
|
18
|
+
License along with this library; if not, write to the Free Software
|
19
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
++
|
21
|
+
=end
|
22
|
+
|
23
|
+
require 'csv'
|
24
|
+
require 'forwardable'
|
25
|
+
|
26
|
+
module Miyako
|
27
|
+
#=マップチップ定義構造体
|
28
|
+
MapChip = Struct.new(:chip_image, :chips, :size, :chip_size, :access_types, :collision_table, :access_table)
|
29
|
+
#=Map用コリジョン構造体
|
30
|
+
MapMoveAmount = Struct.new(:collisions, :amount)
|
31
|
+
|
32
|
+
#=マップチップ作成ファクトリクラス
|
33
|
+
class MapChipFactory
|
34
|
+
#===マップチップを作成するためのファクトリクラス
|
35
|
+
#_csv_filename_:: マップチップファイル名(CSVファイル)
|
36
|
+
#_use_alpha_:: 画像にαチャネルを使うかどうかのフラグ。trueのときは画像のαチャネルを使用、falseのときはカラーキーを使用。デフォルトはtrue
|
37
|
+
def MapChipFactory.load(csv_filename, use_alpha = true)
|
38
|
+
lines = CSV.read(csv_filename)
|
39
|
+
raise MiyakoError, "This file is not Miyako Map Chip file! : #{csv_filename}" unless lines.shift[0] == "Miyako Mapchip"
|
40
|
+
spr = use_alpha ? Sprite.new({:filename => lines.shift[0], :type => :alpha_channel}) : Sprite.new({:file_name => lines.shift[0], :type => :color_key})
|
41
|
+
tmp = lines.shift
|
42
|
+
chip_size = Size.new(tmp[0].to_i, tmp[1].to_i)
|
43
|
+
size = Size.new(spr.w / chip_size.w, spr.h / chip_size.h)
|
44
|
+
chips = size.w * size.h
|
45
|
+
access_types = lines.shift[0].to_i
|
46
|
+
collision_table = Array.new(access_types){|at|
|
47
|
+
Array.new(chips){|n| Collision.new(lines.shift.map{|s| s.to_i}, Point.new(0, 0)) }
|
48
|
+
}
|
49
|
+
access_table = Array.new(access_types){|at|
|
50
|
+
Array.new(chips){|n| lines.shift.map{|s| s.to_i} << 0 }
|
51
|
+
}
|
52
|
+
return MapChip.new(spr, chips, size, chip_size, access_types, collision_table, access_table)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#==マップ定義クラス
|
57
|
+
class Map
|
58
|
+
@@idx_ix = [-1, 2, 4]
|
59
|
+
@@idx_iy = [-1, 0, 6]
|
60
|
+
|
61
|
+
attr_reader :map_layers, :pos, :margin, :size, :w, :h
|
62
|
+
|
63
|
+
class MapLayer #:nodoc: all
|
64
|
+
extend Forwardable
|
65
|
+
|
66
|
+
attr_reader :mapchip_units, :pos, :margin, :size
|
67
|
+
|
68
|
+
def round(v, max) #:nodoc:
|
69
|
+
v = max + (v % max) if v < 0
|
70
|
+
v %= max if v >= max
|
71
|
+
return v
|
72
|
+
end
|
73
|
+
|
74
|
+
def resize #:nodoc:
|
75
|
+
@cw = (Screen.w + @ow - 1)/ @ow + 1
|
76
|
+
@ch = (Screen.h + @oh - 1)/ @oh + 1
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize(mapchip, mapdat, layer_size) #:nodoc:
|
80
|
+
@mapchip = mapchip
|
81
|
+
@pos = Point.new(0, 0)
|
82
|
+
@margin = Size.new(0, 0)
|
83
|
+
@size = layer_size.dup
|
84
|
+
@ow = @mapchip.chip_size.w
|
85
|
+
@oh = @mapchip.chip_size.h
|
86
|
+
@real_size = Size.new(@size.w * @ow, @size.h * @oh)
|
87
|
+
@mapdat = mapdat
|
88
|
+
@baseimg = @mapchip.chip_image
|
89
|
+
@divpx = get_div_array(0, @real_size.w, @ow)
|
90
|
+
@divpy = get_div_array(0, @real_size.h, @oh)
|
91
|
+
@modpx = get_mod_array(0, @real_size.w, @ow)
|
92
|
+
@modpy = get_mod_array(0, @real_size.h, @oh)
|
93
|
+
@modpx2 = get_mod_array(0, @size.w * 2 + 1, @size.w)
|
94
|
+
@modpy2 = get_mod_array(0, @size.h * 2 + 1, @size.h)
|
95
|
+
@cdivsx = get_div_array(0, @mapchip.chips, @mapchip.size.w)
|
96
|
+
@cmodsx = get_mod_array(0, @mapchip.chips, @mapchip.size.w)
|
97
|
+
@cdivsy = get_div_array(0, @mapchip.chips, @mapchip.size.h)
|
98
|
+
@cmodsy = get_mod_array(0, @mapchip.chips, @mapchip.size.h)
|
99
|
+
@cdivsx = @cdivsx.map{|v| v * @ow }
|
100
|
+
@cdivsy = @cdivsy.map{|v| v * @oh }
|
101
|
+
@cmodsx = @cmodsx.map{|v| v * @ow }
|
102
|
+
@cmodsy = @cmodsy.map{|v| v * @oh }
|
103
|
+
@mapchip_units = Array.new(@mapchip.chips){|idx|
|
104
|
+
SpriteUnitFactory.create(:bitmap=>@baseimg.bitmap,
|
105
|
+
:ox => (idx % @mapchip.size.w) * @ow,
|
106
|
+
:oy => (idx / @mapchip.size.w) * @oh,
|
107
|
+
:ow => @ow,
|
108
|
+
:oh => @oh)
|
109
|
+
}
|
110
|
+
resize
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_div_array(s, t, v) #:nodoc:
|
114
|
+
a = Array.new
|
115
|
+
(s..t).each{|i| a.push(i / v)}
|
116
|
+
return a
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_mod_array(s, t, v) #:nodoc:
|
120
|
+
a = Array.new
|
121
|
+
(s..t).each{|i| a.push(i % v)}
|
122
|
+
return a
|
123
|
+
end
|
124
|
+
|
125
|
+
def convert_position(x, y) #:nodoc:
|
126
|
+
return Point.new(@modpx2[round(x, @size.w)],
|
127
|
+
@modpy2[round(y, @size.h)])
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_code(x, y) #:nodoc:
|
131
|
+
pos = convert_position(x, y)
|
132
|
+
return @mapdat[pos.y][pos.x]
|
133
|
+
end
|
134
|
+
|
135
|
+
def dispose #:nodoc:
|
136
|
+
@mapdat = nil
|
137
|
+
@baseimg = nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
#===インスタンスを生成する
|
142
|
+
#_mapchip_:: マップチップ構造体群
|
143
|
+
#_layer_csv_:: レイヤーファイル(CSVファイル)
|
144
|
+
#_event_manager_:: MapEventManagerクラスのインスタンス
|
145
|
+
#返却値:: 生成したインスタンス
|
146
|
+
def initialize(mapchip, layer_csv, event_manager)
|
147
|
+
@em = event_manager.dup
|
148
|
+
@em.set(self)
|
149
|
+
@mapchip = mapchip
|
150
|
+
@visible = false
|
151
|
+
@pos = Point.new(0, 0)
|
152
|
+
@margin = Size.new(0, 0)
|
153
|
+
@coll = Collision.new(Rect.new(0, 0, 0, 0), Point.new(0, 0))
|
154
|
+
layer_data = CSV.readlines(layer_csv)
|
155
|
+
raise MiyakoError, "This file is not Miyako Map Layer file! : #{layer_csv}" unless layer_data.shift[0] == "Miyako Maplayer"
|
156
|
+
|
157
|
+
tmp = layer_data.shift # 空行の空読み込み
|
158
|
+
|
159
|
+
layer_size = Size.new(*(tmp.map{|v| v.to_i}))
|
160
|
+
@w = layer_size.w
|
161
|
+
@h = layer_size.h
|
162
|
+
|
163
|
+
layers = layer_data.shift[0].to_i
|
164
|
+
|
165
|
+
brlist = {}
|
166
|
+
layers.times{|n|
|
167
|
+
name = layer_data.shift[0]
|
168
|
+
if name == "<event>"
|
169
|
+
name = :event
|
170
|
+
else
|
171
|
+
name = /\<(\d+)\>/.match(name).to_a[1].to_i
|
172
|
+
end
|
173
|
+
values = []
|
174
|
+
layer_size.h.times{|y|
|
175
|
+
values << layer_data.shift.map{|m| m.to_i}
|
176
|
+
}
|
177
|
+
brlist[name] = values
|
178
|
+
}
|
179
|
+
|
180
|
+
@map_layers = Array.new
|
181
|
+
@event_layer = nil
|
182
|
+
|
183
|
+
if brlist.has_key?(:event)
|
184
|
+
@event_layer = Array.new
|
185
|
+
brlist[:event].each_with_index{|ly, y|
|
186
|
+
ly.each_with_index{|code, x|
|
187
|
+
next unless @em.include?(code)
|
188
|
+
@event_layer.push(@em.create(code, x * @mapchip.chip_size.w, y * @mapchip.chip_size.h))
|
189
|
+
}
|
190
|
+
}
|
191
|
+
layers -= 1
|
192
|
+
end
|
193
|
+
|
194
|
+
@map_layers = []
|
195
|
+
layers.times{|i|
|
196
|
+
br = brlist[i].map{|b| b.map{|bb| bb >= @mapchip.chips ? -1 : bb } }
|
197
|
+
@map_layers.push(MapLayer.new(@mapchip, br, layer_size))
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
#===マップにイベントを追加する
|
202
|
+
#_code_:: イベント番号(Map.newメソッドで渡したイベント番号に対応)
|
203
|
+
#_x_:: マップ上の位置(x方向)
|
204
|
+
#_y_:: マップ常温位置(y方向)
|
205
|
+
#返却値:: 自分自身を返す
|
206
|
+
def add_event(code, x, y)
|
207
|
+
return self unless @em.include?(code)
|
208
|
+
@event_layer.push(@em.create(code, x, y))
|
209
|
+
return self
|
210
|
+
end
|
211
|
+
|
212
|
+
#===マップを移動(移動量指定)
|
213
|
+
#_dx_:: 移動量(x方向)
|
214
|
+
#_dy_:: 移動量(y方向)
|
215
|
+
#返却値:: 自分自身を返す
|
216
|
+
def move(dx,dy)
|
217
|
+
@pos.move(dx, dy)
|
218
|
+
@map_layers.each{|l| l.pos.move(dx, dy) }
|
219
|
+
return self
|
220
|
+
end
|
221
|
+
|
222
|
+
#===マップを移動(移動先指定)
|
223
|
+
#_dx_:: 移動先(x方向)
|
224
|
+
#_dy_:: 移動先(y方向)
|
225
|
+
#返却値:: 自分自身を返す
|
226
|
+
def move_to(x,y)
|
227
|
+
@pos.move_to(x, y)
|
228
|
+
@map_layers.each{|l| l.pos.move_to(x, y) }
|
229
|
+
return self
|
230
|
+
end
|
231
|
+
|
232
|
+
#===画像の表示矩形を取得する
|
233
|
+
#Mapの大きさを矩形で取得する。値は、Screen.rectメソッドの値と同じ。
|
234
|
+
#返却値:: 生成された矩形
|
235
|
+
def rect
|
236
|
+
return Screen.rect
|
237
|
+
end
|
238
|
+
|
239
|
+
#===現在の画面の最大の大きさを矩形で取得する
|
240
|
+
#但し、Mapの場合は最大の大きさ=画面の大きさなので、rectと同じ値が得られる
|
241
|
+
#返却値:: 画像の大きさ(Rect構造体のインスタンス)
|
242
|
+
def broad_rect
|
243
|
+
return self.rect
|
244
|
+
end
|
245
|
+
|
246
|
+
#===設定したマージンを各レイヤーに同期させる
|
247
|
+
#マージンを設定した後は必ずこのメソッドを呼び出すこと
|
248
|
+
#返却値:: 自分自身を返す
|
249
|
+
def sync_margin
|
250
|
+
@map_layers.each{|l| l.margin.resize(*@margin) }
|
251
|
+
return self
|
252
|
+
end
|
253
|
+
|
254
|
+
#===設定したマージンを各レイヤーに同期させる
|
255
|
+
#マージンを設定した後は必ずこのメソッドを呼び出すこと
|
256
|
+
#返却値:: 自分自身を返す
|
257
|
+
def [](idx)
|
258
|
+
return @map_layers[idx]
|
259
|
+
end
|
260
|
+
|
261
|
+
#===あとで書く
|
262
|
+
#_idx_:: あとで書く
|
263
|
+
#_x_:: あとで書く
|
264
|
+
#_y_:: あとで書く
|
265
|
+
#返却値:: あとで書く
|
266
|
+
def get_code_real(idx, x = 0, y = 0)
|
267
|
+
code = @map_layers[idx].get_code(x / @mapchip.chip_size[0], y / @mapchip.chip_size[1])
|
268
|
+
yield code if block_given?
|
269
|
+
return code
|
270
|
+
end
|
271
|
+
|
272
|
+
#===あとで書く
|
273
|
+
#_idx_:: あとで書く
|
274
|
+
#_x_:: あとで書く
|
275
|
+
#_y_:: あとで書く
|
276
|
+
#返却値:: あとで書く
|
277
|
+
def get_code(idx, x = 0, y = 0)
|
278
|
+
code = @map_layers[idx].get_code(x, y)
|
279
|
+
yield code if block_given?
|
280
|
+
return code
|
281
|
+
end
|
282
|
+
|
283
|
+
#===あとで書く
|
284
|
+
#_idx_:: あとで書く
|
285
|
+
#_code_:: あとで書く
|
286
|
+
#_base_:: あとで書く
|
287
|
+
#返却値:: あとで書く
|
288
|
+
def set_mapchip_base(idx, code, base)
|
289
|
+
@map_layers[idx].mapchip_units[code] = base
|
290
|
+
return self
|
291
|
+
end
|
292
|
+
|
293
|
+
#===あとで書く
|
294
|
+
#_type_:: あとで書く
|
295
|
+
#_size_:: あとで書く
|
296
|
+
#_collision_:: あとで書く
|
297
|
+
#返却値:: あとで書く
|
298
|
+
def get_amount(type, size, collision)
|
299
|
+
mma = MapMoveAmount.new([], collision.direction.dup)
|
300
|
+
return mma if(mma.amount[0] == 0 && mma.amount[1] == 0)
|
301
|
+
collision.pos = Point.new(*@pos.to_a[0..1])
|
302
|
+
dx, dy = collision.direction[0]*collision.amount[0], collision.direction[1]*collision.amount[1]
|
303
|
+
px1, px2 = (@pos[0]+dx) / @mapchip.chip_size[0], (@pos[0]+size[0]-1+dx) / @mapchip.chip_size[0]
|
304
|
+
py1, py2 = (@pos[1]+dy) / @mapchip.chip_size[1], (@pos[1]+size[1]-1+dy) / @mapchip.chip_size[1]
|
305
|
+
(py1..py2).each{|py|
|
306
|
+
rpy = py * @mapchip.chip_size[1]
|
307
|
+
(px1..px2).each{|px|
|
308
|
+
rpx = px * @mapchip.chip_size[0]
|
309
|
+
@map_layers.each_with_index{|ml, idx|
|
310
|
+
code = ml.get_code(px, py)
|
311
|
+
next if code == -1 # not use chip
|
312
|
+
@coll = @mapchip.collision_table[type][code].dup
|
313
|
+
@coll.pos = Point.new(rpx, rpy)
|
314
|
+
atable = @mapchip.access_table[type][code]
|
315
|
+
if @coll.into?(collision)
|
316
|
+
mma.amount[0] = mma.amount[0] & atable[@@idx_ix[collision.direction[0]]]
|
317
|
+
mma.amount[1] = mma.amount[1] & atable[@@idx_iy[collision.direction[1]]]
|
318
|
+
mma.collisions << [idx, code, :into]
|
319
|
+
end
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|
323
|
+
mma.amount[0] *= collision.amount[0]
|
324
|
+
mma.amount[1] *= collision.amount[1]
|
325
|
+
yield mma if block_given?
|
326
|
+
return mma
|
327
|
+
end
|
328
|
+
|
329
|
+
#===あとで書く
|
330
|
+
#_type_:: あとで書く
|
331
|
+
#_rect_:: あとで書く
|
332
|
+
#_collision_:: あとで書く
|
333
|
+
#返却値:: あとで書く
|
334
|
+
def get_amount_by_rect(type, rect, collision)
|
335
|
+
mma = MapMoveAmount.new([], collision.direction.dup)
|
336
|
+
return mma if(mma.amount[0] == 0 && mma.amount[1] == 0)
|
337
|
+
dx, dy = collision.direction[0]*collision.amount[0], collision.direction[1]*collision.amount[1]
|
338
|
+
x, y = rect.to_a[0..1]
|
339
|
+
collision.pos = Point.new(x, y)
|
340
|
+
px1, px2 = (x+dx) / @mapchip.chip_size[0], (x+rect[2]-1+dx) / @mapchip.chip_size[0]
|
341
|
+
py1, py2 = (y+dy) / @mapchip.chip_size[1], (y+rect[3]-1+dy) / @mapchip.chip_size[1]
|
342
|
+
(py1..py2).each{|py|
|
343
|
+
rpy = py * @mapchip.chip_size[1]
|
344
|
+
(px1..px2).each{|px|
|
345
|
+
rpx = px * @mapchip.chip_size[0]
|
346
|
+
@map_layers.each_with_index{|ml, idx|
|
347
|
+
code = ml.get_code(px, py)
|
348
|
+
next if code == -1 # not use chip
|
349
|
+
@coll = @mapchip.collision_table[type][code].dup
|
350
|
+
@coll.pos = Point.new(rpx, rpy)
|
351
|
+
atable = @mapchip.access_table[type][code]
|
352
|
+
if @coll.into?(collision)
|
353
|
+
mma.amount[0] = mma.amount[0] & atable[@@idx_ix[collision.direction[0]]]
|
354
|
+
mma.amount[1] = mma.amount[1] & atable[@@idx_iy[collision.direction[1]]]
|
355
|
+
mma.collisions << [idx, code, :into]
|
356
|
+
end
|
357
|
+
}
|
358
|
+
}
|
359
|
+
}
|
360
|
+
mma.amount[0] *= collision.amount[0]
|
361
|
+
mma.amount[1] *= collision.amount[1]
|
362
|
+
yield mma if block_given?
|
363
|
+
return mma
|
364
|
+
end
|
365
|
+
|
366
|
+
#===あとで書く
|
367
|
+
#返却値:: あとで書く
|
368
|
+
def chip_size
|
369
|
+
return @mapchip.chip_size
|
370
|
+
end
|
371
|
+
|
372
|
+
#===あとで書く
|
373
|
+
#返却値:: あとで書く
|
374
|
+
def final
|
375
|
+
@event_layer.each{|e| e.final } if @event_layer
|
376
|
+
end
|
377
|
+
|
378
|
+
#===あとで書く
|
379
|
+
#返却値:: あとで書く
|
380
|
+
def dispose
|
381
|
+
@map_layers.each{|l|
|
382
|
+
l.dispose
|
383
|
+
l = nil
|
384
|
+
}
|
385
|
+
@map_layers = Array.new
|
386
|
+
if @event_layer
|
387
|
+
@event_layer.each{|e| e.dispose }
|
388
|
+
@event_layer = nil
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
def re_size #:nodoc:
|
393
|
+
@map_layers.each{|l| l.reSize }
|
394
|
+
return self
|
395
|
+
end
|
396
|
+
|
397
|
+
#===マップに登録しているイベントインスタンス(マップイベント)を取得する
|
398
|
+
#返却値:: マップイベントの配列
|
399
|
+
def events
|
400
|
+
return @event_layer || []
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
--
|
4
|
+
Miyako v2.0
|
5
|
+
Copyright (C) 2007-2008 Cyross Makoto
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License as published by the Free Software Foundation; either
|
10
|
+
version 2.1 of the License, or (at your option) any later version.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public
|
18
|
+
License along with this library; if not, write to the Free Software
|
19
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
++
|
21
|
+
=end
|
22
|
+
|
23
|
+
require 'csv'
|
24
|
+
require 'forwardable'
|
25
|
+
|
26
|
+
module Miyako
|
27
|
+
#==マップ上のイベント全体を管理するクラス
|
28
|
+
#Map/FixedMapクラス内で使用する
|
29
|
+
#使い方:
|
30
|
+
#
|
31
|
+
#(1)インスタンスを生成する
|
32
|
+
#
|
33
|
+
#em = MapEventManager.new
|
34
|
+
#
|
35
|
+
#(2)MapEventクラスとIDを登録する
|
36
|
+
#
|
37
|
+
#(例)MapEventモジュールをmixinしたクラスXを、ID=0のイベントとして登録
|
38
|
+
#
|
39
|
+
#em.add(0, X)
|
40
|
+
#
|
41
|
+
#(3)Map/FixedMapクラスインスタンス生成時に引数として渡す
|
42
|
+
#
|
43
|
+
#@map = Map.new(...,em)
|
44
|
+
#
|
45
|
+
#(注)登録するIDは、イベントレイヤー上の番号と対応しておくこと
|
46
|
+
class MapEventManager
|
47
|
+
#===インスタンスを生成する
|
48
|
+
#_map_obj_:: Managerが属するMap/FixedMapクラスのインスタンス
|
49
|
+
#返却値:: 生成されたインスタンス
|
50
|
+
def initialize
|
51
|
+
@map = nil
|
52
|
+
@id2event = Hash.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def set(map) #:nodoc:
|
56
|
+
@map = map
|
57
|
+
end
|
58
|
+
|
59
|
+
#===イベントクラスをマップに追加登録する
|
60
|
+
#_id_:: マップ(イベントレイヤ)上の番号。
|
61
|
+
#イベントレイヤ上に存在しない番号を渡してもエラーや警告は発しない
|
62
|
+
#_event_:: イベントクラス。クラスのインスタンスではないことに注意!
|
63
|
+
#返却値:: 自分自身を返す
|
64
|
+
def add(id, event)
|
65
|
+
@id2event[id] = event
|
66
|
+
return self
|
67
|
+
end
|
68
|
+
|
69
|
+
#===イベントが登録されているかを確認する
|
70
|
+
#引数で渡した番号に対応するイベントクラスが登録されているかどうかを確認する
|
71
|
+
#_id_:: イベントクラスに対応した番号
|
72
|
+
#返却値:: イベントクラスが登録されている時はtrueを返す
|
73
|
+
def include?(id)
|
74
|
+
raise MiyakoError, "This MapEventManager instance is not set Map/FixedMap instance!" unless @map
|
75
|
+
return @id2event.has_key?(id)
|
76
|
+
end
|
77
|
+
|
78
|
+
#===イベントのインスタンスを生成する(番号指定)
|
79
|
+
#インスタンス生成と同時に、マップ上の座標を渡して初期位置を設定する
|
80
|
+
#登録していないIDを指定するとエラーになる
|
81
|
+
#
|
82
|
+
#設置は、マップ上の座標に設置する。表示上の座標ではない事に注意。
|
83
|
+
#_id_:: イベントクラスと登録した際の番号
|
84
|
+
#_x_:: イベントを設置する位置(X座標)
|
85
|
+
#_y_:: イベントを設置する位置(Y座標)
|
86
|
+
#返却値:: 生成したインスタンス
|
87
|
+
def create(id, x = 0, y = 0)
|
88
|
+
raise MiyakoError, "This MapEventManager instance is not set Map/FixedMap instance!" unless @map
|
89
|
+
raise MiyakoError, "Unknown Map Event ID! : #{id}" unless include?(id)
|
90
|
+
return @id2event[id].new(@map, x, y)
|
91
|
+
end
|
92
|
+
|
93
|
+
#===すべての登録済みイベントクラスの登録を解除する
|
94
|
+
def clear
|
95
|
+
@id2event.keys.each{|k| @id2event[k] = nil }
|
96
|
+
end
|
97
|
+
|
98
|
+
def dispose
|
99
|
+
@map = nil
|
100
|
+
@id2event.clear
|
101
|
+
@id2event = nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
#==マップ上のイベントを管理するモジュール
|
106
|
+
#実際に使う際にはmix-inして使う
|
107
|
+
module MapEvent
|
108
|
+
#===イベントのインスタンスを作成する
|
109
|
+
#引数として渡せるX,Y座標の値は、表示上ではなく理論上の座標位置
|
110
|
+
#_map_obj_:: 関連づけられたMap/FixedMapクラスのインスタンス
|
111
|
+
#_x_:: マップ上のX座標の値。デフォルトは0
|
112
|
+
#_y_:: マップ上のY座標の値。デフォルトは0
|
113
|
+
#返却値:: 生成されたインスタンス
|
114
|
+
def initialize(map_obj, x = 0, y = 0)
|
115
|
+
init(map_obj, x, y)
|
116
|
+
end
|
117
|
+
|
118
|
+
#===イベント生成時のテンプレートメソッド
|
119
|
+
#イベントクラスからインスタンスが生成された時の初期化処理を実装する
|
120
|
+
#_map_obj_:: 関連づけられたMap/FixedMapクラスのインスタンス
|
121
|
+
#_x_:: マップ上のX座標の値
|
122
|
+
#_y_:: マップ上のY座標の値
|
123
|
+
def init(map_obj, x, y)
|
124
|
+
end
|
125
|
+
|
126
|
+
#===インスタンス内の表示やデータを更新するテンプレートメソッド
|
127
|
+
#マップ画像が更新された時に呼び出される
|
128
|
+
#_map_obj_:: インスタンスが組み込まれているMap/FixedMapクラスのインスタンス
|
129
|
+
#_events_:: マップに登録されているイベントインスタンスの配列
|
130
|
+
#_params_:: 開発者が明示的に用意した引数。内容はハッシュ
|
131
|
+
def update(map_obj, events, params)
|
132
|
+
end
|
133
|
+
|
134
|
+
#===イベントを指定の分量で移動させる(テンプレートメソッド)
|
135
|
+
#_dx_:: 移動量(x座標)。単位はピクセル
|
136
|
+
#_dy_:: 移動量(y座標)。単位はピクセル
|
137
|
+
#返却値:: 自分自身を返す
|
138
|
+
def move(dx,dy)
|
139
|
+
return self
|
140
|
+
end
|
141
|
+
|
142
|
+
#===イベントを指定の位置へ移動させる(テンプレートメソッド)
|
143
|
+
#_x_:: 移動先の位置(x座標)。単位はピクセル
|
144
|
+
#_y_:: 移動先の位置(y座標)。単位はピクセル
|
145
|
+
#返却値:: 自分自身を返す
|
146
|
+
def move_to(x,y)
|
147
|
+
return self
|
148
|
+
end
|
149
|
+
|
150
|
+
#===イベント発生可否問い合わせ(テンプレートメソッド)
|
151
|
+
#イベント発生が可能なときはtrueを返す(その後、startメソッドを呼び出す)処理を実装する
|
152
|
+
#_param_:: 問い合わせに使用するパラメータ群。デフォルトはnil
|
153
|
+
#返却値:: イベント発生可能ならばtrue
|
154
|
+
def met?(params = nil)
|
155
|
+
return false
|
156
|
+
end
|
157
|
+
|
158
|
+
#===画面に画像を描画する(テンプレートメソッド)
|
159
|
+
#イベントで所持している画像を描画するメソッドを実装する
|
160
|
+
#(イベント内部で用意している画像の描画用テンプレートメソッド)
|
161
|
+
def render
|
162
|
+
end
|
163
|
+
|
164
|
+
#===イベントを発生させる(テンプレートメソッド)
|
165
|
+
#ここに、イベント発生イベントを実装する。更新はupdateメソッドに実装する
|
166
|
+
#_param_:: イベント発生に必要なパラメータ群。デフォルトはnil
|
167
|
+
#返却値:: 自分自身を返す
|
168
|
+
def start(params = nil)
|
169
|
+
return self
|
170
|
+
end
|
171
|
+
|
172
|
+
#===イベントを停止・終了させる(テンプレートメソッド)
|
173
|
+
#ここに、イベント停止・終了イベントを実装する。更新はupdateメソッドに実装する
|
174
|
+
#_param_:: イベント発生に必要なパラメータ群。デフォルトはnil
|
175
|
+
#返却値:: 自分自身を返す
|
176
|
+
def stop(params = nil)
|
177
|
+
return self
|
178
|
+
end
|
179
|
+
|
180
|
+
#===イベント発生中問い合わせ(テンプレートメソッド)
|
181
|
+
#ここに、イベント発生中の問い合わせ処理を実装する。
|
182
|
+
#_param_:: あとで書く
|
183
|
+
#返却値:: イベント発生中の時はtrue
|
184
|
+
def executing?
|
185
|
+
return false
|
186
|
+
end
|
187
|
+
|
188
|
+
#===イベント終了後の後処理(テンプレートメソッド)
|
189
|
+
#ここに、イベント終了後の後処理を実装する。
|
190
|
+
def final
|
191
|
+
end
|
192
|
+
|
193
|
+
#===イベントに使用しているインスタンスを解放する(テンプレートメソッド)
|
194
|
+
#ここに、インスタンス解放処理を実装する。
|
195
|
+
def dispose
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
--
|
4
|
+
Miyako v2.0
|
5
|
+
Copyright (C) 2007-2008 Cyross Makoto
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License as published by the Free Software Foundation; either
|
10
|
+
version 2.1 of the License, or (at your option) any later version.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public
|
18
|
+
License along with this library; if not, write to the Free Software
|
19
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
++
|
21
|
+
=end
|
22
|
+
|
23
|
+
module Miyako
|
24
|
+
=begin rdoc
|
25
|
+
==基本スプライトモジュール
|
26
|
+
スプライトの基本メソッドで構成されるテンプレートモジュール
|
27
|
+
=end
|
28
|
+
module SpriteBase
|
29
|
+
#===スプライトインスタンスを取得するメソッドのテンプレート
|
30
|
+
#_data_:: あとで書く
|
31
|
+
#返却値:: 自分自身を返す
|
32
|
+
def to_sprite(data = nil)
|
33
|
+
return self
|
34
|
+
end
|
35
|
+
|
36
|
+
#===SpriteUnit構造体を取得するメソッドのテンプレート
|
37
|
+
#返却値:: nilを返す
|
38
|
+
def to_unit
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
|
42
|
+
#===領域の矩形を取得するメソッドのテンプレート
|
43
|
+
#返却値:: nilを返す
|
44
|
+
def rect
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
|
48
|
+
#===領域の最大矩形を取得するメソッドのテンプレート
|
49
|
+
#返却値:: nilを返す
|
50
|
+
def broad_rect
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
54
|
+
#===画像(Bitmapクラスのインスタンス)を取得するメソッドのテンプレート
|
55
|
+
#返却値:: nilを返す
|
56
|
+
def bitmap
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
|
60
|
+
#===画像内での描画開始位置(x座標)を取得するメソッドのテンプレート
|
61
|
+
#返却値:: 0を返す
|
62
|
+
def ox
|
63
|
+
return 0
|
64
|
+
end
|
65
|
+
|
66
|
+
#===画像内での描画開始位置(y座標)を取得するメソッドのテンプレート
|
67
|
+
#返却値:: 0を返す
|
68
|
+
def oy
|
69
|
+
return 0
|
70
|
+
end
|
71
|
+
|
72
|
+
#===画面への描画を指示するメソッドのテンプレート
|
73
|
+
#_block_:: 呼び出し時にブロック付き呼び出しが行われたときのブロック本体。呼び先に渡すことが出来る。ブロックがなければnilが入る
|
74
|
+
#返却値:: 自分自身を返す
|
75
|
+
def render(&block)
|
76
|
+
return self
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
=begin rdoc
|
81
|
+
==基本アニメーションモジュール
|
82
|
+
アニメーションの基本メソッドで構成されるテンプレートモジュール
|
83
|
+
=end
|
84
|
+
module Animation
|
85
|
+
#===アニメーションを開始するメソッドのテンプレート
|
86
|
+
#返却値:: 自分自身を返す
|
87
|
+
def start
|
88
|
+
return self
|
89
|
+
end
|
90
|
+
|
91
|
+
#===アニメーションを停止するメソッドのテンプレート
|
92
|
+
#返却値:: 自分自身を返す
|
93
|
+
def stop
|
94
|
+
return self
|
95
|
+
end
|
96
|
+
|
97
|
+
#===アニメーションパターンを先頭に戻すメソッドのテンプレート
|
98
|
+
#返却値:: 自分自身を返す
|
99
|
+
def reset
|
100
|
+
return self
|
101
|
+
end
|
102
|
+
|
103
|
+
#===アニメーションを更新するメソッドのテンプレート
|
104
|
+
#返却値:: falseを返す(アニメーションパターンが更新されたときにtrueを返す)
|
105
|
+
def update_animation
|
106
|
+
return false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|