Movimentando O Herói Com O Mouse No RMXP
Publicado em 9 de setembro de 2011.Anlog Movment é um script desenvolvido por Near Fantastica, para o RPG Maker XP que permite um projeto sendo feito nessa ferramenta tenha o controle de movimento feito pelo mouse, onde o herói segue a setinha deste periférico. As setinhas ainda funcionam, mas no momento em que estas teclas são soltas, o herói segue a setinha automaticamente.
Eliminando a necessidade de usar as setinhas, o game pode ficar mais relax, permitindo que o jogador use apenas o mouse para movimentar. Também pode ser interessante em jogos onde tenha mais ação.
O Anlog Movment precisa do Mouse Input Module (também de Near Fantastica) e RMXP Standard Development Kit (SDK), (dele e outros autores). Ambos já estão no minigame, disponível para download aqui.
#==============================================================================
# ** Anlog Movment
#------------------------------------------------------------------------------
# Near Fantastica
# Version 1
# 01.03.06
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Anlog Movment", "Near Fantastica", 1, "01.03.06")
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Anlog Movment") == true
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
alias nf_anlogmovement_scene_map_main_loop main_loop
#--------------------------------------------------------------------------
# * Main Loop
#--------------------------------------------------------------------------
def main_loop
#Update Mouse
Mouse.update
nf_anlogmovement_scene_map_main_loop
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias nf_anlogmovement_game_character_update_movement update_movement
#--------------------------------------------------------------------------
# * Update Movement
#--------------------------------------------------------------------------
def update_movement
nf_anlogmovement_game_character_update_movement
# 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 4 # move_toward_target
x,y = Mouse.grid
return if x == nil or y == nil
move_toward_target(x, y)
end
end
end
#--------------------------------------------------------------------------
# * Move object toward target
#--------------------------------------------------------------------------
def move_toward_target(x, y)
# Get difference in player coordinates
sx = @x - x
sy = @y - y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move towards player, prioritize left and right directions
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# If vertical distance is longer
else
# Move towards player, prioritize up and down directions
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
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
#--------------------------------------------------------------------------
alias nf_anlogmovement_game_player_update_player_movement update_player_movement
#--------------------------------------------------------------------------
# * Player Movement Update
#--------------------------------------------------------------------------
def update_player_movement
anlog_movement
nf_anlogmovement_game_player_update_player_movement
end
#--------------------------------------------------------------------------
# * Anlog Movement
#--------------------------------------------------------------------------
def anlog_movement
@move_type = 4
x,y = Mouse.grid
return if x == nil or y == nil
sx = @x - x
sy = @y - y
abs_sx = sx.abs
abs_sy = sy.abs
distance = (abs_sx + abs_sy) / 2
case distance
when 0..1
@move_speed = 3
when 2..8
@move_speed = 4
end
end
end
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
endDownload e ficha técnica
- Download (clique com o botão esquerdo do mouse ou toque no link)
- Desenvolvedor, publisher e/ou distribuidor: Near Fantastica
- Sistema(s): Windows 98/98SE/Me/2000/XP/Vista/7
- Tamanho: 204 KB (pacote de instalação e/ou espaço em disco)
- Licença: Gratuita
- Categoria: Programação XP
- Adicionado por: LichKing
- Acessos: 95
Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Acesse aqui e saiba como. Obrigado!
