Class: Game_CharacterBase

Inherits:
Object
  • Object
show all
Defined in:
Game_CharacterBase.rb

Overview

** Game_CharacterBase


This base class handles characters. It retains basic information, such as

coordinates and graphics, shared by all characters.

Direct Known Subclasses

Game_Character

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Game_CharacterBase) initialize


  • Object Initialization




38
39
40
41
# File 'Game_CharacterBase.rb', line 38

def initialize
  init_public_members
  init_private_members
end

Instance Attribute Details

- (Object) animation_id

animation ID



32
33
34
# File 'Game_CharacterBase.rb', line 32

def animation_id
  @animation_id
end

- (Object) balloon_id

balloon icon ID



33
34
35
# File 'Game_CharacterBase.rb', line 33

def balloon_id
  @balloon_id
end

- (Object) blend_type (readonly)

blending method



26
27
28
# File 'Game_CharacterBase.rb', line 26

def blend_type
  @blend_type
end

- (Object) bush_depth (readonly)

bush depth



31
32
33
# File 'Game_CharacterBase.rb', line 31

def bush_depth
  @bush_depth
end

- (Object) character_index (readonly)

character graphic index



19
20
21
# File 'Game_CharacterBase.rb', line 19

def character_index
  @character_index
end

- (Object) character_name (readonly)

character graphic filename



18
19
20
# File 'Game_CharacterBase.rb', line 18

def character_name
  @character_name
end

- (Object) direction (readonly)

direction



27
28
29
# File 'Game_CharacterBase.rb', line 27

def direction
  @direction
end

- (Object) direction_fix (readonly)

direction fix



24
25
26
# File 'Game_CharacterBase.rb', line 24

def direction_fix
  @direction_fix
end

- (Object) id (readonly)


  • Public Instance Variables




12
13
14
# File 'Game_CharacterBase.rb', line 12

def id
  @id
end

- (Object) move_frequency (readonly)

movement frequency



21
22
23
# File 'Game_CharacterBase.rb', line 21

def move_frequency
  @move_frequency
end

- (Object) move_speed (readonly)

movement speed



20
21
22
# File 'Game_CharacterBase.rb', line 20

def move_speed
  @move_speed
end

- (Object) opacity (readonly)

opacity level



25
26
27
# File 'Game_CharacterBase.rb', line 25

def opacity
  @opacity
end

- (Object) pattern (readonly)

pattern



28
29
30
# File 'Game_CharacterBase.rb', line 28

def pattern
  @pattern
end

- (Object) priority_type (readonly)

priority type



29
30
31
# File 'Game_CharacterBase.rb', line 29

def priority_type
  @priority_type
end

- (Object) real_x (readonly)

map X coordinate (real)



15
16
17
# File 'Game_CharacterBase.rb', line 15

def real_x
  @real_x
end

- (Object) real_y (readonly)

map Y coordinate (real)



16
17
18
# File 'Game_CharacterBase.rb', line 16

def real_y
  @real_y
end

- (Object) step_anime (readonly)

stepping animation



23
24
25
# File 'Game_CharacterBase.rb', line 23

def step_anime
  @step_anime
end

- (Object) through (readonly)

pass-through



30
31
32
# File 'Game_CharacterBase.rb', line 30

def through
  @through
end

- (Object) tile_id (readonly)

tile ID (invalid if 0)



17
18
19
# File 'Game_CharacterBase.rb', line 17

def tile_id
  @tile_id
end

- (Object) transparent

transparency flag



34
35
36
# File 'Game_CharacterBase.rb', line 34

def transparent
  @transparent
end

- (Object) walk_anime (readonly)

walking animation



22
23
24
# File 'Game_CharacterBase.rb', line 22

def walk_anime
  @walk_anime
end

- (Object) x (readonly)

map X coordinate (logical)



13
14
15
# File 'Game_CharacterBase.rb', line 13

def x
  @x
end

- (Object) y (readonly)

map Y coordinate (logical)



14
15
16
# File 'Game_CharacterBase.rb', line 14

def y
  @y
end

Instance Method Details

- (Boolean) bush?


  • Determine if Bush


Returns:

  • (Boolean)


359
360
361
# File 'Game_CharacterBase.rb', line 359

def bush?
  $game_map.bush?(@x, @y)
end

- (Object) check_event_trigger_touch(x, y)


  • Determine if Touch Event is Triggered




404
405
406
# File 'Game_CharacterBase.rb', line 404

def check_event_trigger_touch(x, y)
  return false
end

- (Object) check_event_trigger_touch_front


  • Determine Triggering of Frontal Touch Event




396
397
398
399
400
# File 'Game_CharacterBase.rb', line 396

def check_event_trigger_touch_front
  x2 = $game_map.round_x_with_direction(@x, @direction)
  y2 = $game_map.round_y_with_direction(@y, @direction)
  check_event_trigger_touch(x2, y2)
end

- (Boolean) collide_with_characters?(x, y)


  • Detect Collision with Character


Returns:

  • (Boolean)


199
200
201
# File 'Game_CharacterBase.rb', line 199

def collide_with_characters?(x, y)
  collide_with_events?(x, y) || collide_with_vehicles?(x, y)
end

- (Boolean) collide_with_events?(x, y)


  • Detect Collision with Event


Returns:

  • (Boolean)


205
206
207
208
209
# File 'Game_CharacterBase.rb', line 205

def collide_with_events?(x, y)
  $game_map.events_xy_nt(x, y).any? do |event|
    event.normal_priority? || self.is_a?(Game_Event)
  end
end

- (Boolean) collide_with_vehicles?(x, y)


  • Detect Collision with Vehicle


Returns:

  • (Boolean)


213
214
215
# File 'Game_CharacterBase.rb', line 213

def collide_with_vehicles?(x, y)
  $game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y)
end

- (Boolean) dash?


  • Determine if Dashing


Returns:

  • (Boolean)


141
142
143
# File 'Game_CharacterBase.rb', line 141

def dash?
  return false
end

- (Boolean) debug_through?


  • Determine if Debug Pass-Through State


Returns:

  • (Boolean)


147
148
149
# File 'Game_CharacterBase.rb', line 147

def debug_through?
  return false
end

- (Boolean) diagonal_passable?(x, y, horz, vert)


  • Determine Diagonal Passability

    horz : Horizontal (4 or 6)
    vert : Vertical (2 or 8)

Returns:

  • (Boolean)


183
184
185
186
187
188
# File 'Game_CharacterBase.rb', line 183

def diagonal_passable?(x, y, horz, vert)
  x2 = $game_map.round_x_with_direction(x, horz)
  y2 = $game_map.round_y_with_direction(y, vert)
  (passable?(x, y, vert) && passable?(x, y2, horz)) ||
  (passable?(x, y, horz) && passable?(x2, y, vert))
end

- (Object) distance_per_frame


  • Calculate Move Distance per Frame




135
136
137
# File 'Game_CharacterBase.rb', line 135

def distance_per_frame
  2 ** real_move_speed / 256.0
end

- (Object) increase_steps


  • Increase Steps




377
378
379
380
381
# File 'Game_CharacterBase.rb', line 377

def increase_steps
  set_direction(8) if ladder?
  @stop_count = 0
  update_bush_depth
end

- (Object) init_private_members


  • Initialize Private Member Variables




73
74
75
76
77
78
79
80
81
82
83
# File 'Game_CharacterBase.rb', line 73

def init_private_members
  @original_direction = 2               # Original direction
  @original_pattern = 1                 # Original pattern
  @anime_count = 0                      # Animation count
  @stop_count = 0                       # Stop count
  @jump_count = 0                       # Jump count
  @jump_peak = 0                        # Jump peak count
  @locked = false                       # Locked flag
  @prelock_direction = 0                # Direction before lock
  @move_succeed = true                  # Move success flag
end

- (Object) init_public_members


  • Initialize Public Member Variables




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
# File 'Game_CharacterBase.rb', line 45

def init_public_members
  @id = 0
  @x = 0
  @y = 0
  @real_x = 0
  @real_y = 0
  @tile_id = 0
  @character_name = ""
  @character_index = 0
  @move_speed = 4
  @move_frequency = 6
  @walk_anime = true
  @step_anime = false
  @direction_fix = false
  @opacity = 255
  @blend_type = 0
  @direction = 2
  @pattern = 1
  @priority_type = 1
  @through = false
  @bush_depth = 0
  @animation_id = 0
  @balloon_id = 0
  @transparent = false
end

- (Object) jump_height


  • Calculate Jump Height




117
118
119
# File 'Game_CharacterBase.rb', line 117

def jump_height
  (@jump_peak * @jump_peak - (@jump_count - @jump_peak).abs ** 2) / 2
end

- (Boolean) jumping?


  • Determine if Jumping


Returns:

  • (Boolean)


111
112
113
# File 'Game_CharacterBase.rb', line 111

def jumping?
  @jump_count > 0
end

- (Boolean) ladder?


  • Determine if Ladder


Returns:

  • (Boolean)


343
344
345
# File 'Game_CharacterBase.rb', line 343

def ladder?
  $game_map.ladder?(@x, @y)
end

- (Boolean) map_passable?(x, y, d)


  • Determine if Map is Passable

    d : Direction (2,4,6,8)

Returns:

  • (Boolean)


193
194
195
# File 'Game_CharacterBase.rb', line 193

def map_passable?(x, y, d)
  $game_map.passable?(x, y, d)
end

- (Object) move_diagonal(horz, vert)


  • Move Diagonally

    horz:  Horizontal (4 or 6)
    vert:  Vertical (2 or 8)



431
432
433
434
435
436
437
438
439
440
441
442
# File 'Game_CharacterBase.rb', line 431

def move_diagonal(horz, vert)
  @move_succeed = diagonal_passable?(x, y, horz, vert)
  if @move_succeed
    @x = $game_map.round_x_with_direction(@x, horz)
    @y = $game_map.round_y_with_direction(@y, vert)
    @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
    @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
    increase_steps
  end
  set_direction(horz) if @direction == reverse_dir(horz)
  set_direction(vert) if @direction == reverse_dir(vert)
end

- (Object) move_straight(d, turn_ok = true)


  • Move Straight

    d:        Direction (2,4,6,8)
    turn_ok : Allows change of direction on the spot



412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'Game_CharacterBase.rb', line 412

def move_straight(d, turn_ok = true)
  @move_succeed = passable?(@x, @y, d)
  if @move_succeed
    set_direction(d)
    @x = $game_map.round_x_with_direction(@x, d)
    @y = $game_map.round_y_with_direction(@y, d)
    @real_x = $game_map.x_with_direction(@x, reverse_dir(d))
    @real_y = $game_map.y_with_direction(@y, reverse_dir(d))
    increase_steps
  elsif turn_ok
    set_direction(d)
    check_event_trigger_touch_front
  end
end

- (Object) moveto(x, y)


  • Move to Designated Position




219
220
221
222
223
224
225
226
227
# File 'Game_CharacterBase.rb', line 219

def moveto(x, y)
  @x = x % $game_map.width
  @y = y % $game_map.height
  @real_x = @x
  @real_y = @y
  @prelock_direction = 0
  straighten
  update_bush_depth
end

- (Boolean) moving?


  • Determine if Moving


Returns:

  • (Boolean)


105
106
107
# File 'Game_CharacterBase.rb', line 105

def moving?
  @real_x != @x || @real_y != @y
end

- (Boolean) normal_priority?


  • Determine if [Same as Characters] Priority


Returns:

  • (Boolean)


99
100
101
# File 'Game_CharacterBase.rb', line 99

def normal_priority?
  @priority_type == 1
end

- (Boolean) object_character?


  • Determine Object Character


Returns:

  • (Boolean)


245
246
247
# File 'Game_CharacterBase.rb', line 245

def object_character?
  @tile_id > 0 || @character_name[0, 1] == '!'
end

- (Boolean) passable?(x, y, d)


  • Determine if Passable

    d : Direction (2,4,6,8)

Returns:

  • (Boolean)


168
169
170
171
172
173
174
175
176
177
# File 'Game_CharacterBase.rb', line 168

def passable?(x, y, d)
  x2 = $game_map.round_x_with_direction(x, d)
  y2 = $game_map.round_y_with_direction(y, d)
  return false unless $game_map.valid?(x2, y2)
  return true if @through || debug_through?
  return false unless map_passable?(x, y, d)
  return false unless map_passable?(x2, y2, reverse_dir(d))
  return false if collide_with_characters?(x2, y2)
  return true
end

- (Boolean) pos?(x, y)


  • Determine Coordinate Match


Returns:

  • (Boolean)


87
88
89
# File 'Game_CharacterBase.rb', line 87

def pos?(x, y)
  @x == x && @y == y
end

- (Boolean) pos_nt?(x, y)


  • Determine if Coordinates Match and Pass-Through Is Off (nt = No Through)


Returns:

  • (Boolean)


93
94
95
# File 'Game_CharacterBase.rb', line 93

def pos_nt?(x, y)
  pos?(x, y) && !@through
end

- (Object) real_move_speed


  • Get Move Speed (Account for Dash)




129
130
131
# File 'Game_CharacterBase.rb', line 129

def real_move_speed
  @move_speed + (dash? ? 1 : 0)
end

- (Object) region_id


  • Get Region ID




371
372
373
# File 'Game_CharacterBase.rb', line 371

def region_id
  $game_map.region_id(@x, @y)
end

- (Object) reverse_dir(d)


  • Get Opposite Direction

    d : Direction (2,4,6,8)



161
162
163
# File 'Game_CharacterBase.rb', line 161

def reverse_dir(d)
  return 10 - d
end

- (Object) screen_x


  • Get Screen X-Coordinates




257
258
259
# File 'Game_CharacterBase.rb', line 257

def screen_x
  $game_map.adjust_x(@real_x) * 32 + 16
end

- (Object) screen_y


  • Get Screen Y-Coordinates




263
264
265
# File 'Game_CharacterBase.rb', line 263

def screen_y
  $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height
end

- (Object) screen_z


  • Get Screen Z-Coordinates




269
270
271
# File 'Game_CharacterBase.rb', line 269

def screen_z
  @priority_type * 100
end

- (Object) set_direction(d)


  • Change Direction to Designated Direction

    d : Direction (2,4,6,8)



232
233
234
235
# File 'Game_CharacterBase.rb', line 232

def set_direction(d)
  @direction = d if !@direction_fix && d != 0
  @stop_count = 0
end

- (Object) set_graphic(character_name, character_index)


  • Change Graphics

    character_name  : new character graphic filename
    character_index : new character graphic index



387
388
389
390
391
392
# File 'Game_CharacterBase.rb', line 387

def set_graphic(character_name, character_index)
  @tile_id = 0
  @character_name = character_name
  @character_index = character_index
  @original_pattern = 1
end

- (Object) shift_y


  • Get Number of Pixels to Shift Up from Tile Position




251
252
253
# File 'Game_CharacterBase.rb', line 251

def shift_y
  object_character? ? 0 : 4
end

- (Boolean) stopping?


  • Determine if Stopping


Returns:

  • (Boolean)


123
124
125
# File 'Game_CharacterBase.rb', line 123

def stopping?
  !moving? && !jumping?
end

- (Object) straighten


  • Straighten Position




153
154
155
156
# File 'Game_CharacterBase.rb', line 153

def straighten
  @pattern = 1 if @walk_anime || @step_anime
  @anime_count = 0
end

- (Object) terrain_tag


  • Get Terrain Tag




365
366
367
# File 'Game_CharacterBase.rb', line 365

def terrain_tag
  $game_map.terrain_tag(@x, @y)
end

- (Boolean) tile?


  • Determine Tile


Returns:

  • (Boolean)


239
240
241
# File 'Game_CharacterBase.rb', line 239

def tile?
  @tile_id > 0 && @priority_type == 0
end

- (Object) update


  • Frame Update




275
276
277
278
279
280
# File 'Game_CharacterBase.rb', line 275

def update
  update_animation
  return update_jump if jumping?
  return update_move if moving?
  return update_stop
end

- (Object) update_animation


  • Update Walking/Stepping Animation




313
314
315
316
317
318
319
# File 'Game_CharacterBase.rb', line 313

def update_animation
  update_anime_count
  if @anime_count > 18 - real_move_speed * 2
    update_anime_pattern
    @anime_count = 0
  end
end

- (Object) update_anime_count


  • Update Animation Count




323
324
325
326
327
328
329
# File 'Game_CharacterBase.rb', line 323

def update_anime_count
  if moving? && @walk_anime
    @anime_count += 1.5
  elsif @step_anime || @pattern != @original_pattern
    @anime_count += 1
  end
end

- (Object) update_anime_pattern


  • Update Animation Pattern




333
334
335
336
337
338
339
# File 'Game_CharacterBase.rb', line 333

def update_anime_pattern
  if !@step_anime && @stop_count > 0
    @pattern = @original_pattern
  else
    @pattern = (@pattern + 1) % 4
  end
end

- (Object) update_bush_depth


  • Update Bush Depth




349
350
351
352
353
354
355
# File 'Game_CharacterBase.rb', line 349

def update_bush_depth
  if normal_priority? && !object_character? && bush? && !jumping?
    @bush_depth = 8 unless moving?
  else
    @bush_depth = 0
  end
end

- (Object) update_jump


  • Update While Jumping




284
285
286
287
288
289
290
291
292
293
# File 'Game_CharacterBase.rb', line 284

def update_jump
  @jump_count -= 1
  @real_x = (@real_x * @jump_count + @x) / (@jump_count + 1.0)
  @real_y = (@real_y * @jump_count + @y) / (@jump_count + 1.0)
  update_bush_depth
  if @jump_count == 0
    @real_x = @x = $game_map.round_x(@x)
    @real_y = @y = $game_map.round_y(@y)
  end
end

- (Object) update_move


  • Update While Moving




297
298
299
300
301
302
303
# File 'Game_CharacterBase.rb', line 297

def update_move
  @real_x = [@real_x - distance_per_frame, @x].max if @x < @real_x
  @real_x = [@real_x + distance_per_frame, @x].min if @x > @real_x
  @real_y = [@real_y - distance_per_frame, @y].max if @y < @real_y
  @real_y = [@real_y + distance_per_frame, @y].min if @y > @real_y
  update_bush_depth unless moving?
end

- (Object) update_stop


  • Update While Stopped




307
308
309
# File 'Game_CharacterBase.rb', line 307

def update_stop
  @stop_count += 1 unless @locked
end