Home > RGSS Script Reference > Game_Character
Game_Character
Inherits from: None
Description: This class determines the behavior of the hero sprite and event sprites on the map, including movement, defining the different movement types for events, and handling the commands for custom movement routes and the "Move Event" command.
class Game_Character
# ------------------------------------
attr_reader :id
attr_reader :x
attr_reader :y
attr_reader :real_x
attr_reader :real_y
attr_reader :tile_id
attr_reader :character_name
attr_reader :character_hue
attr_reader :opacity
attr_reader :blend_type
attr_reader :direction
attr_reader :pattern
attr_reader :move_route_forcing
attr_reader :through
attr_accessor :animation_id
attr_accessor :transparent
# ------------------------------------
def initialize
@id = 0
@x = 0
@y = 0
@real_x = 0
@real_y = 0
@tile_id = 0
@character_name = ""
@character_hue = 0
@opacity = 255
@blend_type = 0
@direction = 2
@pattern = 0
@move_route_forcing = false
@through = false
@animation_id = 0
@transparent = false
@original_direction = 2
@original_pattern = 0
@move_type = 0
@move_speed = 4
@move_frequency = 6
@move_route = nil
@move_route_index = 0
@original_move_route = nil
@original_move_route_index = 0
@walk_anime = true
@step_anime = false
@direction_fix = false
@always_on_top = false
@anime_count = 0
@stop_count = 0
@jump_count = 0
@jump_peak = 0
@wait_count = 0
@locked = false
@prelock_direction = 0
end
# ------------------------------------
def moving?
return (@real_x != @x * 128 or @real_y != @y * 128)
end
# ------------------------------------
def jumping?
return @jump_count > 0
end
# ------------------------------------
def straighten
if @walk_anime or @step_anime
@pattern = 0
end
@anime_count = 0
@prelock_direction = 0
end
# ------------------------------------
def force_move_route(move_route)
if @original_move_route == nil
@original_move_route = @move_route
@original_move_route_index = @move_route_index
end
@move_route = move_route
@move_route_index = 0
@move_route_forcing = true
@prelock_direction = 0
@wait_count = 0
move_type_custom
end
# ------------------------------------
def passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
unless $game_map.valid?(new_x, new_y)
return false
end
if @through
return true
end
unless $game_map.passable?(x, y, d, self)
return false
end
unless $game_map.passable?(new_x, new_y, 10 - d)
return false
end
for event in $game_map.events.values
if event.x == new_x and event.y == new_y
unless event.through
if self != $game_player
return false
end
if event.character_name != ""
return false
end
end
end
end
if $game_player.x == new_x and $game_player.y == new_y
unless $game_player.through
if @character_name != ""
return false
end
end
end
return true
end
# ------------------------------------
def lock
if @locked
return
end
@prelock_direction = @direction
turn_toward_player
@locked = true
end
# ------------------------------------
def lock?
return @locked
end
# ------------------------------------
def unlock
unless @locked
return
end
@locked = false
unless @direction_fix
if @prelock_direction != 0
@direction = @prelock_direction
end
end
end
# ------------------------------------
def moveto(x, y)
@x = x
@y = y
@real_x = x * 128
@real_y = y * 128
end
# ------------------------------------
def screen_x
return (@real_x - $game_map.display_x) / 4 + 16
end
# ------------------------------------
def screen_y
y = (@real_y - $game_map.display_y) / 4 + 32
if @jump_count >= @jump_peak
n = @jump_count - @jump_peak
else
n = @jump_peak - @jump_count
end
return y - (@jump_peak * @jump_peak - n * n) / 2
end
# ------------------------------------
def screen_z(height = 0)
if @always_on_top
return 999
end
z = (@real_y - $game_map.display_y) / 4
if @real_y % 128 > 0
z += (131 - @real_y % 128) / 4
end
if @tile_id > 0
return z + $game_map.priorities[@tile_id] * 32
else
return z + ((height > 32) ? 31 : 0)
end
end
# ------------------------------------
def bush_depth
if @tile_id > 0 or @always_on_top
return 0
end
if @jump_count == 0 and $game_map.bush?(@x, @y)
return 12
else
return 0
end
end
# ------------------------------------
def terrain_tag
return $game_map.terrain_tag(@x, @y)
end
end
# ------------------------------------
def update
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
if @anime_count > 18 - @move_speed * 2
if not @step_anime and @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % 4
end
@anime_count = 0
end
if @wait_count > 0
@wait_count -= 1
return
end
if @move_route_forcing
move_type_custom
return
end
if @starting or lock?
return
end
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
case @move_type
when 1
move_type_random
when 2
move_type_toward_player
when 3
move_type_custom
end
end
end
# ------------------------------------
def update_jump
@jump_count -= 1
@real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
@real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
end
# ------------------------------------
def update_move
distance = 2 ** @move_speed
if @y * 128 > @real_y
@real_y = [@real_y + distance, @y * 128].min
end
if @x * 128 < @real_x
@real_x = [@real_x - distance, @x * 128].max
end
if @x * 128 > @real_x
@real_x = [@real_x + distance, @x * 128].min
end
if @y * 128 < @real_y
@real_y = [@real_y - distance, @y * 128].max
end
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
end
# ------------------------------------
def update_stop
if @step_anime
@anime_count += 1
elsif @pattern != @original_pattern
@anime_count += 1.5
end
unless @starting or lock?
@stop_count += 1
end
end
# ------------------------------------
def move_type_random
case rand(6)
when 0..3
move_random
when 4
move_forward
when 5
@stop_count = 0
end
end
# ------------------------------------
def move_type_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
abs_sx = sx > 0 ? sx : -sx
abs_sy = sy > 0 ? sy : -sy
if sx + sy >= 20
move_random
return
end
case rand(6)
when 0..3
move_toward_player
when 4
move_random
when 5
move_forward
end
end
# ------------------------------------
def move_type_custom
if jumping? or moving?
return
end
while @move_route_index < @move_route.list.size
command = @move_route.list[@move_route_index]
if command.code == 0
if @move_route.repeat
@move_route_index = 0
end
unless @move_route.repeat
if @move_route_forcing and not @move_route.repeat
@move_route_forcing = false
@move_route = @original_move_route
@move_route_index = @original_move_route_index
@original_move_route = nil
end
@stop_count = 0
end
return
end
if command.code <= 14
case command.code
when 1
move_down
when 2
move_left
when 3
move_right
when 4
move_up
when 5
move_lower_left
when 6
move_lower_right
when 7
move_upper_left
when 8
move_upper_right
when 9
move_random
when 10
move_toward_player
when 11
move_away_from_player
when 12
move_forward
when 13
move_backward
when 14
jump(command.parameters[0], command.parameters[1])
end
if not @move_route.skippable and not moving? and not jumping?
return
end
@move_route_index += 1
return
end
if command.code == 15
@wait_count = command.parameters[0] * 2 - 1
@move_route_index += 1
return
end
if command.code >= 16 and command.code <= 26
case command.code
when 16
turn_down
when 17
turn_left
when 18
turn_right
when 19
turn_up
when 20
turn_right_90
when 21
turn_left_90
when 22
turn_180
when 23
turn_right_or_left_90
when 24
turn_random
when 25
turn_toward_player
when 26
turn_away_from_player
end
@move_route_index += 1
return
end
if command.code >= 27
case command.code
when 27
$game_switches[command.parameters[0]] = true
$game_map.need_refresh = true
when 28
$game_switches[command.parameters[0]] = false
$game_map.need_refresh = true
when 29
@move_speed = command.parameters[0]
when 30
@move_frequency = command.parameters[0]
when 31
@walk_anime = true
when 32
@walk_anime = false
when 33
@step_anime = true
when 34
@step_anime = false
when 35
@direction_fix = true
when 36
@direction_fix = false
when 37
@through = true
when 38
@through = false
when 39
@always_on_top = true
when 40
@always_on_top = false
when 41
@tile_id = 0
@character_name = command.parameters[0]
@character_hue = command.parameters[1]
if @original_direction != command.parameters[2]
@direction = command.parameters[2]
@original_direction = @direction
@prelock_direction = 0
end
if @original_pattern != command.parameters[3]
@pattern = command.parameters[3]
@original_pattern = @pattern
end
when 42
@opacity = command.parameters[0]
when 43
@blend_type = command.parameters[0]
when 44
$game_system.se_play(command.parameters[0])
when 45
result = eval(command.parameters[0])
end
@move_route_index += 1
end
end
end
# ------------------------------------
def increase_steps
@stop_count = 0
end
end
# ------------------------------------
def move_down(turn_enabled = true)
if turn_enabled
turn_down
end
if passable?(@x, @y, 2)
turn_down
@y += 1
increase_steps
else
check_event_trigger_touch(@x, @y+1)
end
end
# ------------------------------------
def move_left(turn_enabled = true)
if turn_enabled
turn_left
end
if passable?(@x, @y, 4)
turn_left
@x -= 1
increase_steps
else
check_event_trigger_touch(@x-1, @y)
end
end
# ------------------------------------
def move_right(turn_enabled = true)
if turn_enabled
turn_right
end
if passable?(@x, @y, 6)
turn_right
@x += 1
increase_steps
else
check_event_trigger_touch(@x+1, @y)
end
end
# ------------------------------------
def move_up(turn_enabled = true
if turn_enabled
turn_up
end
if passable?(@x, @y, 8)
turn_up
@y -= 1
increase_steps
else
check_event_trigger_touch(@x, @y-1)
end
end
# ------------------------------------
def move_lower_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
@x -= 1
@y += 1
increase_steps
end
end
# ------------------------------------
def move_lower_right
# ?????????
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
@x += 1
@y += 1
increase_steps
end
end
# ------------------------------------
def move_upper_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
@x -= 1
@y -= 1
increase_steps
end
end
# ------------------------------------
def move_upper_right
# ?????????
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
@x += 1
@y -= 1
increase_steps
end
end
# ------------------------------------
def move_random
case rand(4)
when 0
move_down(false)
when 1
move_left(false)
when 2
move_right(false)
when 3
move_up(false)
end
end
# ------------------------------------
def move_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx == 0 and sy == 0
return
end
abs_sx = sx.abs
abs_sy = sy.abs
if abs_sx == abs_sy
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
if abs_sx > abs_sy
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
else
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
# ------------------------------------
def move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx == 0 and sy == 0
return
end
abs_sx = sx.abs
abs_sy = sy.abs
if abs_sx == abs_sy
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
if abs_sx > abs_sy
sx > 0 ? move_right : move_left
if not moving? and sy != 0
sy > 0 ? move_down : move_up
end
else
sy > 0 ? move_down : move_up
if not moving? and sx != 0
sx > 0 ? move_right : move_left
end
end
end
# ------------------------------------
def move_forward
case @direction
when 2
move_down(false)
when 4
move_left(false)
when 6
move_right(false)
when 8
move_up(false)
end
end
# ------------------------------------
def move_backward
last_direction_fix = @direction_fix
@direction_fix = true
case @direction
when 2
move_up(false)
when 4
move_right(false)
when 6
move_left(false)
when 8
move_down(false)
end
@direction_fix = last_direction_fix
end
# ------------------------------------
def jump(x_plus, y_plus)
if x_plus != 0 or y_plus != 0
if x_plus.abs > y_plus.abs
x_plus < 0 ? turn_left : turn_right
else
y_plus < 0 ? turn_up : turn_down
end
end
new_x = @x + x_plus
new_y = @y + y_plus
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
straighten
@x = new_x
@y = new_y
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
end
end
# ------------------------------------
def turn_down
unless @direction_fix
@direction = 2
end
end
# ------------------------------------
def turn_left
unless @direction_fix
@direction = 4
end
end
# ------------------------------------
def turn_right
unless @direction_fix
@direction = 6
end
end
# ------------------------------------
def turn_up
unless @direction_fix
@direction = 8
end
end
# ------------------------------------
def turn_right_90
case @direction
when 2
turn_left
when 4
turn_up
when 6
turn_down
when 8
turn_right
end
end
# ------------------------------------
def turn_left_90
case @direction
when 2
turn_right
when 4
turn_down
when 6
turn_up
when 8
turn_left
end
end
# ------------------------------------
def turn_180
case @direction
when 2
turn_up
when 4
turn_right
when 6
turn_left
when 8
turn_down
end
end
# ------------------------------------
def turn_right_or_left_90
if rand(2) == 0
turn_right_90
else
turn_left_90
end
end
# ------------------------------------
def turn_random
case rand(4)
when 0
turn_up
when 1
turn_right
when 2
turn_left
when 3
turn_down
end
end
# ------------------------------------
def turn_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx == 0 and sy == 0
return
end
if sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
else
sy > 0 ? turn_up : turn_down
end
end
# ------------------------------------
def turn_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx == 0 and sy == 0
return
end
if sx.abs > sy.abs
sx > 0 ? turn_right : turn_left
else
sy > 0 ? turn_down : turn_up
end
end
end
|
ID: The event ID of the character.
X: The character's X coordinate, expressed in tiles.
Y: The character's Y coordinate, expressed in tiles.
Real_X: The character's real X coordinate, equal to 128 x the character's X coordinate in tiles.
Real_Y: The character's real Y coordinate, equal to 128 x the character's Y coordinate in tiles.
Tile_ID: The character's tile ID (0 = the character is not present on the map).
Character_Name: The filename of the character's sprite.
Character_Hue: The character's hue modification.
Opacity: The character's opacity level (0 = completely transparent, 255 = completely opaque).
Blend_Tyoe: The method used to display the character (0 = Normal, 1 = Additive, 2 = Negative).
Direction: The direction the character is facing (2 = Down, 4 = Left, 6 = Right, 8 = Up)
Pattern: Which of the character's walking patterns is currently being shown, from 0 (leftmost) to 3 (rightmost).
Move_Route_Forcing: This flag is set if the character is being forced to move by the "Move Event" command.
Through: This flag is set if the character has been assigned the "Phasing" property.
Animation_ID: If this value is greater than 0, it means that a battle animation is waiting to be shown on the event due to having been the target of the "Show Battle Animation" event command.
Transparent: This flag is set when the character has been assigned the "Transparent" property through events. This setting overrides the character's opacity value.
Original_Direction: Stores the original direction the character was facing when it is changed by some events.
Original_Pattern: Stores the original character animation frame for the character when it is changed by some events.
Move_Type: The character's movement type (0 = stationary, 1 = random, 2 = move toward player, 3 = custom route).
Move_Speed: This value shows how quickly the character should move. Higher values mean the character moves faster.
Move_Frequency: This value shows how often the character should move. Higher values mean the character will move more often.
Move_Route: An array containing a movement route from the "Move Event" command.
Move_Route_Index: Keeps track of which instruction in a "Move Event" command was just executed.
Original_Move_Route: This array is used to remember the character's original movement route in the case where a character with a custom movement pattern is forced to move using the "Move Event" command.
Original_Move_Route_Index: Remembers what command the in the character's custom movement pattern executed before the Move Event took over his movement.
Walk_Anime: If this flag is set, the character's walking animation will be played when it moves.
Step_Anime: If this flag is set, the character's walking animation will be played even when the character is not moving.
Direction_Fix: If this flag is set, then the character won't change facing.
Always_On_Top: If this flag is set, the character will never be obscured by scenery that is supposed to appear above the character, nor will it be obscured by tiles that have the "Obscure Character" property.
Anime_Count: This counter is updated each frame if either the @walk_anime or @step_anime flag is set. When this value reaches a certain value based on the character's movement speed, the character's walking animation pattern is updated.
Stop_Count: This counter is updated each frame the character is stopped as long as another event isn't executing. Once the counter reaches a certain value based on the character's movement frequency, the character will move so long as the character's movement type isn't "stationary".
Jump_Count: The number of frames remaining in a jump.
Jump_Peak: The point in the jump where the jump will peak, equal to half the jump count.
Wait_Count: The amount of time the character should take no action (in frames).
Locked: A flag that is set when the event is locked because it has been triggered by the player.
Prelock_Direction: The direction the event was facing prior to being locked.
Starting: This flag is set when an event associated with the character has been triggered.
Initialize
Arguments: None
Local Variables: None
How it Works: Sets all the instance variables of the character object to their default values, which represent a null character.
Moving?
Arguments: None
Local Variables: None
How it Works: Returns a boolean value representing whether the character is moving or not. This is determined by comparing the logical X and Y coordinates with what the real X and Y coordinates should be if the character is not moving. If either real coordinate differs, then this method returns true.
Jumping?
Arguments: None
Local Variables: None
How it Works: This method returns true if the character is jumping.
Straighten
Arguments: None
Local Variables: None
How it Works: This method straightens the character by returning it to its idle stance. First, the @pattern variable is set to 0, meaning the character's idle stance. The animation counter is then reset to 0. Finally, the @prelock_direction is reset to 0 (no prelock direction).
Force_Move_Route
Arguments:
Move_Route: An array containing the route.
Local Variables: None
How it Works: This method sets up a forced movement route. The if @original_move_route == nil clause makes it so that if a character has a custom pattern, that pattern is stored in @original_move_route until the forced movement is complete. The command index at which the custom movement pattern was interrupted is stored in @original_move_route_index. The rest of this method does necessary housekeeping in preparation for a forced move, such as setting the forced movement flag and clearing any wait time remaining for the event. The actual forced movement is carried out by the call to
move_type_custom.
Passable?
Arguments:
X: The X coordinate of the character.
Y: The Y coordinate of the character.
D: The direction the character is walking to enter the tile (0 = Multidirectional [used in jumping], 2 = Down, 4 = Left, 6 = Right, 8 = Up).
Local Variables: None
How it Works: This method calculates whether a character can enter the tile specified in the X and Y coordinates passed to the method from the direction passed to the method. The new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0) statement and the corresponding statement for the y coordinate use the direction specified in the arguments to determine the coordinate of the tile to check for passability. The first thing the method checks is whether or not the new coordinate is even inside the bounds of the map. If it isn't, then the method returns false straight away. If the tile is within the map's bounds, the next thing to determine is whether the character has the Phasing property as shown by his @through flag. If this flag is set, then any tile on the map is passable, so the method returns true. The next two unless statements check the directional passability of both the tile from which the character is departing and the tile to which the character is arriving. If either check fails, then the movement is not possible and the method returns false. The for loop checks for illegal event collisions. An illegal event collision will occur if either an event or the player is at the new X and Y coordinate and that event or the player does not have the "Phasing" property. There is one exception to this rule, and that is transparent events. Transparent events can be freely crossed by both the player and other events. If an event's @character_name property is equal to a null string, then the event is transparent. If none of the above conditions are true, then the tile is passable and the method returns true.
Lock
Arguments: None
Local Variables: None
How it Works: This method locks a non-autostart/parallel process event that has been triggered if it isn't already locked. It first sets the @prelock_direction value to the direction the event was facing before being triggered, then makes the event face the player, and finally sets the @locked flag for the event to show that it is locked.
Locked?
Arguments: None
Local Variables: None
How it Works: This method returns the value of the character's @locked flag.
Unlock
Arguments: None
Local Variables: None
How it Works: This method unlocks an event that has been triggered after it finishes executing. First, the character's @locked flag is cleared. Then, as long as the character doesn't have the "Lock Facing" property and a prelock direction has been assigned (and there always will be except in an anomolous case), the character's facing is set to the value stored in @prelock_direction.
Moveto
Arguments:
X: The new X coordinate in tiles.
Y: The new Y coordinate in tiles.
Local Variables: None
How it Works: This method teleports the character to the specified location. It is called by the "Teleport" and "Change Event Location" event commands. It simply sets the character's X and Y coordinate to the new values, and updates the associated real coordinates.
Screen_X
Arguments: None
Local Variables: None
How it Works: Returns the screen-relative X coordinate of the character. This is done by using the equation @real_x - $game_map.display_x) / 4 + 16. Note that $game_map.display_x is how far in pixels the map has scrolled to the right relative to the left side of the map, multiplied by 4.
Screen_Y
Arguments: None
Local Variables:
Y: The value returned to the caller.
N: A value used in computing the displacement caused by jumping.
How it Works: Returns the screen-relative Y coordinate of the character. This is done by using the equation @real_y - $game_map.display_y) / 4 + 32. Note that $game_map.display_y is how far in pixels the map has scrolled downward relative to the top of the map, multiplied by 4. If the character is jumping, the second part of the method computes the displacement relative to the above value due to jumping. The further away the character is from the jump peak, the smaller the displacement. n is set to the distance from the jump peak, then the screen-relative Y coordinate is reduced by (peak² - n²) / 2 and then returned to the caller.
Screen_Z
Arguments:
Height: The height of the character.
Local Variables: None
Z: The Z-index returned to the caller.
How it Works: This method returns the Z-index of the character. The Z-index determines the priority of graphics that occupy the same space. A graphic with a higher Z-index will cover a graphic with a lower Z-index. The first thing the method does is check to see if the character's @always_on_top flag is set. If it is, the method simply returns 999 without doing any further processing. Otherwise, the next part of the method sets the Z-index based on the character's displacement from the top of the map. Characters that are further displaced from the top of the map will have, on average, higher z-indices than those near the top of the map. The if @real_y % 128 > 0 clause makes it so that characters that are moving will have higher z-indices than those that are not. The first return statement returns the value of z up to this point plus the tile's priority level of the tile multiplied by 32. If the character is on a zero-priority tile, nothing is added if the character is 32 or fewer pixels tall, or 31 if the character is 33 or more pixels tall.
Bush_Depth
Arguments: None
Local Variables: None
How it Works: This method returns how much of the character to obscure due to being on a tile with the "Obscure Character" property. If either @tile_id is greater than zero or the character's @always_on_top flag is set, then the character is never obscured. Otherwise, the amount of pixels to be obscured (12 by default) is returned if both the character isn't jumping and the tile on which the character is standing has the "Obscure Character' property.
Terrain_Tag
Arguments: None
Local Variables: None
How it Works: Returns the terrain tag of the tile on which the character is standing.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the graphics for every character each frame. The first if statement decides what the character is doing: jumping, moving, or neither. Note that while jumping is considered movement for purposes of the Moving? method, the effect of jumping takes priority in this case, as signified by being the first condition evaluated. The second part of the method determines whether the character's animation should update, the character should move, or both. The if @anime_count > 18 - @move_speed * 2 clause means that as long as the character doesn't have the "Step Animation" property and the @stop_count counter is above 0, the character's animation pattern won't change. Otherwise, the character's animation will advance to the next frame as defined in the character set file if the @anime_count counter is greater than 18 minus twice the character's movement speed. The @wait_count counter is then decremented. The
@move_route_forcing check determines whether or not the character is in the midst of a forced move as a result of "Move Event". If @starting or locked? is true, the event will never move unless being forced, so the method returns. The final part of the method determines whether or not the character should move. If the stop counter is greater than (40 - 2 x frequency) x (6 - frequency), and the character has a movement type other than "stationary", the character will move according to its movement type. Note that the equation above means that if you set the character's movement frequency to 6, it will move constantly.
Update_Jump
Arguments: None
Local Variables: None
How it Works: Updates a jump in progress. First the jump counter is decremented. Then, the values of @real_x and @real_y are updated. Note that the logical X and Y coordinates are not updated during a jump, but they are used in the equation. This is so that they can be used to maintain the slope of the imaginary line created between the beginning point and ending point of the jump. Please see the jump method to see how the line is created.
Update_Move
Arguments: None
Local Variables:
Distance: The distance in real units to move the character.
How it Works: Updates a move in progress. First, the value of distance is set to 2speed. The next four if statements move the character the value of distance in real units and creates an imaginary bounding box to ensure that the character doesn't overshoot its destination. The checks of the walk_anime and step_anime flags determine whether and by how much the animation counter should be increased. Note that if the character's walk animation flag is set, the character's walking animation will be updated 3 times for every 2 compared to if only the step animation flag is set.
Update_Stop
Arguments: None
Local Variables: None
How it Works: Updates the counters for characters that are neither moving nor jumping. If the character's step_anime flag is set, the animation counter is incremented. Otherwise, the animation counter isn't changed unless another method has caused the animation to be updated. Finally, unless the event has been triggered by the player or is starting for some other reason, the character's stop counter is incremented.
Move_Type_Random
Arguments: None
Local Variables: None
How it Works: Resolves movement for characters with the "Random" movement type. A random number between 0 and 5 is chosen. If the result is between 0 and 3, the character has an equal chance of moving in any of the four cardinal directions. If the result is 4, the character moves in the direction it is currently facing. If the result is 5, it doesn't move at all and resets the stop counter.
Move_Type_Toward_Player
Arguments: None
Local Variables:
sx: The difference in tiles between the X coordinate of the player and the X coordinate of the character.
sy: The difference in tiles between the Y coordinate of the player and the Y coordinate of the character.
How it Works: Resolves movement for characters with the "Move Toward Player" movement type. The first two statements compare the coordinates of the event with the coordinates of the player and store them in sx and sy. If the sum of the difference between the X and Y coordinates of the character and the X and Y coordinates of the player is 20 or more, the character acts as if it has the "Random" movement type. Otherwise, a random number between 0 and 5 is generated. On a result of 0 to 3, the character moves towards the player. On a result of 4, the character will move in a random direction. On a result of 5, it will move in the direction it is facing.
Move_Type_Custom
Arguments: None
Local Variables:
Command: Points to the next move in the route to be executed.
How it Works: This method resolves the movement for characters that have a custom movement route defined. This method is also used to resolve "Move Event" commands. The first part of this method checks to see if the character is moving or jumping. If it is, then the custom pattern is ignored and the method returns. Otherwise, the huge while loop executes. First, the method sets up the route by creating the variable command, which points to the next move in the series to be executed. It then checks to see if command.code is 0, which means the last move in the route has executed. If it is, then it checks to see whether the route should repeat. If the repeat flag is set, then the route wraps around to the beginning and executes again. The unless @move_route.repeat clause contains the code for terminating the movement. If the character's movement was being forced by a "Move Event" command, then the @move_route_forcing flag is cleared and the character's movement route and the positiion in that movement route is restored if that character had a custom movement pattern interrupted by the Move Event. The rest of this loop is a large set of if statements that check to see what the next command in the route is. I won't go through each individually. Instead, I'll highlight the groupings Enterbrain used. The first grouping (commands 1-14) are movement commands. These commands simply call the appropriate movement method (see below to see how a given movement method works). Command 15 is Wait. Note that the frame count for this wait is doubled. The next eleven commands (commands 16-26) are commands that perform changes to facing. They call the appropritate facing change method. See below for specific method defintions. Commands 27-45 are "other" commands, that set or clear character flags, change the value of switches, change the character's graphics, or run a script. These command don't call associated methods. Rather, they simply execute within the move_type_custom method.
Increase_Steps
Arguments: None
Local Variables: None
How it Works: This method resets the stop counter after a move is executed. It is called by some of the movement commands from "Move Event".
Move_Dwn
Arguments:
Turn_Enabled: A flag that tells the method whether the character is allowed to turn.
Local Variables: None
How it Works: This method moves the character down one tile, if possible. First, if the character can turn (its direction isn't fixed), it faces downward. Then, the method checks whether the tile below the character is passable. If it is, the character's Y coordinate is incremented and the stop counter is reset. Otherwise, the method checks to see if an event that has the "Collision with Hero" trigger is triggered as a result of colliding with an event on the tile below the character.
Move_Left
Arguments:
Turn_Enabled: A flag that tells the method whether the character is allowed to turn.
Local Variables: None
How it Works: This method moves the character left one tile, if possible. First, if the character can turn, it faces left. Then, the method checks whether the tile to the left of the character is passable. If it is, the character's X coordinate is decremented and the stop counter is reset. Otherwise, the method checks to see if an event with the "Collision with Hero" trigger is triggered as a result of colliding with an event on the tile to the left of the character.
Move_Right
Arguments:
Turn_Enabled: A flag that tells the method whether the character is allowed to turn.
Local Variables: None
How it Works: This method moves the character right one tile, if possible. First, if the character can turn, it faces right. Then, the method checks whether the tile to the right of the character is passable. If it is, the character's X coordinate is incremented and the stop counter is reset. Otherwise, the method checks to see if an event with the "Collision with Hero" trigger is triggered as a result of colliding with an event on the tile to the right of the character.
Move_Up
Arguments:
Turn_Enabled: A flag that tells the method whether the character is allowed to turn.
Local Variables: None
How it Works: This method moves the character up one tile, if possible. First, if the character can turn, it faces up. Then, the method checks whether the tile above the character is passable. If it is, the character's Y coordinate is decremented and the stop counter is reset. Otherwise, the method checks to see if an event with the "Collision with Hero" trigger is triggered as a result of colliding with an event on the tile above the character.
Move_Lower_Left
Arguments: None
Local Variables: None
How it Works: Moves the character down and left one tile. Unless the character's @direction_fix flag is set, the method first changes the character's facing. If the character is currently facing right, the character faces left. If the character is currently facing up, the character faces down. Otherwise, the character retains its current facing. The next part of the method checks to see if it's possible to get from the current tile to the lower-left tile by checking to see if either the character can go from the current tile to the left, and then down, or go down, and then to the left. If it is possible to do either, the character's X coordinate is decremented and the character's Y coordinate is incremented, and the stop counter is reset.
Move_Lower_Right
Arguments: None
Local Variables: None
How it Works: Moves the character down and right one tile. Unless the character's @direction_fix flag is set, the method first changes the character's facing. If the character is currently facing left, the character faces right. If the character is currently facing up, the character faces down. Otherwise, the character retains its current facing. The next part of the method checks to see if it's possible to get from the current tile to the lower-right tile by checking to see if either the character can go from the current tile to the right, and then down, or go down, and then to the right. If it is possible to do either, the character's X and Y coordinates are incremented, and the stop counter is reset.
Move_Upper_Left
Arguments: None
Local Variables: None
How it Works: Moves the character up and left one tile. Unless the character's @direction_fix flag is set, the method first changes the character's facing. If the character is currently facing right, the character faces left. If the character is currently facing down, the character faces up. Otherwise, the character retains its current facing. The next part of the method checks to see if it's possible to get from the current tile to the upper-left tile by checking to see if either the character can go from the current tile to the left, and then up, or go up, and then to the left. If it is possible to do either, the character's X and Y coordinates are decremented, and the stop counter is reset.
Move_Upper_Right
Arguments: None
Local Variables: None
How it Works: Moves the character up and right one tile. Unless the character's @direction_fix flag is set, the method first changes the character's facing. If the character is currently facing left, the character faces right. If the character is currently facing down, the character faces up. Otherwise, the character retains its current facing. The next part of the method checks to see if it's possible to get from the current tile to the upper-right tile by checking to see if either the character can go from the current tile to the right, and then up, or go up, and then to the right. If it is possible to do either, the character's X coordinate is incremented and the character's Y coordinate is decremented, and the stop counter is reset.
Move_Random
Arguments: None
Local Variables: None
How it Works: Chooses a random number between 0 and 3. If the result is 0, the character moves down. If the result is 1, the character moves left. If the result is 2, the characte rmoves right. If the result is 3, the character moves up.
Move_Toward_Player
Arguments: None
Local Variables: None
sx: The difference in tiles between the X coordinate of the player and the X coordinate of the character.
sy: The difference in tiles between the Y coordinate of the player and the Y coordinate of the character.
How it Works: Makes the character move toward the player. The sx = @x - $game_player.x and sy = @y - $game_player.y statements determine the character's spatial relationship with the player. If both sx and sy are both 0 (the character being moved is the player), then the method returns without doing anything. The method then takes the absolute value of those values to determine whether the character is further away from the player in the X direction or the Y direction. If sx.abs and sy.abs are equal, one of the values is randomly incremented so that the method can continue. The next part of the method checks to see if sx.abs > sy.abs. If it is, then it checks whether the raw value of sx is positive or negative. If the value is positive, then the character moves left. Otherwise, it moves right. The nested conditional is there in case the character can't move in the specified direction because of an obstruction. If it can't, the character moves toward player in the Y direction, so long as the character's Y coordinate is different from the player. If sy.abs > sx.abs, then the character moves in the Y direction (or the X direction if there's an obstruction).
Move_Away_from_Player
Arguments: None
Local Variables: None
sx: The difference in tiles between the X coordinate of the player and the X coordinate of the character.
sy: The difference in tiles between the Y coordinate of the player and the Y coordinate of the character.
How it Works: Makes the character move away from the player. The sx = @x - $game_player.x and sy = @y - $game_player.y statements determine the character's spatial relationship with the player. If both sx and sy are both 0 (the character being moved is the player), then the method returns without doing anything. The method then takes the absolute value of those values to determine whether the character is further away from the player in the X direction or the Y direction. If sx.abs and sy.abs are equal, one of the values is randomly incremented so that the method can continue. The next part of the method checks to see if sx.abs > sy.abs. If it is, then it checks whether the raw value of sx is positive or negative. If the value is positive, then the character moves right. Otherwise, it moves left. The nested conditional is there in case the character can't move in the specified direction because of an obstruction. If it can't, the character moves away from the player in the Y direction, so long as the character's Y coordinate is different from the player. If sy.abs > sx.abs, then the character moves in the Y direction (or the X direction if there's an obstruction).
Move_Forward
Arguments: None
Local Variables: None
How it Works: Moves the character in the direction it is currently facing by calling the approprite movement method.
Move_Backward
Arguments: None
Local Variables: None
How it Works: Moves the character in the direction opposite of its current facing by calling the approprite movement method. Note that this method doesn't change the character's facing.
Jump
Arguments:
X_Plus: The number of tiles to jump in the X direction.
Y_Plus: The number of tiles to jump in the Y direction.
Local Variables:
New_X: The destination X coordinate.
New_Y: The destination Y coordinate.
How it Works: Causes the character to begin a jump, disregarding the passability of all tiles except the destination tile. The first part of the method decides which way to turn the character prior to jumping. If x_plus.abs > y_plus.abs, then the character will turn left if x_plus is negative. If x_plus is positive, the character will turn left. If y_plus.abs >= x_plus.abs, then the character will turn up if y_plus is negative or turn down if it is positive. Next, the jump destination is set and checked for passability. If the new destination is valid, then the character is straightened and the character's tile coordinates (but not real coordinates) are updated to those of the destination tile. The distance of the jump is then found by using the Pythagorean Theorem to find the length of the hypoteneuse of the right triangle formed by the change in X coordinate, the change in Y coordinate, and the change in both X and Y coordinate. The jump peak is then computed by adding 10 and the distance, and then subtracting the character's move speed. The jump count is then set to twice the jump peak. The jump count and jump peak are used in the update_jump method to compute the slope of the jump line. The stop count is then reset to 0 so that the character's animation won't update during the jump.
Turn_Down
Arguments: None
Local Variables: None
How it Works: Changes the character's facing to 2 (down) unless the character has the "Direction Fix" property.
Turn_Left
Arguments: None
Local Variables: None
How it Works: Changes the character's facing to 4 (left) unless the character has the "Direction Fix" property.
Turn_Right
Arguments: None
Local Variables: None
How it Works: Changes the character's facing to 6 (right) unless the character has the "Direction Fix" property.
Turn_Up
Arguments: None
Local Variables: None
How it Works: Changes the character's facing to 8 (up) unless the character has the "Direction Fix" property.
Turn_Right_90
Arguments: None
Local Variables: None
How it Works: Turns the character right 90 degrees. If the character is currently facing down, it turns left. If the character is currently facing left, it turns up. If the character is facing up, it turns right. If the character is facing right, it turns down.
Turn_Left_90
Arguments: None
Local Variables: None
How it Works: Turns the character left 90 degrees. If the character is currently facing down, it turns right. If the character is currently facing left, it turns down. If the character is facing up, it turns left. If the character is facing right, it turns up.
Turn_180
Arguments: None
Local Variables: None
How it Works: Turns the character 180 degrees. If the character is currently facing down, it turns up. If the character is currently facing left, it turns right. If the character is facing up, it turns down. If the character is facing right, it turns left.
Turn_Right_or_Left_90
Arguments: None
Local Variables: None
How it Works: Chooses a random number between 0 and 1. On a result of 0, the turn_right_90 method is called. On a result of 1, the turn_left_90 method is called.
Turn_Random
Arguments: None
Local Variables: None
How it Works: The character faces a random direction. A random number between 0 and 3 is generated. On a result of 0, the character faces up. On a result of 1, the character faces right. On a result of 2, the character faces left. On a result of 3, the character faces down.
Turn_Toward_Player
Arguments: None
Local Variables: None
sx: The difference in tiles between the X coordinate of the player and the X coordinate of the character.
sy: The difference in tiles between the Y coordinate of the player and the Y coordinate of the character.
How it Works: How it Works: Makes the character turn toward the player. The sx = @x - $game_player.x and sy = @y - $game_player.y statements determine the character's spatial relationship with the player. If both sx and sy are both 0 (the character being moved is the player), then the method returns without doing anything. The method then takes the absolute value of those values to determine whether the character is further away from the player in the X direction or the Y direction. The next part of the method checks to see if sx.abs > sy.abs. If it is, then it checks whether the raw value of sx is positive or negative. If the value is positive, then the character turns left. Otherwise, it turns right. If sy.abs >= sx.abs. If it is, then it checks whether the raw value of sy is positive or negative. If the value is positive, the character turns up. Otherwise, it turns down.
Turn_Away_From_Player
Arguments: None
Local Variables: None
sx: The difference in tiles between the X coordinate of the player and the X coordinate of the character.
sy: The difference in tiles between the Y coordinate of the player and the Y coordinate of the character.
How it Works: How it Works: Makes the character turn away from the player. The sx = @x - $game_player.x and sy = @y - $game_player.y statements determine the character's spatial relationship with the player. If both sx and sy are both 0 (the character being moved is the player), then the method returns without doing anything. The method then takes the absolute value of those values to determine whether the character is further away from the player in the X direction or the Y direction. The next part of the method checks to see if sx.abs > sy.abs. If it is, then it checks whether the raw value of sx is positive or negative. If the value is positive, then the character turns right. Otherwise, it turns left. If sy.abs >= sx.abs. If it is, then it checks whether the raw value of sy is positive or negative. If the value is positive, the character turns down. Otherwise, it turns up.
|
|