SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ARSA's Avatar
    Join Date
    Apr 2003
    Location
    San Juan, Puerto Rico
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Flash Game: Action Script 2: Basic Pathfinder

    Hello all, its been a while

    I'm currently working on this point and click game where the user click on a map and the character will follow the [target placed on the ground] So far I have managed to create a character that limit itself to the boundaries of the map and that follows the target icon whenever the map its clicked.

    The situation:
    My game it is not tile based but it does have a tile based node system. What I want to be able to do is to hard code the nodes in each map, while then create the program that will validate these nodes by adding them. That way I can control and or erase nodes that are non walkable for my character.

    I have tried pathfinding algorithms but they seem to advanced for me. I seem to understand the words but the practice is a failure. Can anyone guide me in my initial stages.

    Right now I have my nodes hard placed on the map they are called "node_mc" all of them. I think the first thing I need to do is to re-name them all like "node_mc1", "node_mc2", "node_mc3" etc... etc... etc... to differentiate them or can I leave them like that? Please look at the picture attached.

    - Thank you in advanced.
    Attached Images Attached Images
    "I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." - Albert Einstein

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,813
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    ¡Hola! ¿Como estan los coquis?

    Well I haven'd coded AS in like 4 years, and AS2 in like 6. Sorry If I don't whip up a script off the top of my head.

    I would suggest the following logic.

    1) Store your bodes in a 2 dimensional array. eg.:grid [x][y]
    2) you could then have a player grid position(PGP), where the player is at , and Target grid position (TGP), where the player wants to go.
    3) in the grid there will ALWAYS be 8 adjacent blocks to the PGP. You could then recursively loop trough these checking the nodes.
    -if it's a 'blocked' or 'impassable' node skip to next node.
    - if the block y value is the closest of all 8 to the TGP then remember that blocks 'Y'
    - if the block X value is the closest of all 8 to the TGP then remember that blocks 'X'
    - Move the player to the node stored in grid[x][y]/etc.
    - IF the X/Y of the player DO NOT mach the X/Y of the target repeat/ else wait for new target


    Since you have only stored (mapped) the position of the nodes in a grid virtually' in the array.. you should be able to retain the rest of your coding strategy.

    Hopefully that helps

  3. #3
    SitePoint Addict ARSA's Avatar
    Join Date
    Apr 2003
    Location
    San Juan, Puerto Rico
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jeje! los coquies estan bien

    Thanks you for the example. Now here is where my biggest problem lies. I don't seem to see the big picture after reading. So, I will start with numero 1.

    1) Store nodes in a 2D Array called: Grid[x][y]
    - Since I will be hard coding/placing the nodes to the stage I will tell each node to push it's own coordinate on event(load) to the main Grid[x][y] on the root. And that will create my Main Grid System.

    NOTE: My character already follows it's own target. On click the stage, the character will center itself to the disk_locator. Now How do the point system works with this method?

    - Thanks
    "I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." - Albert Einstein


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •