1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
| #==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :cw # スプライトの横サイズ
attr_reader :ch # スプライトの縦サイズ
attr_reader :collision # 接触判定に使う四隅の座標(real_x,yに加算)
attr_reader :update_flag # 更新フラグ
attr_reader :lift # リフト属性
attr_reader :hit_skill # 接触スキル
attr_accessor :gravity # 重力
attr_accessor :undead # 無敵
attr_accessor :real_x # マップ X 座標 (実座標 * 256)
attr_accessor :real_y # マップ Y 座標 (実座標 * 256)
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias act_game_character_initialize initialize
def initialize
act_game_character_initialize
@lift = false
@gravity = 5
@undead = true
@vx = @vy = 0
@cw = @ch = 256
@collision = [0, 0, 256, 256]
@update_flag = true
@jump_flag = false
@jump_lock = 0
@touch_flag = -1
@ladder = false
@move_count = 0
@dead_count = 0
@dash_timer = 0
end
#--------------------------------------------------------------------------
# ● 移動中判定
#--------------------------------------------------------------------------
def moving?
return @move_count > 0
end
#--------------------------------------------------------------------------
# ● 左に移動
# turn_ok : その場での向き変更を許可
#--------------------------------------------------------------------------
def move_left(turn_ok = true)
turn_left
d = 2 ** @move_speed
@vx = 0 - d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 右に移動
# turn_ok : その場での向き変更を許可
#--------------------------------------------------------------------------
def move_right(turn_ok = true)
turn_right
d = 2 ** @move_speed
@vx = d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 上に移動
# turn_ok : その場での向き変更を許可
#--------------------------------------------------------------------------
def move_up(turn_ok = true)
@stop_count = 0
d = 2 ** @move_speed
@vy = 0 - d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 下に移動
# turn_ok : その場での向き変更を許可
#--------------------------------------------------------------------------
def move_down(turn_ok = true)
@stop_count = 0
d = 2 ** @move_speed
@vy = d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 左下に移動
#--------------------------------------------------------------------------
def move_lower_left
turn_left
d = 2 ** @move_speed
@vx = 0 - d
@vy = d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 右下に移動
#--------------------------------------------------------------------------
def move_lower_right
turn_right
d = 2 ** @move_speed
@vx = d
@vy = d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 左上に移動
#--------------------------------------------------------------------------
def move_upper_left
turn_left
d = 2 ** @move_speed
@vx = 0 - d
@vy = 0 - d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● 右上に移動
#--------------------------------------------------------------------------
def move_upper_right
turn_right
d = 2 ** @move_speed
@vx = d
@vy = 0 - d
@move_count = 256 / d
end
#--------------------------------------------------------------------------
# ● マップ通行可能判定
# mode : 0でx方向、1でy方向
#--------------------------------------------------------------------------
def map_passable?(mode)
left_x = @real_x + 32 >> 8 # 4 <<3
right_x = @real_x + 224 >> 8 # 28 << 3
up_y = @real_y + 16 >> 8 # 2 << 3
down_y = @real_y + 224 >> 8 # 28 << 3
if mode == 0 # X方向の判定
if @vx > 0
return false unless $game_map.map_pass?(right_x, up_y)
return false unless $game_map.map_pass?(right_x, down_y)
else
return false unless $game_map.map_pass?(left_x, up_y)
return false unless $game_map.map_pass?(left_x, down_y)
end
else # Y方向の判定
if @vy > 0
unless $game_map.map_pass?(left_x, down_y) and
$game_map.map_pass?(right_x, down_y)
@real_y = (down_y << - 225
return false
end
if $game_map.map_pass_through?(left_x, down_y) or
$game_map.map_pass_through?(right_x, down_y) and not @ladder
@real_y = (down_y << - 225
return false
end
else
unless $game_map.map_pass?(left_x, up_y) and
$game_map.map_pass?(right_x, up_y)
@real_y = up_y + 1 << 8
return false
end
end
end
return true
end
#--------------------------------------------------------------------------
# ● 通行可能判定
# mode : 0でx方向、1でy方向
#--------------------------------------------------------------------------
def passable?(mode = 0)
unless @through or debug_through? # すり抜け ON?
return false if collide_with_characters?(mode)
end
return false unless map_passable?(mode) # マップが通行不能?
return true # 通行可
end
#--------------------------------------------------------------------------
# ● 接触判定
# real_x : X 座標
# real_y : Y 座標
#--------------------------------------------------------------------------
def hit_pos?(real_x, real_y)
return (@real_x + 32 < real_x + 224 and real_x + 32 < @real_x + 224 and
@real_y < real_y + (@lift ? 232 : 224) and real_y < @real_y + 224)
end
#--------------------------------------------------------------------------
# ● キャラクター衝突判定
# x : X 座標
# y : Y 座標
# プレイヤーと乗り物を含め、通常キャラの衝突を検出する。
#--------------------------------------------------------------------------
def collide_with_characters?(mode)
for event in $game_map.events.values # 全イベントを検索
next if event.through # すり抜け OFF?
next if event.id == self.id # 自分自身を無視
if hit_pos?(event.real_x, event.real_y)
if @lift # リフト属性がある場合
if mode == 0
collide_with_characters?(mode)
event.real_x += @vx
event.real_x -= @vx if event.collide_with_characters?(mode)
else
event.real_y += @vy
event.real_y -= @vy if event.collide_with_characters?(mode)
end
else
@real_y = event.real_y + (@vy > 0 ? -225 : 224) if mode == 1
@touch_flag = event.id
return true
end
end
end
if @priority_type == 1 # 自分が通常キャラ
unless self.is_a?(Game_Player)
if hit_pos?($game_player.real_x, $game_player.real_y) # プレイヤーと接触
if @lift # リフト属性がある場合
if mode == 0
$game_player.real_x += @vx
if $game_player.collide_with_characters?(mode)
$game_player.real_x -= @vx
else
$game_player.update_scroll($game_player.real_x - @vx, $game_player.real_y)
end
else
$game_player.real_y += @vy
if $game_player.collide_with_characters?(mode)
$game_player.real_y -= @vy
else
$game_player.update_scroll($game_player.real_x, $game_player.real_y - @vy)
end
end
else
@real_y = $game_player.real_y + (@vy > 0 ? -225 : 224) if mode == 1
@touch_flag = 0
return true
end
end
end
end
return false
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
if dash?
@move_count = 1
@dash_timer -= 1
end
update_x
update_y
if moving? # 移動中
@move_count -= 1
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
else # 停止中
if @step_anime
@anime_count += 1
elsif @pattern != @original_pattern
@anime_count += 1.5
end
@stop_count += 1 unless @locked
end
if @wait_count > 0 # ウェイト中
@wait_count -= 1
elsif @move_route_forcing # 移動ルート強制中
move_type_custom
elsif not @locked # ロック中以外
update_self_movement
end
update_animation
end
#--------------------------------------------------------------------------
# ● x座標の更新
#--------------------------------------------------------------------------
def update_x
unless @jump_flag or moving?
@vx = 0
return
end
last_x = @real_x
@real_x += @vx
@x = @real_x >> 8
@touch_flag = -1
unless passable?(0)
@real_x = last_x
@x = @real_x >> 8
@vx = 0
check_event_trigger_touch() # 接触起動判定
end
end
#--------------------------------------------------------------------------
# ● y座標の更新
#--------------------------------------------------------------------------
def update_y
if @gravity > 0
@vy = [@vy + @gravity, 64].min
elsif !moving?
@vy = 0
return
end
@real_y += @vy
@y = @real_y >> 8
@touch_flag = -1
unless passable?(1)
@y = @real_y >> 8
if @vy > 0
if @vy > 20
$game_temp.anime_heap.push([@real_x + 128, @real_y + 256, ACT::ANIME_GROUND])
end
@jump_flag = false
get_off if @ladder
end
@vy = 0
check_event_trigger_touch() # 接触起動判定
end
end
#--------------------------------------------------------------------------
# ● プレイヤーの方を向く
#--------------------------------------------------------------------------
def turn_toward_player
@real_x < $game_player.real_x ? turn_right : turn_left
end
#--------------------------------------------------------------------------
# ● ランダムに移動
#--------------------------------------------------------------------------
def move_random
case rand(@gravity == 0 ? 4 : 2)
when 0; move_left(false)
when 1; move_right(false)
when 2; move_up(false)
when 3; move_down(false)
end
end
#--------------------------------------------------------------------------
# ● プレイヤーに近づく
#--------------------------------------------------------------------------
def move_toward_player
distance_x_from_player > 0 ? move_left : move_right
end
#--------------------------------------------------------------------------
# ● プレイヤーから遠ざかる
#--------------------------------------------------------------------------
def move_away_from_player
distance_x_from_player > 0 ? move_right : move_left
end
#--------------------------------------------------------------------------
# ● ジャンプ
#--------------------------------------------------------------------------
def jump(vy = -80, vx = 0)
return if @jump_flag
$game_temp.anime_heap.push([@real_x + 128, @real_y + 256, ACT::ANIME_JUMP])
@vy = vy
@jump_flag = true
@stop_count = 0
end
#--------------------------------------------------------------------------
# ● 接触イベントの起動判定
#--------------------------------------------------------------------------
def check_event_trigger_touch()
end
#--------------------------------------------------------------------------
# ○ nウェイショット
#--------------------------------------------------------------------------
def nway_shot(n, space, angle, speed, aim, timer, gravity, name,
skill_id, throw = false)
return unless @update_flag # 画面外なら発射しない
x = @real_x + 128
y = @real_y + 128
d = angle
d += $game_player.get_angle(x, y) if aim
d = d - ( space * ( n - 1 ) / 2 )
for i in 0...n
$game_map.add_bullet(x, y, (Math.cos(d) * speed).to_i,
(Math.sin(d) * speed).to_i, timer, gravity, name, battler,
skill_id, d, throw)
d += space
end
end
#--------------------------------------------------------------------------
# ○ 全方位ショット
#--------------------------------------------------------------------------
def nall_shot(n, angle, speed, aim, timer, gravity, name,
skill_id, throw = false)
return unless @update_flag # 画面外なら発射しない
x = @real_x + 128
y = @real_y + 128
a = angle
a += $game_player.get_angle(x, y) if aim
d = Math::PI * 2 / n
for i in 0...n
$game_map.add_bullet(x, y, (Math.cos(a) * speed).to_i,
(Math.sin(a) * speed).to_i, timer, gravity, name, battler,
skill_id, a, throw)
a += d
end
end
end
|