#==============================================================================# # # # # # AUTO-TELEPORT # # # # # #==============================================================================# # # #Vincentmhd # #http://vincentmhdmaker.canalblog.com/ # #10/2/2010 # # # # # #-------------------------------------NOTE-------------------------------------# # # # Ce script permet d'ordonner les cartes les une par rapport aux autres. # #De créer les liens de téléportation automatiquement. # # # #==============================================================================#
module Mhd_TP SWITCH = 1 #Id du switch active ou désactive le script X_ID = 2 #Id de la variable correspondante Y_ID = 3 #Id de la variable coorespondante SET_ID = 1 #Id de la variable correspondante #------------------------------------------------------------------------------# # # # Les sets et les matrices de maps # # # #------------------------------------------------------------------------------# SET_MAP = [ #Set n°0: { "Matrice" => [ [1, 4, 6], [2, 3, 5], [7, 8, 9], [12,10,11] ], "Unlimited?" => true #boucle la matrice #et saute les "nil" } ]
#------------------------------------------------------------------------------# # # # Gestions des collisions # # # #------------------------------------------------------------------------------#
COLISION = true # false : les colisions entre les différentes maps ne sont pas gérées # true : les colisions sont bloquantes, elles empêchent les changements de map end
#==============================================================================# # # # # # AUTO-TELEPORT # # # # # #==============================================================================# # # #Vincentmhd # #http://vincentmhdmaker.canalblog.com/ # #10/2/2010 # # # # # #-------------------------------------NOTE-------------------------------------# # # # Classe du gestionnaire. # # # #==============================================================================#
class Auto_Tp
attr_reader :m_x attr_reader :m_y attr_reader :set
#------------------------------------------------------------------------------# # # # Initialisation # # # #------------------------------------------------------------------------------# def initialize() #prochaine map @next_map = Game_Map.new #Coordonnées matricielles @m_x = 0 @m_y = 0 @set = 0 $game_variables[Mhd_TP::X_ID] = @m_x $game_variables[Mhd_TP::Y_ID] = @m_y $game_variables[Mhd_TP::SET_ID] = @set #coordonnées physiques de destination @d_x = 0 @d_y = 0
@transfert = true end
#------------------------------------------------------------------------------# # # # Attribut les coordonnées # # # #------------------------------------------------------------------------------# def set_coord(x,y, set =0) @m_x = x @m_y = y @set = set end
#------------------------------------------------------------------------------# # # # Crée une map légère, pour tester la prochaine map. # # # #------------------------------------------------------------------------------# def create_map(map_id) @next_map.rapid_setup(map_id) end
#------------------------------------------------------------------------------# # # # Choisi la map # # # #------------------------------------------------------------------------------# def map_choice(direction) x = @m_x y = @m_y case direction when 2 #Si la coordonnée y est possible if !(Mhd_TP::SET_MAP[@set]["Matrice"][y+1].nil?) #si le couple de coordonnée coordonnée [x,y] est possible if !(Mhd_TP::SET_MAP[@set]["Matrice"][y+1][x].nil?) y +=1 possible = true else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true y += 1 y %= Mhd_TP::SET_MAP[@set]["Matrice"].size() while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) y += 1 y %= Mhd_TP::SET_MAP[@set]["Matrice"].size() end possible = true else possible = false end end else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true y += 1 y %= Mhd_TP::SET_MAP[@set]["Matrice"].size() #le problème vient de ["Matrice"].size() while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) y += 1 y %= Mhd_TP::SET_MAP[@set]["Matrice"].size() end possible = true else possible = false end end when 4 if (x-1 >= 0)&&(Mhd_TP::SET_MAP[@set]["Matrice"][y][x-1] != nil) x -=1 possible = true else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true x -= 1 x %= Mhd_TP::SET_MAP[@set]["Matrice"][y].size() if x < 0 x += (Mhd_TP::SET_MAP[@set]["Matrice"][y].size()) end while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) x -= 1 x %= Mhd_TP::SET_MAP[@set]["Matrice"][y].size() if x < 0 x += (Mhd_TP::SET_MAP[@set]["Matrice"][y].size()) end end possible = true else possible = false end end when 6 if (Mhd_TP::SET_MAP[@set]["Matrice"][y][x+1] != nil) x +=1 possible = true else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true x += 1 x %= Mhd_TP::SET_MAP[@set]["Matrice"][y].size() while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) x += 1 x %= Mhd_TP::SET_MAP[@set]["Matrice"][y].size() end possible = true else possible = false end end when 8 #si y -1 est possible if (y - 1 >= 0)&&(Mhd_TP::SET_MAP[@set]["Matrice"][y-1] != nil) #si le couple de coordonnée coordonnée [x,y-1] est possible if !(Mhd_TP::SET_MAP[@set]["Matrice"][y-1][x].nil?) y -=1 possible = true else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true y -= 1 y %= (Mhd_TP::SET_MAP[@set]["Matrice"].size()) if y < 0 y += (Mhd_TP::SET_MAP[@set]["Matrice"].size()) end while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) y -= 1 y %= Mhd_TP::SET_MAP[@set]["Matrice"].size() if y < 0 y += (Mhd_TP::SET_MAP[@set]["Matrice"].size()) end end possible = true else possible = false end end else if Mhd_TP::SET_MAP[@set]["Unlimited?"] == true y -= 1 y %= (Mhd_TP::SET_MAP[@set]["Matrice"].size()) if y < 0 y += (Mhd_TP::SET_MAP[@set]["Matrice"].size()) end while (Mhd_TP::SET_MAP[@set]["Matrice"][y][x] == nil) y -= 1 y %= (Mhd_TP::SET_MAP[@set]["Matrice"].size()) if y < 0 y += (Mhd_TP::SET_MAP[@set]["Matrice"].size()) end end possible = true else possible = false end end end id = Mhd_TP::SET_MAP[@set]["Matrice"][y][x] if id != nil create_map(id) else print("Ceci est un bug du Auto_Tp, repérez bien les conditions du bug! \n Vous pouvez continuer à jouer, cependant la map n'est pas accessible par ce chemin...") print("informations de matrice: x = " + x.to_s + " y = " + y.to_s) possible = false end
result = {"next_map" => id, "transfers" => possible, "@m_x" => x, "@m_y" => y} return result end
#------------------------------------------------------------------------------# # # #Choisi la future map , la direction et la position du joueur # # # #------------------------------------------------------------------------------# def tp_choice(direction) result = map_choice(direction) #Gestion des collisions if result["transfers"] case direction #détermination des coordonnées suivantes when 2 @d_x = $game_player.x @d_y = 0 when 4 @d_x = (@next_map.width() -1) @d_y = $game_player.y when 6 @d_x = 0 @d_y = $game_player.y when 8 @d_x = $game_player.x @d_y = (@next_map.height() -1) end if Mhd_TP::COLISION if (@next_map.passable?(@d_x,@d_y)) @transfert = result["transfers"] else @transfert = false end else @transfert = result["transfers"] end #si téléportation, on réserve... if @transfert == true @m_x = result["@m_x"] @m_y = result["@m_y"] $game_variables[Mhd_TP::X_ID] = @m_x $game_variables[Mhd_TP::Y_ID] = @m_y $game_variables[Mhd_TP::SET_ID] = @set $game_player.auto_tp_reserve_transfer(result["next_map"], @d_x, @d_y, direction) end end end
def teleportation(set, m_x, m_y, y, x, direction, active = true) id_map = Mhd_TP::SET_MAP[@set]["Matrice"][m_y][m_x] if id_map != nil @set = set @m_x = m_x @m_y = m_y $game_switches[Mhd_TP::SWITCH] = active $game_player.auto_tp_reserve_transfer(id_map, x, y, direction) else print("Erreur de coordonnées matricielles ou de set, vérifiez vos données") end end
#------------------------------------------------------------------------------# # # #Teste s'il y a téléportation avant le mouvement # # # #------------------------------------------------------------------------------# def down_cond if $game_switches[Mhd_TP::SWITCH] == true if ($game_player.y==($game_map.height() -1))&&(!$game_map.loop_vertical?()) tp_choice(2) end end end def left_cond if $game_switches[Mhd_TP::SWITCH] == true if ($game_player.x==0)&&(!$game_map.loop_horizontal?()) tp_choice(4) end end end def right_cond if $game_switches[Mhd_TP::SWITCH] == true if ($game_player.x==($game_map.width() -1))&&(!$game_map.loop_horizontal?()) tp_choice(6) end end end def up_cond if $game_switches[Mhd_TP::SWITCH] == true if ($game_player.y==0)&&(!$game_map.loop_vertical?()) tp_choice(8) end end end
#------------------------------------------------------------------------------# # # # Changement de Set manuellement # # # #------------------------------------------------------------------------------# def tp_set(set) @set = set $game_variables[Mhd_TP::SET_ID] = @set id = Mhd_TP::SET_MAP[@set]["Matrice"][@m_y][@m_x] create_map(id) coord = replace #$game_map.setup(id) #$game_player.moveto(@d_x, @d_y) $game_player.auto_tp_reserve_transfer(id, @d_x, @d_y, $game_player.direction) end
#------------------------------------------------------------------------------# # # # Renvois les coordonnées d'une case dans la direction donné au rayon donné. # # # #------------------------------------------------------------------------------# #2: down, 4: left, 6: right, 8: up # 5 8 7 # 4 6 # 3 2 1 def coord?(coord, direction, rayon = 1) case(direction) when 1 coord[1] +=rayon coord[0] +=rayon when 2 coord[1] +=rayon when 3 coord[1] +=rayon coord[0] -=rayon when 4 coord[0] -=rayon when 5 coord[0] -=rayon coord[1] -=rayon when 6 coord[0] +=rayon when 7 coord[0] +=rayon coord[1] -=rayon when 8 coord[1] -=rayon else coord = nil end return coord end #------------------------------------------------------------------------------# # # # Si entre 2 sets liés, il y a une différence de passabilité, le script # # décale le joueur de quelques cases. # # # #------------------------------------------------------------------------------# def replace x = $game_player.x y = $game_player.y if(!@next_map.passable?(x, y)) cherche = true rayon = 0 while cherche direction = 1 x = $game_player.x y = $game_player.y while direction <=8 coord = coord?([$game_player.x,$game_player.y], direction, rayon) x = coord[0] y = coord[1] if (x>= 0) && (y>= 0) && (y< @next_map.height() ) && (x< @next_map.width() ) if(@next_map.passable?(x, y)) direction = 9 #arrêt première boucle cherche = false #arrêt seconde boucle end end direction += 1 end rayon +=1 end end @d_x = x @d_y = y end #------------------------------------------------------------------------------# # # # Actualise la valeur des variables internes par les externes # # # #------------------------------------------------------------------------------# def refresh @m_x = $game_variables[Mhd_TP::X_ID] @m_y = $game_variables[Mhd_TP::Y_ID] @set = $game_variables[Mhd_TP::SET_ID] end end
class Game_Player #------------------------------------------------------------------------------# # # # Surcharges des commandes du players pour tester si tranfert de map # # # #------------------------------------------------------------------------------# alias tp_move_down move_down def move_down(turn_ok = true) $game_tp.down_cond tp_move_down(turn_ok) end alias tp_move_left move_left def move_left(turn_ok = true) $game_tp.left_cond tp_move_left(turn_ok) end alias tp_move_right move_right def move_right(turn_ok = true) $game_tp.right_cond tp_move_right(turn_ok) end alias auto_tp_move_up move_up def move_up(turn_ok = true) $game_tp.up_cond auto_tp_move_up(turn_ok) end #------------------------------------------------------------------------------# # # # Réservation de la téléportation # # # #------------------------------------------------------------------------------# def auto_tp_reserve_transfer(map_id, x, y, direction) reserve_transfer(map_id, x, y, direction) @tp_force_setup = true end #------------------------------------------------------------------------------# # # # Téléportation en cours # # # #------------------------------------------------------------------------------# alias tp_perform_transfer perform_transfer def perform_transfer if @tp_force_setup != nil if @tp_force_setup == true return unless @transferring @transferring = false set_direction(@new_direction) $game_map.setup(@new_map_id) moveto(@new_x, @new_y) else tp_perform_transfer end else tp_perform_transfer end @tp_force_setup = false end
end
class Game_Map #------------------------------------------------------------------------------# # # # Création de maps + légères pour faire des tests # # # #------------------------------------------------------------------------------# def rapid_setup (map_id) @map = load_data(sprintf("Data/Map%03d.rvdata", map_id)) @passages = $data_system.passages setup_events end
#------------------------------------------------------------------------------# # # # Mise à jour des coordonnées de la matrice # # # #------------------------------------------------------------------------------# alias setup_map_mhd setup def setup(map_id) setup_map_mhd(map_id) $game_tp.refresh end end
class Scene_Title #------------------------------------------------------------------------------# # # # Initialisation du gestionnaire # # # #------------------------------------------------------------------------------# alias tp_create_game_objects create_game_objects def create_game_objects tp_create_game_objects $game_tp = Auto_Tp.new end end
|