AccueilAccueil  PortailPortail  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  ConnexionConnexion  



Le Deal du moment :
Funko POP! Jumbo One Piece Kaido Dragon Form : ...
Voir le deal

Partagez
 

 [VXAce] Event Extender, Pathfinder

Voir le sujet précédent Voir le sujet suivant Aller en bas 
AuteurMessage
Invité
Invité
avatar



[VXAce] Event Extender, Pathfinder Empty
MessageSujet: [VXAce] Event Extender, Pathfinder   [VXAce] Event Extender, Pathfinder Icon_minitimeMar 11 Sep 2012 - 0:14

Création d'un nouveau module
Lien du code ici : https://github.com/Funkywork/Scripts-rm/blob/master/VXAce/EE-Pathfinder.rb
Code ici :
Code:
# Module Pathfinder par Grim (inspiré par Avygeil EL3.0)
# Détail des commandes
# cmd(:move_to, ID_EVENT, X, Y)
#==============================================================================
# ** Pathfinder
#------------------------------------------------------------------------------
#  Module to manage pathfinder
#==============================================================================

module Pathfinder
   #--------------------------------------------------------------------------
   # * Constants
   #--------------------------------------------------------------------------
   Goal = Struct.new(:x, :y)
   ROUTE_MOVE_DOWN = 1
   ROUTE_MOVE_LEFT = 2
   ROUTE_MOVE_RIGHT = 3
   ROUTE_MOVE_UP = 4
   #--------------------------------------------------------------------------
   # * Definition of a point
   #--------------------------------------------------------------------------
   class Point
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :x, :y, :g, :h, :f, :parent, :goal
      #--------------------------------------------------------------------------
      # * Object initialize
      #--------------------------------------------------------------------------
      def initialize(x, y, p, goal = Goal.new(0,0))
         @goal = goal
         @x, @y, @parent = x, y, p
         self.score(@parent)
      end
      #--------------------------------------------------------------------------
      # * id
      #--------------------------------------------------------------------------
      def id
         return "#{@x}-#{@y}"
      end
      #--------------------------------------------------------------------------
      # * Calculate score
      #--------------------------------------------------------------------------
      def score(parent)
         if !parent
            @g = 0
         elsif !@g || @g > parent.g + 1
            @g = parent.g + 1
            @parent = parent
         end
         @h = (@x - @goal.x).abs + (@y - @goal.y).abs
         @f = @g + @h
      end
      #--------------------------------------------------------------------------
      # * Cast to move_command
      #--------------------------------------------------------------------------
      def to_move
         return nil unless @parent
         return RPG::MoveCommand.new(2) if @x < @parent.x
         return RPG::MoveCommand.new(3) if @x > @parent.x
         return RPG::MoveCommand.new(4) if @y < @parent.y
         return RPG::MoveCommand.new(1) if @y > @parent.y
         return nil
      end
   end
   #--------------------------------------------------------------------------
   # * Singleton of Pathfinder
   #--------------------------------------------------------------------------
   class << self
      #--------------------------------------------------------------------------
      # * spec ID
      #--------------------------------------------------------------------------
      def id(x, y)
         return "#{x}-#{y}"
      end
      #--------------------------------------------------------------------------
      # * Create a path
      #--------------------------------------------------------------------------
      def create_path(goal, event)
         open_list = {}
         closed_list = {}
         current = Point.new(event.x, event.y, nil, goal)
         open_list[current.id] = current
         while !closed_list.has_key?(id(goal.x, goal.y)) && !open_list.empty?
            current = open_list.values.min{|point1, point2|point1.f <=> point2.f}
            open_list.delete(current.id)
            closed_list[current.id] = current
            if $game_map.passable?(current.x, current.y, 2) && !closed_list.has_key?(id(current.x, current.y+1))
               if !open_list.has_key?(id(current.x, current.y+1))
                  open_list[id(current.x, current.y+1)] = Point.new(current.x, current.y+1, current, goal)
               else
                  open_list[id(current.x, current.y+1)].score(current)
               end
            end
            if $game_map.passable?(current.x, current.y, 4) && !closed_list.has_key?(id(current.x-1, current.y))
               if !open_list.has_key?(id(current.x-1, current.y))
                  open_list[id(current.x-1, current.y)] = Point.new(current.x-1, current.y, current, goal)
               else
                  open_list[id(current.x-1, current.y)].score(current)
               end
            end
            if $game_map.passable?(current.x, current.y, 4) && !closed_list.has_key?(id(current.x+1, current.y))
               if !open_list.has_key?(id(current.x+1, current.y))
                  open_list[id(current.x+1, current.y)] = Point.new(current.x+1, current.y, current, goal)
               else
                  open_list[id(current.x+1, current.y)].score(current)
               end
            end
            if $game_map.passable?(current.x, current.y, 2) && !closed_list.has_key?(id(current.x, current.y-1))
               if !open_list.has_key?(id(current.x, current.y-1))
                  open_list[id(current.x, current.y-1)] = Point.new(current.x, current.y-1, current, goal)
               else
                  open_list[id(current.x, current.y-1)].score(current)
               end
            end
         end
         move_route = RPG::MoveRoute.new
         if closed_list.has_key?(id(goal.x, goal.y))
            current = closed_list[id(goal.x, goal.y)]
            while current
               move_command = current.to_move
               move_route.list = [move_command] + move_route.list if move_command
               current = current.parent
            end
         end
         move_route.list.pop
         return move_route
      end
   end
end

#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  This base class handles characters. It retains basic information, such as
# coordinates and graphics, shared by all characters.
#==============================================================================

class Game_Character
   #--------------------------------------------------------------------------
   # * Move to x y coord
   #--------------------------------------------------------------------------
   def move_to_position(x, y)
      return if not $game_map.passable?(x,y,0)
      route = Pathfinder.create_path(Pathfinder::Goal.new(x, y), self)
      self.force_move_route(route)
   end
end

#==============================================================================
# ** Command
#------------------------------------------------------------------------------
#  Ajoute des commandes facilement manipulables (Event Extender)
#==============================================================================

module Command
   #--------------------------------------------------------------------------
   # * Singleton de Command
   #--------------------------------------------------------------------------
   extend self
   #--------------------------------------------------------------------------
   # * Move event to a point (if the point 's passable)
   # id = id of the event
   #--------------------------------------------------------------------------
   def move_to(id, x, y)
      $game_map.events[id].move_to_position(x, y)
   end
end

La commande est : cmd(:move_to, id_event, x, y)
Un exemple simple... un point and click minimaliste:
Spoiler:

Smile

Toujours des scripts très sympas ! +3 points de participation !
Revenir en haut Aller en bas
zouzaka
Croisé Lv.14
Croisé Lv.14
zouzaka


Masculin Age : 25
Inscrit le : 22/05/2011
Messages : 1141

[VXAce] Event Extender, Pathfinder Empty
MessageSujet: Re: [VXAce] Event Extender, Pathfinder   [VXAce] Event Extender, Pathfinder Icon_minitimeMar 11 Sep 2012 - 10:00

vraiment simpa Very Happy
Revenir en haut Aller en bas
Ice Monkey
Templier Lv.15
Templier Lv.15
Ice Monkey


Masculin Age : 26
Inscrit le : 30/01/2011
Messages : 1273

[VXAce] Event Extender, Pathfinder Empty
MessageSujet: Re: [VXAce] Event Extender, Pathfinder   [VXAce] Event Extender, Pathfinder Icon_minitimeMar 11 Sep 2012 - 18:08

Très utile pour des cbs. Encore bravo à toi grim pour le boulot que tu fais.
Revenir en haut Aller en bas
http://rpg-maker-factory.bbactif.com
Invité
Invité
avatar



[VXAce] Event Extender, Pathfinder Empty
MessageSujet: Re: [VXAce] Event Extender, Pathfinder   [VXAce] Event Extender, Pathfinder Icon_minitimeMar 18 Sep 2012 - 12:00

https://github.com/Funkywork/Scripts-rm/blob/master/VXAce/EE-Pathfinder.rb
Petit correctif (et ajout de la possibilité d'attendre et déplacer le héros)
Revenir en haut Aller en bas
Contenu sponsorisé




[VXAce] Event Extender, Pathfinder Empty
MessageSujet: Re: [VXAce] Event Extender, Pathfinder   [VXAce] Event Extender, Pathfinder Icon_minitime

Revenir en haut Aller en bas
 

[VXAce] Event Extender, Pathfinder

Voir le sujet précédent Voir le sujet suivant Revenir en haut 
Page 1 sur 1

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
RPG Maker VX :: Entraide :: Scripts :: Scripts VX.Ace - RGSS3 :: Utilitaires-
Créer un forum | ©phpBB | Forum gratuit d'entraide | Signaler un abus | Forum gratuit