It is currently Wed May 23, 2012 1:03 am

All times are UTC - 6 hours



Welcome
Welcome to icugigasoft

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!





 Page 1 of 1 [ 5 posts ] 
Author Message
 Post subject: Turn Diagonal Direction command
PostPosted: Wed Oct 19, 2011 1:59 pm 
Senior Member
Senior Member
User avatar

Joined: Sat May 22, 2010 8:24 pm
Posts: 412
Location: Obvious exits are: North, South, and uh... Dennis
So, for a game working on in RMVX, I'm using this script for 8-directional movement:
Spoiler:
#==============================================================================
# 8 Way Directional Movement
#------------------------------------------------------------------------------
# Kylock
# 21.3.2008
# Version 1.1
#==============================================================================
# Special thanks to Arrow-1 for the script request and supplying sprites for
# testing purposes.
#==============================================================================
# Instructions:
# Add this script towards the top, since methods are rewritten and not
# aliased. Once you add it and run your game, the script will
# automagically enable 8-way directional movement for your hero.
# Features:
# * Added movement functionality to allow your hero to move in diagonal
# directions
# * Corrects directional issues resulting from trying to activate events
# while facing a diaganol direction. (could be better implemented,
# but does work as it is)
#==============================================================================
# Changelog
# 1.0 Initial Release
# 1.1 Added support for no custom sprites and added compatibility with
# Anaryu's Anti-Lag script (must be loaded above the anti-lag script)
#==============================================================================

#==============================================================================
# ** Script Configuration
#==============================================================================
module KMDM
DIRSPRITE = true # set to true if you are using a custom
# character sprite for diagonal movement
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# rewrote def move_by-input to enable extra directions
#==============================================================================

class Game_Player < Game_Character
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
case Input.dir8
when 1; move_lower_left
when 2; move_down
when 3; move_lower_right
when 4; move_left
when 7; move_upper_left
when 6; move_right
when 8; move_up
when 9; move_upper_right
end
end
end

#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# Corrects direction so events will respond when hero is facing diagonal.
# Modifies: def move_lower_left, def move_lower_right, def move_upper_left,
# and def move_upper_right
#==============================================================================

class Game_Character
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left(turn_ok = true)
set_direction(5)
if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
(passable?(@x-1, @y) and passable?(@x-1, @y+1))
@x -= 1
@y += 1
increase_steps
@move_failed = false
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right(turn_ok = true)
set_direction(3)
if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
(passable?(@x+1, @y) and passable?(@x+1, @y+1))
@x += 1
@y += 1
increase_steps
@move_failed = false
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left(turn_ok = true)
if KMDM::DIRSPRITE == true
set_direction(7)
else
set_direction(8)
end
if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
(passable?(@x-1, @y) and passable?(@x-1, @y-1))
@x -= 1
@y -= 1
increase_steps
@move_failed = false
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right(turn_ok = true)
set_direction(9)
if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
(passable?(@x+1, @y) and passable?(@x+1, @y-1))
@x += 1
@y -= 1
increase_steps
@move_failed = false
else
@move_failed = true
end
end
end

#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# Adds functionality for diagonal character sprites.
# Modifies: def update_src_rect
#==============================================================================

class Sprite_Character < Sprite_Base
#--------------------------------------------------------------------------
# * Update Transfer Origin Rectangle
#--------------------------------------------------------------------------
def update_src_rect
if @tile_id == 0
index = @character.character_index
#if the character is facing diagonally, use the second spriteset
if @character.direction % 2 != 0 && KMDM::DIRSPRITE == true
index = @character.character_index + 1
end
pattern = @character.pattern < 3 ? @character.pattern : 1
sx = (index % 4 * 3 + pattern) * @cw
sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end
end


and for cut scenes, I need to make a character turn diagonally. So I was wondering if anybody knows a way to make them do so, I'm thinking it could be done using the script function in the "Set Move Route" option, but my scripting knowledge is pretty much none, so if anybody knows what I need to do, it is much appreciated. :D



_________________
*Insert witty phrase here*
Offline
 Profile  
 
 Post subject: Re: Turn Diagonal Direction command
PostPosted: Wed Oct 19, 2011 2:09 pm 
Senior Member
Senior Member
User avatar

Joined: Sun Nov 01, 2009 7:38 pm
Posts: 4323
I can't test it out myself, but you might be able to do something like
Move Event -> Script -> @event.set_direction(x), where x is the direction from 1 to 8 i think.
if it's the player, $game_player.set_direction


Offline
 Profile  
 
 Post subject: Re: Turn Diagonal Direction command
PostPosted: Wed Oct 19, 2011 2:31 pm 
Senior Member
Senior Member
User avatar

Joined: Sat May 22, 2010 8:24 pm
Posts: 412
Location: Obvious exits are: North, South, and uh... Dennis
It works for the player, but not for events, for some reason, when it's used on an event, it says that "set_direction" is an undefined method.



_________________
*Insert witty phrase here*
Offline
 Profile  
 
 Post subject: Re: Turn Diagonal Direction command
PostPosted: Wed Oct 19, 2011 3:38 pm 
Senior Member
Senior Member
User avatar

Joined: Sun Nov 01, 2009 7:38 pm
Posts: 4323
That's because "@event" isn't the appropriate object.
You could try $game_map.events.keys[@event_id] instead of @event.
I just can't remember off the top of my head and I don't have VX right now.


Offline
 Profile  
 
 Post subject: Re: Turn Diagonal Direction command
PostPosted: Wed Oct 19, 2011 5:14 pm 
Senior Member
Senior Member
User avatar

Joined: Sat May 22, 2010 8:24 pm
Posts: 412
Location: Obvious exits are: North, South, and uh... Dennis
So apparently It's only necessary to say "set_direction(x)", but I was being an idiot and forgot to set the move route to the event itself, though in my defense, I haven't used Rpg Maker in a looooong time. But anyways, thanks for the help!



_________________
*Insert witty phrase here*
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

cron

suspicion-preferred