using sprite2mem for feeding the pathfinding function

Previous topic - Next topic

kaotiklabs

Hello,

I need to move a sprite following a brown path painted in a png image.
I was thinking about using the path finding function but I don´t know how to feed the function with an image.

Do you know if its possible to use sprite2mem for generating the map used by the findpath function?
could be maybe easier using a mask image?

thanks in advance.

Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Ian Price

You could create an image - either pre-loaded or made on the fly or pre-rendered at start of the game and use GETPIXEL or use an array to control the movement of the sprite. There are multiple routes to solve this problem. Some are easier than others (the array method is probably the quickest and easiet one to implement, but none are tricky).

Be aware though that the GETPIXEL method can misbehave from one pc to another, depending on the graphics card not reading the pixel colour data accurately/in the same way. Try to ensure pure colours either with values as 0, 128 or 255 - eg RGB(0,0,0) or  RGB(0,128,255) etc. These seem to give more accurate results from my studies.

The array method can also be used for recording a demo of the game in action; to be used as a demo attractor or tutorial - I've used both methods in the past.
I came. I saw. I played.

kaotiklabs

Hi Ian, thanks for the fast answer.
I know there are easier ways but I must use A* because is a kind of an AI demo.

The problem is how to generate the map needed by the AI function from an image.  :(
Maybe I could generate a mask image from the original image with getpixel... (if sprite2mem is not a valid solution)
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Slydog

Depending on how precise you need to be, to speed up 'getpixel', you could sample every 4th pixel (for example) across and down.
This should speed up the A* too because of the smaller array size.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

why not using mem2spr? It should work. Just make a pixel array and fill the path points with a value. Then draw the pixels as a sprite.