Page 1 of 1

Enemy movement on the game grid

PostPosted: Sat Aug 29, 2015 5:08 pm
by DrakeStoel
Hi!
So I'm making a game with a bunch of different enemies, but the main feature most of them have in common is to chase down the player when they get close. They are each confined to each game screen (which is just the resolution of my game). The other thing I would like them to do is to move only on a vertical or horizontal axis (in other words not diagonally) and move a complete grid square over (the grid being the grid size while editing the game). My resolution is 256x224, and my grid size is 16x16, making each screen 16x14 tiles, for a total of 224 different grid squares per screen.

Any help would be greatly appreciated!

Re: Enemy movement on the game grid

PostPosted: Tue Sep 08, 2015 9:02 am
by barney12345
Split the area into quadrants with the use of filled frame region and have integer goodLoc which is determined by which quadrant the good guy is in and integer badLoc which is determined by which quadrant each enemy is in. Then if the quadrants are something like

1 2
3 4

if goodLoc=1, and enemyLoc=2, x=x-20;
if goodLoc=3, and enemyLoc=4, x=x-20;
and etc for all other quadrants. You can then adjust the movements so that the enemy will always remain within the confides of any square and not be in between.

That's one solution, I expect there are many simpler ones, this one doesn't rely on moveTo at least

Re: Enemy movement on the game grid

PostPosted: Fri Sep 11, 2015 4:46 pm
by DrakeStoel
Okay, I have simple movement of my enemy now, but I've run into another snag. How can I make my enemy avoid objects like rocks, trees, etc. while still moving on the grid? So instead of just moving through, it moves around while still prohibiting diagonal movement.

Re: Enemy movement on the game grid

PostPosted: Sat Sep 19, 2015 12:54 am
by barney12345
make an action where if the object collides with a tree, depending on the direction it is travelling in, it will move one square down, two left/right, one up