Main Menu
  • Welcome to The RPG Maker Resource Kit.

Path Finder v 0.4

Started by Tsunokiette, October 01, 2006, 09:18:24 PM

0 Members and 1 Guest are viewing this topic.

Tsunokiette

Another In Progress Script.

Won't be the best in the world, but will use a method a little different than the others.

def find_path(event_id, tile_x, tile_y)
   path = Path.new(event_id)
   path.find(tile_x,tile_y)
end

class Path

   def initialize(event_id)
      @map = $game_map
      if event_id == 9999
         @event = $game_player
      else
         @event = @map.events[event_id]
      end
      @open_tiles = set
   end

   def find(tile_x,tile_y)
      @paths = []
      if @event.lock?
         return p 'Error :  Event Position Locked Cannot Move'
      elsif !@open_tiles.include?([@event.x,@event.y])
         return p 'Error :  Movement Not Allowed From Current Possition'
      end
      @x = @event.x.deep_clone
      @y = @event.y.deep_clone
      border = [[@x, @y - 1], [@x + 1, @y], [@x, @y + 1], [@x - 1, @y]]
      total_possible_paths = 0
      for tile in border
         total_possible_paths += 1 if @open_tiles.include?(tile)
      end
      for i in 0..(total_possible_paths)
         @paths[i] = Possible_Path.new
         # Code to Map Path Goes Here
      end
      distances = []
      for i in 0..(@paths.size)
         distances[i] = @paths[i].distance
      end
      @best_path =  @paths.find{ |path| path.distance == distances.min }
   end

   def move
      # Code to move Goes Here
   end

   def set
      temp = []
      for x in 0..(@map.width / 32)
         for y in 0..(@map.height / 32)
            temp.push([x,y]) if @map.passable?(x,y,0)
        end
      end
      return temp
   end

end

class Possible_Path
   # Code for Storing Path Information Goes Here
end

class Object
   def deep_clone
      file = File.open('cloning.txt', "wb")
      Marshal.dump(self,file)
      file.close
      file = File.open('cloning.txt', "rb")
      data = Marshal.load(file)
      file.close
      return data
   end
end
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

Arrow

...So what does it do, exactly?

Tsunokiette

#2
Eventually it will test all possible paths and find the shortest route, and move the event/player to the chosen position.

EDIT : @programmers - Slight rewriting needed for the add_sub definition, I'll get it done, it's just notepad is hard to program with.

EDIT 2 : As a matter of fact, I'm going to have to rewrite the Possible_Path class all together. -_-
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

Arrow

Oh, sweet! I can think of all kinds of uses for this...