Reputation: 57
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 map generated from 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 that the mouse is over. I have this path information in an array. The White tiles in the picture.
var 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.
Upvotes: 2
Views: 1795
Reputation: 3710
See this example. It's about tween interpolations, but illustrates a tween along a path as well. Basically instead of a single value for x, you pass an array.
Upvotes: 3