Class: Game_Character

Inherits:
Game_CharacterBase show all
Defined in:
Game_Character.rb

Overview

** Game_Character


A character class with mainly movement route and other such processing

added. It is used as a super class of Game_Player, Game_Follower, GameVehicle, and Game_Event.

Direct Known Subclasses

Game_Event, Game_Follower, Game_Player, Game_Vehicle

Constant Summary

ROUTE_END =

  • Constants


0
ROUTE_MOVE_DOWN =

End of Move Route

1
ROUTE_MOVE_LEFT =

Move Down

2
ROUTE_MOVE_RIGHT =

Move Left

3
ROUTE_MOVE_UP =

Move Right

4
ROUTE_MOVE_LOWER_L =

Move Up

5
ROUTE_MOVE_LOWER_R =

Move Lower Left

6
ROUTE_MOVE_UPPER_L =

Move Lower Right

7
ROUTE_MOVE_UPPER_R =

Move Upper Left

8
ROUTE_MOVE_RANDOM =

Move Upper Right

9
ROUTE_MOVE_TOWARD =

Move at Random

10
ROUTE_MOVE_AWAY =

Move toward Player

11
ROUTE_MOVE_FORWARD =

Move away from Player

12
ROUTE_MOVE_BACKWARD =

1 Step Forward

13
ROUTE_JUMP =

1 Step Backward

14
ROUTE_WAIT =

Jump

15
ROUTE_TURN_DOWN =

Wait

16
ROUTE_TURN_LEFT =

Turn Down

17
ROUTE_TURN_RIGHT =

Turn Left

18
ROUTE_TURN_UP =

Turn Right

19
ROUTE_TURN_90D_R =

Turn Up

20
ROUTE_TURN_90D_L =

Turn 90 Degrees Right

21
ROUTE_TURN_180D =

Turn 90 Degrees Left

22
ROUTE_TURN_90D_R_L =

Turn 180 Degrees

23
ROUTE_TURN_RANDOM =

Turn 90 Degrees Right/Left

24
ROUTE_TURN_TOWARD =

Turn at Random

25
ROUTE_TURN_AWAY =

Turn toward player

26
ROUTE_SWITCH_ON =

Turn away from Player

27
ROUTE_SWITCH_OFF =

Switch ON

28
ROUTE_CHANGE_SPEED =

Switch OFF

29
ROUTE_CHANGE_FREQ =

Change Speed

30
ROUTE_WALK_ANIME_ON =

Change Frequency

31
ROUTE_WALK_ANIME_OFF =

Walking Animation ON

32
ROUTE_STEP_ANIME_ON =

Walking Animation OFF

33
ROUTE_STEP_ANIME_OFF =

Stepping Animation ON

34
ROUTE_DIR_FIX_ON =

Stepping Animation OFF

35
ROUTE_DIR_FIX_OFF =

Direction Fix ON

36
ROUTE_THROUGH_ON =

Direction Fix OFF

37
ROUTE_THROUGH_OFF =

Pass-Through ON

38
ROUTE_TRANSPARENT_ON =

Pass-Through OFF

39
ROUTE_TRANSPARENT_OFF =

Transparent ON

40
ROUTE_CHANGE_GRAPHIC =

Transparent OFF

41
ROUTE_CHANGE_OPACITY =

Change Graphic

42
ROUTE_CHANGE_BLENDING =

Change Opacity

43
ROUTE_PLAY_SE =

Change Blending

44
ROUTE_SCRIPT =

Play SE

45

Instance Attribute Summary (collapse)

Attributes inherited from Game_CharacterBase

#animation_id, #balloon_id, #blend_type, #bush_depth, #character_index, #character_name, #direction, #direction_fix, #id, #move_frequency, #move_speed, #opacity, #pattern, #priority_type, #real_x, #real_y, #step_anime, #through, #tile_id, #transparent, #walk_anime, #x, #y

Instance Method Summary (collapse)

Methods inherited from Game_CharacterBase

#bush?, #check_event_trigger_touch, #check_event_trigger_touch_front, #collide_with_characters?, #collide_with_events?, #collide_with_vehicles?, #dash?, #debug_through?, #diagonal_passable?, #distance_per_frame, #increase_steps, #initialize, #jump_height, #jumping?, #ladder?, #map_passable?, #move_diagonal, #move_straight, #moveto, #moving?, #normal_priority?, #object_character?, #passable?, #pos?, #pos_nt?, #real_move_speed, #region_id, #reverse_dir, #screen_x, #screen_y, #screen_z, #set_direction, #set_graphic, #shift_y, #stopping?, #straighten, #terrain_tag, #tile?, #update, #update_animation, #update_anime_count, #update_anime_pattern, #update_bush_depth, #update_jump, #update_move

Constructor Details

This class inherits a constructor from Game_CharacterBase

Instance Attribute Details

- (Object) move_route_forcing (readonly)


  • Public Instance Variables




62
63
64
# File 'Game_Character.rb', line 62

def move_route_forcing
  @move_route_forcing
end

Instance Method Details

- (Object) advance_move_route_index


  • Advance Execution Position of Move Route




341
342
343
# File 'Game_Character.rb', line 341

def advance_move_route_index
  @move_route_index += 1 if @move_succeed || @move_route.skippable
end

- (Object) distance_x_from(x)


  • Calculate Distance in X Axis Direction




186
187
188
189
190
191
192
193
194
195
196
# File 'Game_Character.rb', line 186

def distance_x_from(x)
  result = @x - x
  if $game_map.loop_horizontal? && result.abs > $game_map.width / 2
    if result < 0
      result += $game_map.width
    else
      result -= $game_map.width
    end
  end
  result
end

- (Object) distance_y_from(y)


  • Calculate Distance in Y Axis Direction




200
201
202
203
204
205
206
207
208
209
210
# File 'Game_Character.rb', line 200

def distance_y_from(y)
  result = @y - y
  if $game_map.loop_vertical? && result.abs > $game_map.height / 2
    if result < 0
      result += $game_map.height
    else
      result -= $game_map.height
    end
  end
  result
end

- (Object) force_move_route(move_route)


  • Force Move Route




99
100
101
102
103
104
105
106
# File 'Game_Character.rb', line 99

def force_move_route(move_route)
  memorize_move_route unless @original_move_route
  @move_route = move_route
  @move_route_index = 0
  @move_route_forcing = true
  @prelock_direction = 0
  @wait_count = 0
end

- (Object) init_private_members


  • Initialize Private Member Variables




73
74
75
76
77
78
79
80
# File 'Game_Character.rb', line 73

def init_private_members
  super
  @move_route = nil                 # Move route
  @move_route_index = 0             # Move route execution position
  @original_move_route = nil        # Original move route
  @original_move_route_index = 0    # Original move route execution position
  @wait_count = 0                   # Wait count
end

- (Object) init_public_members


  • Initialize Public Member Variables




66
67
68
69
# File 'Game_Character.rb', line 66

def init_public_members
  super
  @move_route_forcing = false
end

- (Object) jump(x_plus, y_plus)


  • Jump

    x_plus : x-coordinate plus value
    y_plus : y-coordinate plus value



313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'Game_Character.rb', line 313

def jump(x_plus, y_plus)
  if x_plus.abs > y_plus.abs
    set_direction(x_plus < 0 ? 4 : 6) if x_plus != 0
  else
    set_direction(y_plus < 0 ? 8 : 2) if y_plus != 0
  end
  @x += x_plus
  @y += y_plus
  distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  @jump_peak = 10 + distance - @move_speed
  @jump_count = @jump_peak * 2
  @stop_count = 0
  straighten
end

- (Object) memorize_move_route


  • Memorize Move Route




84
85
86
87
# File 'Game_Character.rb', line 84

def memorize_move_route
  @original_move_route        = @move_route
  @original_move_route_index  = @move_route_index
end

- (Object) move_away_from_character(character)


  • Move Away from Character




234
235
236
237
238
239
240
241
242
243
244
# File 'Game_Character.rb', line 234

def move_away_from_character(character)
  sx = distance_x_from(character.x)
  sy = distance_y_from(character.y)
  if sx.abs > sy.abs
    move_straight(sx > 0 ? 6 : 4)
    move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0
  elsif sy != 0
    move_straight(sy > 0 ? 2 : 8)
    move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0
  end
end

- (Object) move_away_from_player


  • Move away from Player




290
291
292
# File 'Game_Character.rb', line 290

def move_away_from_player
  move_away_from_character($game_player)
end

- (Object) move_backward


  • 1 Step Backward




302
303
304
305
306
307
# File 'Game_Character.rb', line 302

def move_backward
  last_direction_fix = @direction_fix
  @direction_fix = true
  move_straight(reverse_dir(@direction), false)
  @direction_fix = last_direction_fix
end

- (Object) move_forward


  • 1 Step Forward




296
297
298
# File 'Game_Character.rb', line 296

def move_forward
  move_straight(@direction)
end

- (Object) move_random


  • Move at Random




214
215
216
# File 'Game_Character.rb', line 214

def move_random
  move_straight(2 + rand(4) * 2, false)
end

- (Object) move_toward_character(character)


  • Move Toward Character




220
221
222
223
224
225
226
227
228
229
230
# File 'Game_Character.rb', line 220

def move_toward_character(character)
  sx = distance_x_from(character.x)
  sy = distance_y_from(character.y)
  if sx.abs > sy.abs
    move_straight(sx > 0 ? 4 : 6)
    move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
  elsif sy != 0
    move_straight(sy > 0 ? 8 : 2)
    move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
  end
end

- (Object) move_toward_player


  • Move toward Player




284
285
286
# File 'Game_Character.rb', line 284

def move_toward_player
  move_toward_character($game_player)
end

- (Object) process_move_command(command)


  • Process Move Command




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
# File 'Game_Character.rb', line 132

def process_move_command(command)
  params = command.parameters
  case command.code
  when ROUTE_END;               process_route_end
  when ROUTE_MOVE_DOWN;         move_straight(2)
  when ROUTE_MOVE_LEFT;         move_straight(4)
  when ROUTE_MOVE_RIGHT;        move_straight(6)
  when ROUTE_MOVE_UP;           move_straight(8)
  when ROUTE_MOVE_LOWER_L;      move_diagonal(4, 2)
  when ROUTE_MOVE_LOWER_R;      move_diagonal(6, 2)
  when ROUTE_MOVE_UPPER_L;      move_diagonal(4, 8)
  when ROUTE_MOVE_UPPER_R;      move_diagonal(6, 8)
  when ROUTE_MOVE_RANDOM;       move_random
  when ROUTE_MOVE_TOWARD;       move_toward_player
  when ROUTE_MOVE_AWAY;         move_away_from_player
  when ROUTE_MOVE_FORWARD;      move_forward
  when ROUTE_MOVE_BACKWARD;     move_backward
  when ROUTE_JUMP;              jump(params[0], params[1])
  when ROUTE_WAIT;              @wait_count = params[0] - 1
  when ROUTE_TURN_DOWN;         set_direction(2)
  when ROUTE_TURN_LEFT;         set_direction(4)
  when ROUTE_TURN_RIGHT;        set_direction(6)
  when ROUTE_TURN_UP;           set_direction(8)
  when ROUTE_TURN_90D_R;        turn_right_90
  when ROUTE_TURN_90D_L;        turn_left_90
  when ROUTE_TURN_180D;         turn_180
  when ROUTE_TURN_90D_R_L;      turn_right_or_left_90
  when ROUTE_TURN_RANDOM;       turn_random
  when ROUTE_TURN_TOWARD;       turn_toward_player
  when ROUTE_TURN_AWAY;         turn_away_from_player
  when ROUTE_SWITCH_ON;         $game_switches[params[0]] = true
  when ROUTE_SWITCH_OFF;        $game_switches[params[0]] = false
  when ROUTE_CHANGE_SPEED;      @move_speed = params[0]
  when ROUTE_CHANGE_FREQ;       @move_frequency = params[0]
  when ROUTE_WALK_ANIME_ON;     @walk_anime = true
  when ROUTE_WALK_ANIME_OFF;    @walk_anime = false
  when ROUTE_STEP_ANIME_ON;     @step_anime = true
  when ROUTE_STEP_ANIME_OFF;    @step_anime = false
  when ROUTE_DIR_FIX_ON;        @direction_fix = true
  when ROUTE_DIR_FIX_OFF;       @direction_fix = false
  when ROUTE_THROUGH_ON;        @through = true
  when ROUTE_THROUGH_OFF;       @through = false
  when ROUTE_TRANSPARENT_ON;    @transparent = true
  when ROUTE_TRANSPARENT_OFF;   @transparent = false
  when ROUTE_CHANGE_GRAPHIC;    set_graphic(params[0], params[1])
  when ROUTE_CHANGE_OPACITY;    @opacity = params[0]
  when ROUTE_CHANGE_BLENDING;   @blend_type = params[0]
  when ROUTE_PLAY_SE;           params[0].play
  when ROUTE_SCRIPT;            eval(params[0])
  end
end

- (Object) process_route_end


  • Process Move Route End




330
331
332
333
334
335
336
337
# File 'Game_Character.rb', line 330

def process_route_end
  if @move_route.repeat
    @move_route_index = -1
  elsif @move_route_forcing
    @move_route_forcing = false
    restore_move_route
  end
end

- (Object) restore_move_route


  • Restore Move Route




91
92
93
94
95
# File 'Game_Character.rb', line 91

def restore_move_route
  @move_route           = @original_move_route
  @move_route_index     = @original_move_route_index
  @original_move_route  = nil
end

- (Object) swap(character)


  • Swap Character Positions




390
391
392
393
394
395
# File 'Game_Character.rb', line 390

def swap(character)
  new_x = character.x
  new_y = character.y
  character.moveto(x, y)
  moveto(new_x, new_y)
end

- (Object) turn_180


  • Turn 180°




369
370
371
# File 'Game_Character.rb', line 369

def turn_180
  set_direction(reverse_dir(@direction))
end

- (Object) turn_away_from_character(character)


  • Turn Away from Character




260
261
262
263
264
265
266
267
268
# File 'Game_Character.rb', line 260

def turn_away_from_character(character)
  sx = distance_x_from(character.x)
  sy = distance_y_from(character.y)
  if sx.abs > sy.abs
    set_direction(sx > 0 ? 6 : 4)
  elsif sy != 0
    set_direction(sy > 0 ? 2 : 8)
  end
end

- (Object) turn_away_from_player


  • Turn away from Player




278
279
280
# File 'Game_Character.rb', line 278

def turn_away_from_player
  turn_away_from_character($game_player)
end

- (Object) turn_left_90


  • Turn 90° Left




358
359
360
361
362
363
364
365
# File 'Game_Character.rb', line 358

def turn_left_90
  case @direction
  when 2;  set_direction(6)
  when 4;  set_direction(2)
  when 6;  set_direction(8)
  when 8;  set_direction(4)
  end
end

- (Object) turn_random


  • Turn at Random




384
385
386
# File 'Game_Character.rb', line 384

def turn_random
  set_direction(2 + rand(4) * 2)
end

- (Object) turn_right_90


  • Turn 90° Right




347
348
349
350
351
352
353
354
# File 'Game_Character.rb', line 347

def turn_right_90
  case @direction
  when 2;  set_direction(4)
  when 4;  set_direction(8)
  when 6;  set_direction(2)
  when 8;  set_direction(6)
  end
end

- (Object) turn_right_or_left_90


  • Turn 90° Right or Left




375
376
377
378
379
380
# File 'Game_Character.rb', line 375

def turn_right_or_left_90
  case rand(2)
  when 0;  turn_right_90
  when 1;  turn_left_90
  end
end

- (Object) turn_toward_character(character)


  • Turn Toward Character




248
249
250
251
252
253
254
255
256
# File 'Game_Character.rb', line 248

def turn_toward_character(character)
  sx = distance_x_from(character.x)
  sy = distance_y_from(character.y)
  if sx.abs > sy.abs
    set_direction(sx > 0 ? 4 : 6)
  elsif sy != 0
    set_direction(sy > 0 ? 8 : 2)
  end
end

- (Object) turn_toward_player


  • Turn toward Player




272
273
274
# File 'Game_Character.rb', line 272

def turn_toward_player
  turn_toward_character($game_player)
end

- (Object) update_routine_move


  • Update Move Along Route




117
118
119
120
121
122
123
124
125
126
127
128
# File 'Game_Character.rb', line 117

def update_routine_move
  if @wait_count > 0
    @wait_count -= 1
  else
    @move_succeed = true
    command = @move_route.list[@move_route_index]
    if command
      process_move_command(command)
      advance_move_route_index
    end
  end
end

- (Object) update_stop


  • Update While Stopped




110
111
112
113
# File 'Game_Character.rb', line 110

def update_stop
  super
  update_routine_move if @move_route_forcing
end