Jump to content

Need help making player move along a grid with a fixed path


VincentMeier
 Share

Recommended Posts

Hello. Newbie dev here.

 

Started working with Phaser making my first game and so far progress has been fine, but I have hit a snag, where my inexperience is getting the best of me.

 

So the situation is as follows. I have a 2D grid, it's currently saved in a 2D matrix. The Purple tiles in the picture

var testMap = [    [0, 0, 0, 1, 1, 1, 1, 1],    [0, 1, 1, 1, 1, 1, 0, 1],    [0, 0, 0, 0, 0, 1, 1, 1],    [1, 1, 0, 0, 0, 0, 0, 0],    [1, 1, 0, 0, 0, 0, 0, 0],    [1, 0, 0, 0, 0, 0, 0, 0],    [1, 0, 1, 1, 1, 1, 1, 1],    [1, 0, 0, 0, 0, 1, 1, 1],    [1, 0, 1, 1, 0, 1, 1, 1],    [1, 0, 1, 1, 0, 1, 1, 1],    [1, 0, 1, 1, 0, 1, 1, 1],    [1, 0, 1, 1, 0, 1, 1, 1],    [1, 0, 1, 1, 0, 1, 1, 1],];

And I have a range of tiles around the player, that he can move to. The Green tiles in the picture

 

I've also made a system that reads the mouse location and generates a path to the tile, the mouse is over. The White tiles in the picture. I have this path information in an array

path = [[3,3],[4,3],[5,3],[5,4],[5,5]];

And now I want to make the player move along this path, by using the coordinates of the path array. And ideally have a function in between, that checks if the player has stepped on a trap when he steps on a new tile while moving.

 

But I keep hitting a wall with this function. Any and all ideas would be a appreciated.

post-15699-0-51253200-1438268717_thumb.p

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...