Well I'm almost done with the movement script, only need one more class to actually finish it, but I can't get this part to stop error-ing.
I have a feeling it's because of some extra end's that might be there. This script is basically two scripts that I would like combined, which normally would not work together.
Unfortunately I don't have much time left. I have to finish my programming assignment today, and write a few pages for my sociology paper. I also have to read 2 chapters for a history exam, and study for my programming exam, so I am swamped for the week...
If anyone could please get this part fixed up, I will finish it hopefully this weekend :P
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Zexion's Movement & Animation Script
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Instructions:
# If you want 8-directional movement, set the below to true otherwise set to
# false.
#
# The standing pose is the first pose of the characterset. Default style rtp
# does not need a standing pose. This could be used to make charsets smaller.
#
# For a standard charset, no mod is needed:
# Charset.png
#
# For a charset with more walking frames:
# Charset_cs[5].png
#
# For a charset with vertical correction: (Fixes the charset appearing "too high")
# Charset_v[50].png [50] is the y offset of the graphic. Must be POSITIVE
#
# For a charset with 8-directional poses:
# Charset_iso.png
#
# You can use one or all of the tags. (Two is fine also, haha.)
# Charset_cs[8]_v[50]_iso.png
# That is the setup for an isometric charset with a vertical correction of 50
# and 8 walking frames.
# (if you need a vertical correction of 50, you should prob edit the charset XD)
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Configuration
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
module ANIM_DATA
iso_tag = "iso" # Tag for 8 pose charset.
eight_dir = true # Does not require certain number
# of frames, or custom charset.
standing_frame = true # This uses the first pose as
# a standing pose. Useful for
# larger animation sheets.
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# Dirtie
# 16th December 2006
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Game_Character
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
#--------------------------------------------------------------------------
# * Get Vertical Adjustment for Character Graphic
#--------------------------------------------------------------------------
def character_adjust_y
@character_name.gsub(/v\_(\d+)/) do
if $1 != @character_name
return $1.to_i
end
end
return nil
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# End of section by: Dirtie
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# DerVVulfman
# With small edits by Zexion to allow custom amounts of frames.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :step_anime # Holds a sprite's step flag
attr_reader :walk_anime # Holds an event's movement flag
attr_reader :stop_count # The number of steps left to count
attr_reader :jump_count # The number of steps in a jump
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % self.character_frames
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left
# If no direction fix
unless @direction_fix
turn_down_left
end
# When a down to left or a left to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# Update coordinates
@x -= 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right
# If no direction fix
unless @direction_fix
turn_down_right
end
# When a down to right or a right to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# Update coordinates
@x += 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left
# If no direction fix
unless @direction_fix
turn_up_left
end
# When an up to left or a left to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# Update coordinates
@x -= 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right
# If no direction fix
unless @direction_fix
turn_up_right
end
# When an up to right or a right to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# Update coordinates
@x += 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Turn Up Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::iso_tag)
@direction = 7
else
# Face left if facing right, and face up if facing down
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Up Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::iso_tag)
@direction = 9
else
# Face right if facing left, and face up if facing down
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::iso_tag)
# Face down-left
@direction = 1
else
# Face down is facing right or up
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::iso_tag)
@direction = 3
else
# Face right if facing left, and face down if facing up
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
end
end
#------------------------------------------------------------------------
# * Move Random
#------------------------------------------------------------------------
def move_random
case rand(8)
when 0 ; move_down(false)
when 1 ; move_left(false)
when 2 ; move_right(false)
when 3 ; move_up(false)
when 4 ; move_lower_left
when 5 ; move_lower_right
when 6 ; move_upper_left
when 7 ; move_upper_right
end
end
#------------------------------------------------------------------------
# * Move Toward Player
#------------------------------------------------------------------------
def move_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_upper_right if sx < 0 and sy > 0
move_upper_left if sx > 0 and sy > 0
move_lower_left if sx > 0 and sy < 0
move_lower_right if sx < 0 and sy < 0
move_right if sx < 0
move_left if sx > 0
move_up if sy > 0
move_down if sy < 0
end
end
#------------------------------------------------------------------------
# * Move Away from Player
#------------------------------------------------------------------------
def move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_lower_left if sx < 0 and sy > 0
move_lower_right if sx > 0 and sy > 0
move_upper_right if sx > 0 and sy < 0
move_upper_left if sx < 0 and sy < 0
move_left if sx < 0
move_right if sx > 0
move_down if sy > 0
move_up if sy < 0
end
end
#--------------------------------------------------------------------------
# * Set Custom Animation
#--------------------------------------------------------------------------
def set_custom_anim
return if @animating
@frame_count = self.character_frames
@animating = true
@anim_wait = 40
@pattern = 0
@direction_fix = true
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character # character
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : character (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
if @character.character_name.include?(ANIM_DATA::iso_tag)
if ANIM_DATA::standing_frame == true
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 8
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 8
end
else
if ANIM_DATA::standing_frame == true
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 4
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 4
end
end
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# If a iso character in use
if @character.character_name.include?(ANIM_DATA::iso_tag)
if not @character.step_anime and @character.stop_count > 0
sx = (@character.pattern) * @cw
else
# If event's Movement flag is checked (or player sprite)
if @character.walk_anime
# Set rectangular transfer
if ANIM_DATA::standing_frame
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
end
# Otherwise, normal control
else
sx = @character.pattern * @cw
end
# Basic direction value
dir = @character.direction
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::iso_tag)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
Btw, When I'm done the features will be:
- Optional 8-directional movement
- Optional 8-pose charset
- Optional first frame standing pose
- A custom amount of frames per charset
- Vertical correction if needed
Extra 'end' in this chunk in Sprite_Character:
# If graphic is character
if @tile_id == 0
# If a iso character in use
if @character.character_name.include?(ANIM_DATA::iso_tag)
if not @character.step_anime and @character.stop_count > 0
sx = (@character.pattern) * @cw
else
# If event's Movement flag is checked (or player sprite)
if @character.walk_anime
# Set rectangular transfer
if ANIM_DATA::standing_frame
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
end
# Otherwise, normal control
else
sx = @character.pattern * @cw
end
# Basic direction value
dir = @character.direction
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::iso_tag)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
end # <====?
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end # <====?
It's so wierd, if I remove those two, it causes syntax errors pointing to the last end. Then I have to add 2 more ends for it to work, and then it gives me random errors like undefined blah, even though they are defined :P
I was only pointing to two ends because I wasn't sure what you wanted.
Anyways, I think it's this end you want removed:
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
end #<===== DELETE
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
And you need one more end at the very bottom to finish the class.
It's all fixed now thanks, again KK20 :P
If you keep fixing everything, I might as well put you as a developer on my game haha.
I also forgot that it doesn't let me use lowercase names for the variables in a module. Idk why, that is kinda dumb :P
Hah, I'd like that 8)
It's a matter of constants and local variables. As soon as the first letter in a variable name is capitalized, it's treated as a constant. As to why you can't use local variables to access values in a module:
Quote from: RMXP Help FileIdentifiers beginning with a lowercase letter or '_' are local variables or method calls.
Within a local variable's scope (classes, modules, method definitions), the initial assignment to an identifier beginning with lowercase letters is the declaration of that scope's local variable. Referencing undeclared identifiers (like using '::') is considered a call to a method with no arguments.
If you were to do
def self.iso_var; return "iso"; end it would work.
But that is so ew, and not pretty :P
I finished the script, but I found some pretty huge bugs lol. Only 2 though.
Sprite faces the wrong direction, and the walking animation plays the standing frame if you have standing frame == true.
If you wanna take a look :P
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Zexion's Movement & Animation Script
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Instructions:
# If you want 8-directional movement, set the below to true otherwise set to
# false.
#
# The standing pose is the first pose of the characterset. Default style rtp
# does not need a standing pose. This could be used to make charsets smaller.
#
# For a standard charset, no mod is needed:
# Charset.png
#
# For a charset with more walking frames:
# Charset_cs[5].png
#
# For a charset with vertical correction: (Fixes the charset appearing "too high")
# Charset_v[50].png [50] is the y offset of the graphic. Must be POSITIVE
#
# For a charset with 8-directional poses:
# Charset_iso.png
#
# You can use one or all of the tags. (Two is fine also, haha.)
# Charset_cs[8]_v[50]_iso.png
# That is the setup for an isometric charset with a vertical correction of 50
# and 8 walking frames.
# (if you need a vertical correction of 50, you should prob edit the charset XD)
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Configuration
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
module ANIM_DATA
ISO_TAG = "iso" # Tag for 8 pose charset.
EIGHT_DIR = true # Does not require certain number
# of frames, or custom charset.
STANDING_FRAME = true # This uses the first pose as
# a standing pose. Useful for
# larger animation sheets.
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# Dirtie
# 16th December 2006
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Game_Character
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
#--------------------------------------------------------------------------
# * Get Vertical Adjustment for Character Graphic
#--------------------------------------------------------------------------
def character_adjust_y
@character_name.gsub(/v\_(\d+)/) do
if $1 != @character_name
return $1.to_i
end
end
return nil
end
end
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Graphic (modified lines marked)
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_actor_graphic(actor, x, y)
bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
cw = bitmap.width / actor.character_frames
if ANIM_DATA::EIGHT_DIR == true
ch = bitmap.height / 8
else
ch = bitmap.height / 4
end
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# End of section by: Dirtie
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# DerVVulfman
# With small edits by Zexion to allow custom amounts of frames.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :step_anime # Holds a sprite's step flag
attr_reader :walk_anime # Holds an event's movement flag
attr_reader :stop_count # The number of steps left to count
attr_reader :jump_count # The number of steps in a jump
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % self.character_frames
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left
# If no direction fix
unless @direction_fix
turn_down_left
end
# When a down to left or a left to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# Update coordinates
@x -= 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right
# If no direction fix
unless @direction_fix
turn_down_right
end
# When a down to right or a right to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# Update coordinates
@x += 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left
# If no direction fix
unless @direction_fix
turn_up_left
end
# When an up to left or a left to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# Update coordinates
@x -= 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right
# If no direction fix
unless @direction_fix
turn_up_right
end
# When an up to right or a right to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# Update coordinates
@x += 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Turn Up Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 7
else
# Face left if facing right, and face up if facing down
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Up Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 9
else
# Face right if facing left, and face up if facing down
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
# Face down-left
@direction = 1
else
# Face down is facing right or up
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 3
else
# Face right if facing left, and face down if facing up
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
end
end
#------------------------------------------------------------------------
# * Move Random
#------------------------------------------------------------------------
def move_random
case rand(8)
when 0 ; move_down(false)
when 1 ; move_left(false)
when 2 ; move_right(false)
when 3 ; move_up(false)
when 4 ; move_lower_left
when 5 ; move_lower_right
when 6 ; move_upper_left
when 7 ; move_upper_right
end
end
#------------------------------------------------------------------------
# * Move Toward Player
#------------------------------------------------------------------------
def move_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_upper_right if sx < 0 and sy > 0
move_upper_left if sx > 0 and sy > 0
move_lower_left if sx > 0 and sy < 0
move_lower_right if sx < 0 and sy < 0
move_right if sx < 0
move_left if sx > 0
move_up if sy > 0
move_down if sy < 0
end
end
#------------------------------------------------------------------------
# * Move Away from Player
#------------------------------------------------------------------------
def move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_lower_left if sx < 0 and sy > 0
move_lower_right if sx > 0 and sy > 0
move_upper_right if sx > 0 and sy < 0
move_upper_left if sx < 0 and sy < 0
move_left if sx < 0
move_right if sx > 0
move_down if sy > 0
move_up if sy < 0
end
end
#--------------------------------------------------------------------------
# * Set Custom Animation
#--------------------------------------------------------------------------
def set_custom_anim
return if @animating
@frame_count = self.character_frames
@animating = true
@anim_wait = 40
@pattern = 0
@direction_fix = true
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character # character
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : character (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
if ANIM_DATA::STANDING_FRAME == true
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 8
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 8
end
else
if ANIM_DATA::STANDING_FRAME == true
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 4
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 4
end
end
self.ox = @cw / 2
if @character.character_adjust_y != nil
self.oy = @character.character_adjust_y
else
self.oy = @ch
end
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# If a iso character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
if not @character.step_anime and @character.stop_count > 0
sx = (@character.pattern) * @cw
else
# If event's Movement flag is checked (or player sprite)
if @character.walk_anime
# Set rectangular transfer
if ANIM_DATA::STANDING_FRAME
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
end
# Otherwise, normal control
else
sx = @character.pattern * @cw
end
# Basic direction value
dir = @character.direction
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================
class Game_Player < Game_Character
@@poin1 = 0
@@poin2 = 0
@@wait_time = 0
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :waiting
attr_accessor :wait_time
#------------------------------------------------------------------------
# * Update Character Movement
#------------------------------------------------------------------------
def update
last_moving = moving?
#----------------------------------------------------------------------
# * Movement Handling
#----------------------------------------------------------------------
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
if ANIM_DATA::EIGHT_DIR == true
case Input.dir8
when 1 ; move_lower_left
when 3 ; move_lower_right
when 7 ; move_upper_left
when 9 ; move_upper_right
when 2 ; move_down
when 4 ; move_left
when 6 ; move_right
when 8 ; move_up
end
else
case Input.dir4
when 2 ; move_down
when 4 ; move_left
when 6 ; move_right
when 8 ; move_up
end
end
end
#----------------------------------------------------------------------
# * Screen Positioning
#----------------------------------------------------------------------
last_real_x = @real_x
last_real_y = @real_y
super
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
$game_map.scroll_up(last_real_y - @real_y)
end
#----------------------------------------------------------------------
# * Encounter and Event Processing
#----------------------------------------------------------------------
unless moving?
if last_moving
result = check_event_trigger_here([1,2])
if result == false
unless $DEBUG and Input.press?(Input::CTRL)
@encounter_count -= 1 if @encounter_count > 0
end
end
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
#------------------------------------------------------------------------
# * Encounter and Event Processing
#------------------------------------------------------------------------
def idle_wait(duration, value)
for i in 0...duration
@@wait_time += 1 if value == false
break if i >= duration / 2
end
end
end
You don't HAVE to fix it though, I'll do it...eventually haha
Edit: Forgot to mention it only happens on charsets with "iso" in them. Standard 4 pose charsets aren't affected D:
Exactly the point :D Use them constants.
So you are talking about this?
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
From what I'm getting at, the character's spritesheet directions are in this order from top to bottom:
Down-left, Down, Down-right, Left, Up-left, Right, Up-right, Up
Not sure where I can go from there.
For problem 2:
if @character.walk_anime
# Set rectangular transfer
if ANIM_DATA::STANDING_FRAME
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
My guess is that you want to check first, after
if ANIM_DATA::STANDING_FRAME, if
@character.pattern == 0, and if it does,
@character.pattern += 1. You'll have to make 'pattern' an attr_accessor in Game_Character first. If you do this, you can remove the '+ 1' in
sx = (@character.pattern + 1) * @cw.
I'd test it for you, but I'm too lazy to make a charset.
That's the wierd thing... my charset is set up correctly D:
link: charset (https://dl.dropboxusercontent.com/u/59018752/Sora%20cs_8%20iso.png)
I'll test out the second part :P
Herp de derp. I should have cared to read further down the code.
# Basic direction value
dir = @character.direction
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch #<======= OMG LOL WE'RE COMPLETELY CHANGING sy EVERYTIME
self.src_rect.set(sx, sy, @cw, @ch)
end
Warning - while you were reading a new reply has been posted. You may wish to review your post.
LMFAO, I was literally about to post the same thing!
Edit: Also, removing the sx, and one of the repeated block transfers completely fixes it all :)
Completely fixed? Oh really? :V:
I'm still getting drawing issues if I have standing poses on with the RTP. It looks like it's not getting a wide enough rectangle for the bitmap transfer.
With any feature turned on, it applies to ALL character graphics, correct? Maybe some developers don't want some characters to be affected by the script?
Yeah, I noticed that, and turned it into a tag rather than a toggle for all. Now it's per charset, also added an animation speed control for animations higher than 6 which tend to appear slower due to more frames to cycle through. All is done :)
While I was creating a new animation to use for play testing, because I like to look stylish while play testing, I noticed that there was a critical error with this script... I've tried to fix it several ways, but I can't find what's bugging it out.
The problem is:
Although you can set any amount of frames per charset and it will always be correctly divided the actual animation that plays is horribly ruined.
I noticed this once I made the new animation and only 2 frames were being played, which is what it should do, but they were the wrong two frames. They were the standing frame and the first movement frame.
For some reason, though, the actual 8 frames that I wanted works perfectly fine.
Script:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Zexion's Movement & Animation Script
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Instructions:
# If you want 8-directional movement, set the below to true otherwise set to
# false.
#
# The standing pose is the first pose of the characterset. Default style rtp
# does not need a standing pose. This could be used to make charsets smaller.
#
# For a standard charset, no mod is needed:
# Charset.png
#
# For a charset with more walking frames:
# Charset cs_[5].png
#
# For a charset with a standing frame:
# Charset stn.png
#
# For a charset with vertical correction: (Fixes the charset appearing "too high")
# Charset v_[50].png [50] is the y offset of the graphic. Must be POSITIVE
#
# For a charset with 8-directional poses:
# Charset iso.png
#
# You can use one or all of the tags. (Two is fine also, haha.)
# Charset cs_[8] v_[50] iso stn.png
# That is the setup for an isometric charset with a vertical correction of 50
# and 8 walking frames.
# (if you need a vertical correction of 50, you should prob edit the charset XD)
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Configuration
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
module ANIM_DATA
ISO_TAG = "iso" # Tag for 8 pose charset.
EIGHT_DIR = true # Does not require certain number
# of frames, or custom charset.
STND_TAG = "stn" # This uses the first pose as
# a standing pose. Useful for
# larger animation sheets.
ANIMATION_SPEED = 3.5 # This speeds up walking animations
# when they are above 6 frames long
# Because they appear slower than
# normal walking animations.
# Leave at 3.5 for best results.
# Good ranges are 2-4
# Decimals are accepted
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# Dirtie
# 16th December 2006
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
end
class Game_Character
#--------------------------------------------------------------------------
# * Get Number of Frames for Character Graphic
#--------------------------------------------------------------------------
def character_frames
@character_name.gsub(/cs\_(\d)/) do
if $1 != @character_name
return $1.to_i
end
end
return 4
end
#--------------------------------------------------------------------------
# * Get Vertical Adjustment for Character Graphic
#--------------------------------------------------------------------------
def character_adjust_y
@character_name.gsub(/v\_(\d+)/) do
if $1 != @character_name
return $1.to_i
end
end
return nil
end
end
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Graphic (modified lines marked)
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_actor_graphic(actor, x, y)
bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
cw = bitmap.width / actor.character_frames
if ANIM_DATA::EIGHT_DIR == true
ch = bitmap.height / 8
else
ch = bitmap.height / 4
end
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# End of section by: Dirtie
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# This section by:
# DerVVulfman
# With small edits by Zexion to allow custom amounts of frames.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :step_anime # Holds a sprite's step flag
attr_reader :walk_anime # Holds an event's movement flag
attr_reader :stop_count # The number of steps left to count
attr_reader :jump_count # The number of steps in a jump
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if self.character_frames > 6
if @anime_count > 18 - @move_speed * ANIM_DATA::ANIMATION_SPEED
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % self.character_frames
end
# Clear animation count
@anime_count = 0
end
else
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % self.character_frames
end
# Clear animation count
@anime_count = 0
end
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left
# If no direction fix
unless @direction_fix
turn_down_left
end
# When a down to left or a left to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# Update coordinates
@x -= 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right
# If no direction fix
unless @direction_fix
turn_down_right
end
# When a down to right or a right to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# Update coordinates
@x += 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left
# If no direction fix
unless @direction_fix
turn_up_left
end
# When an up to left or a left to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# Update coordinates
@x -= 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right
# If no direction fix
unless @direction_fix
turn_up_right
end
# When an up to right or a right to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# Update coordinates
@x += 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Turn Up Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 7
else
# Face left if facing right, and face up if facing down
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Up Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_up_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 9
else
# Face right if facing left, and face up if facing down
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Left (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_left
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
# Face down-left
@direction = 1
else
# Face down is facing right or up
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
end
end
#--------------------------------------------------------------------------
# * Turn Down Right (Added for diagonal animation)
#--------------------------------------------------------------------------
def turn_down_right
unless @direction_fix
if @character_name.include?(ANIM_DATA::ISO_TAG)
@direction = 3
else
# Face right if facing left, and face down if facing up
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
end
end
#------------------------------------------------------------------------
# * Move Random
#------------------------------------------------------------------------
def move_random
case rand(8)
when 0 ; move_down(false)
when 1 ; move_left(false)
when 2 ; move_right(false)
when 3 ; move_up(false)
when 4 ; move_lower_left
when 5 ; move_lower_right
when 6 ; move_upper_left
when 7 ; move_upper_right
end
end
#------------------------------------------------------------------------
# * Move Toward Player
#------------------------------------------------------------------------
def move_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_upper_right if sx < 0 and sy > 0
move_upper_left if sx > 0 and sy > 0
move_lower_left if sx > 0 and sy < 0
move_lower_right if sx < 0 and sy < 0
move_right if sx < 0
move_left if sx > 0
move_up if sy > 0
move_down if sy < 0
end
end
#------------------------------------------------------------------------
# * Move Away from Player
#------------------------------------------------------------------------
def move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
return if sx == 0 and sy == 0
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
move_lower_left if sx < 0 and sy > 0
move_lower_right if sx > 0 and sy > 0
move_upper_right if sx > 0 and sy < 0
move_upper_left if sx < 0 and sy < 0
move_left if sx < 0
move_right if sx > 0
move_down if sy > 0
move_up if sy < 0
end
end
#--------------------------------------------------------------------------
# * Set Custom Animation
#--------------------------------------------------------------------------
def set_custom_anim
return if @animating
@frame_count = self.character_frames
@animating = true
@anim_wait = 40
@pattern = 0
@direction_fix = true
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character # character
attr_accessor :pattern
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : character (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
if @character.character_name.include?(ANIM_DATA::STND_TAG)
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 8
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 8
end
else
if @character.character_name.include?(ANIM_DATA::STND_TAG)
@cw = bitmap.width / (self.character_frames + 1)
@ch = bitmap.height / 4
else
@cw = bitmap.width / self.character_frames
@ch = bitmap.height / 4
end
end
self.ox = @cw / 2
if @character.character_adjust_y != nil
self.oy = @ch - @character.character_adjust_y
else
self.oy = @ch
end
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
if not @character.step_anime and @character.stop_count > 0
sx = (@character.pattern) * @cw
else
# If event's Movement flag is checked (or player sprite)
if @character.walk_anime
# Set rectangular transfer
if @character.character_name.include?(ANIM_DATA::STND_TAG)
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
end
# Otherwise, normal control
else
sx = @character.pattern * @cw
end
# Basic direction value
dir = @character.direction
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement.
sy = (dir - dec) * @ch
else
sy = (dir - 2) / 2 * @ch
end
# Typical block transfer
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================
class Game_Player < Game_Character
@@poin1 = 0
@@poin2 = 0
@@wait_time = 0
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :waiting
attr_accessor :wait_time
#------------------------------------------------------------------------
# * Update Character Movement
#------------------------------------------------------------------------
def update
last_moving = moving?
#----------------------------------------------------------------------
# * Movement Handling
#----------------------------------------------------------------------
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
if ANIM_DATA::EIGHT_DIR == true
case Input.dir8
when 1 ; move_lower_left
when 3 ; move_lower_right
when 7 ; move_upper_left
when 9 ; move_upper_right
when 2 ; move_down
when 4 ; move_left
when 6 ; move_right
when 8 ; move_up
end
else
case Input.dir4
when 2 ; move_down
when 4 ; move_left
when 6 ; move_right
when 8 ; move_up
end
end
end
#----------------------------------------------------------------------
# * Screen Positioning
#----------------------------------------------------------------------
last_real_x = @real_x
last_real_y = @real_y
super
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
$game_map.scroll_up(last_real_y - @real_y)
end
#----------------------------------------------------------------------
# * Encounter and Event Processing
#----------------------------------------------------------------------
unless moving?
if last_moving
result = check_event_trigger_here([1,2])
if result == false
unless $DEBUG and Input.press?(Input::CTRL)
@encounter_count -= 1 if @encounter_count > 0
end
end
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
#------------------------------------------------------------------------
# * Encounter and Event Processing
#------------------------------------------------------------------------
def idle_wait(duration, value)
for i in 0...duration
@@wait_time += 1 if value == false
break if i >= duration / 2
end
end
end
Example Charset:
Name this: "Cloak cs_2 stn"
Cloak cs_2 stn (https://dl.dropboxusercontent.com/u/59018752/Unknown%20-%20Hover%20cs_2%20stn.png)
# If graphic is character
if @tile_id == 0
# If a custom character in use
if @character.character_name.include?(ANIM_DATA::ISO_TAG)
if not @character.step_anime and @character.stop_count > 0
sx = (@character.pattern) * @cw
else
# If event's Movement flag is checked (or player sprite)
if @character.walk_anime
# Set rectangular transfer
if @character.character_name.include?(ANIM_DATA::STND_TAG)
sx = (@character.pattern + 1) * @cw
else
sx = @character.pattern * @cw
end
else
sx = @character.pattern * @cw
end
end
# Otherwise, normal control
else
sx = @character.pattern * @cw #<- Looks like it jumps straight to this if the charset doesn't have 'iso' in its filename
end
Oh wow I totally didn't read that part right...I thought it was to make the charset isometric lol. I should have known just by the sx.
Just removed it because it totally wasn't needed in my script