Class: Game_CharacterBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rgss3_default_scripts/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

#initializeGame_CharacterBase


  • Object Initialization




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

def initialize
  init_public_members
  init_private_members
end

Instance Attribute Details

#animation_idObject

animation ID



32
33
34
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 32

def animation_id
  @animation_id
end

#balloon_idObject

balloon icon ID



33
34
35
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 33

def balloon_id
  @balloon_id
end

#blend_typeObject (readonly)

blending method



26
27
28
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 26

def blend_type
  @blend_type
end

#bush_depthObject (readonly)

bush depth



31
32
33
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 31

def bush_depth
  @bush_depth
end

#character_indexObject (readonly)

character graphic index



19
20
21
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 19

def character_index
  @character_index
end

#character_nameObject (readonly)

character graphic filename



18
19
20
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 18

def character_name
  @character_name
end

#directionObject (readonly)

direction



27
28
29
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 27

def direction
  @direction
end

#direction_fixObject (readonly)

direction fix



24
25
26
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 24

def direction_fix
  @direction_fix
end

#idObject (readonly)


  • Public Instance Variables




12
13
14
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 12

def id
  @id
end

#move_frequencyObject (readonly)

movement frequency



21
22
23
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 21

def move_frequency
  @move_frequency
end

#move_speedObject (readonly)

movement speed



20
21
22
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 20

def move_speed
  @move_speed
end

#opacityObject (readonly)

opacity level



25
26
27
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 25

def opacity
  @opacity
end

#patternObject (readonly)

pattern



28
29
30
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 28

def pattern
  @pattern
end

#priority_typeObject (readonly)

priority type



29
30
31
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 29

def priority_type
  @priority_type
end

#real_xObject (readonly)

map X coordinate (real)



15
16
17
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 15

def real_x
  @real_x
end

#real_yObject (readonly)

map Y coordinate (real)



16
17
18
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 16

def real_y
  @real_y
end

#step_animeObject (readonly)

stepping animation



23
24
25
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 23

def step_anime
  @step_anime
end

#throughObject (readonly)

pass-through



30
31
32
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 30

def through
  @through
end

#tile_idObject (readonly)

tile ID (invalid if 0)



17
18
19
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 17

def tile_id
  @tile_id
end

#transparentObject

transparency flag



34
35
36
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 34

def transparent
  @transparent
end

#walk_animeObject (readonly)

walking animation



22
23
24
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 22

def walk_anime
  @walk_anime
end

#xObject (readonly)

map X coordinate (logical)



13
14
15
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 13

def x
  @x
end

#yObject (readonly)

map Y coordinate (logical)



14
15
16
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 14

def y
  @y
end

Instance Method Details

#bush?Boolean


  • Determine if Bush


Returns:

  • (Boolean)


359
360
361
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 359

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

#check_event_trigger_touch(x, y) ⇒ Object


  • Determine if Touch Event is Triggered




404
405
406
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 404

def check_event_trigger_touch(x, y)
  return false
end

#check_event_trigger_touch_frontObject


  • Determine Triggering of Frontal Touch Event




396
397
398
399
400
# File 'lib/rgss3_default_scripts/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

#collide_with_characters?(x, y) ⇒ Boolean


  • Detect Collision with Character


Returns:

  • (Boolean)


199
200
201
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 199

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

#collide_with_events?(x, y) ⇒ Boolean


  • Detect Collision with Event


Returns:

  • (Boolean)


205
206
207
208
209
# File 'lib/rgss3_default_scripts/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

#collide_with_vehicles?(x, y) ⇒ Boolean


  • Detect Collision with Vehicle


Returns:

  • (Boolean)


213
214
215
# File 'lib/rgss3_default_scripts/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

#dash?Boolean


  • Determine if Dashing


Returns:

  • (Boolean)


141
142
143
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 141

def dash?
  return false
end

#debug_through?Boolean


  • Determine if Debug Pass-Through State


Returns:

  • (Boolean)


147
148
149
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 147

def debug_through?
  return false
end

#diagonal_passable?(x, y, horz, vert) ⇒ Boolean


  • Determine Diagonal Passability

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

Returns:

  • (Boolean)


183
184
185
186
187
188
# File 'lib/rgss3_default_scripts/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

#distance_per_frameObject


  • Calculate Move Distance per Frame




135
136
137
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 135

def distance_per_frame
  2 ** real_move_speed / 256.0
end

#increase_stepsObject


  • Increase Steps




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

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

#init_private_membersObject


  • Initialize Private Member Variables




73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rgss3_default_scripts/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

#init_public_membersObject


  • 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 'lib/rgss3_default_scripts/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

#jump_heightObject


  • Calculate Jump Height




117
118
119
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 117

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

#jumping?Boolean


  • Determine if Jumping


Returns:

  • (Boolean)


111
112
113
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 111

def jumping?
  @jump_count > 0
end

#ladder?Boolean


  • Determine if Ladder


Returns:

  • (Boolean)


343
344
345
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 343

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

#map_passable?(x, y, d) ⇒ Boolean


  • Determine if Map is Passable

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

Returns:

  • (Boolean)


193
194
195
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 193

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

#move_diagonal(horz, vert) ⇒ Object


  • 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 'lib/rgss3_default_scripts/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

#move_straight(d, turn_ok = true) ⇒ Object


  • 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 'lib/rgss3_default_scripts/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

#moveto(x, y) ⇒ Object


  • Move to Designated Position




219
220
221
222
223
224
225
226
227
# File 'lib/rgss3_default_scripts/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

#moving?Boolean


  • Determine if Moving


Returns:

  • (Boolean)


105
106
107
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 105

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

#normal_priority?Boolean


  • Determine if [Same as Characters] Priority


Returns:

  • (Boolean)


99
100
101
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 99

def normal_priority?
  @priority_type == 1
end

#object_character?Boolean


  • Determine Object Character


Returns:

  • (Boolean)


245
246
247
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 245

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

#passable?(x, y, d) ⇒ Boolean


  • Determine if Passable

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

Returns:

  • (Boolean)


168
169
170
171
172
173
174
175
176
177
# File 'lib/rgss3_default_scripts/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

#pos?(x, y) ⇒ Boolean


  • Determine Coordinate Match


Returns:

  • (Boolean)


87
88
89
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 87

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

#pos_nt?(x, y) ⇒ Boolean


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


Returns:

  • (Boolean)


93
94
95
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 93

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

#real_move_speedObject


  • Get Move Speed (Account for Dash)




129
130
131
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 129

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

#region_idObject


  • Get Region ID




371
372
373
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 371

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

#reverse_dir(d) ⇒ Object


  • Get Opposite Direction

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



161
162
163
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 161

def reverse_dir(d)
  return 10 - d
end

#screen_xObject


  • Get Screen X-Coordinates




257
258
259
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 257

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

#screen_yObject


  • Get Screen Y-Coordinates




263
264
265
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 263

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

#screen_zObject


  • Get Screen Z-Coordinates




269
270
271
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 269

def screen_z
  @priority_type * 100
end

#set_direction(d) ⇒ Object


  • Change Direction to Designated Direction

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



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

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

#set_graphic(character_name, character_index) ⇒ Object


  • Change Graphics

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



387
388
389
390
391
392
# File 'lib/rgss3_default_scripts/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

#shift_yObject


  • Get Number of Pixels to Shift Up from Tile Position




251
252
253
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 251

def shift_y
  object_character? ? 0 : 4
end

#stopping?Boolean


  • Determine if Stopping


Returns:

  • (Boolean)


123
124
125
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 123

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

#straightenObject


  • Straighten Position




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

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

#terrain_tagObject


  • Get Terrain Tag




365
366
367
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 365

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

#tile?Boolean


  • Determine Tile


Returns:

  • (Boolean)


239
240
241
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 239

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

#updateObject


  • Frame Update




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

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

#update_animationObject


  • Update Walking/Stepping Animation




313
314
315
316
317
318
319
# File 'lib/rgss3_default_scripts/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

#update_anime_countObject


  • Update Animation Count




323
324
325
326
327
328
329
# File 'lib/rgss3_default_scripts/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

#update_anime_patternObject


  • Update Animation Pattern




333
334
335
336
337
338
339
# File 'lib/rgss3_default_scripts/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

#update_bush_depthObject


  • Update Bush Depth




349
350
351
352
353
354
355
# File 'lib/rgss3_default_scripts/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

#update_jumpObject


  • Update While Jumping




284
285
286
287
288
289
290
291
292
293
# File 'lib/rgss3_default_scripts/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

#update_moveObject


  • Update While Moving




297
298
299
300
301
302
303
# File 'lib/rgss3_default_scripts/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

#update_stopObject


  • Update While Stopped




307
308
309
# File 'lib/rgss3_default_scripts/Game_CharacterBase.rb', line 307

def update_stop
  @stop_count += 1 unless @locked
end