• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with Grid Movement

M

mcglubski

Guest
So I've made a simple grid movement for my game where you can move to squares with 3 actions (1 movement equals an action), I am having difficulty figuring out a good way to let the player move back to previous squares and regaining their actions. I was able to figure out a really poor "Press Backspace Method" but honestly it would be much more beneficial to have them just be able to move there with their actual movements. I tried setting each square they were previously on and checking whether they are moving to that square and act accordingly (add action points back to player and erase the third actions xy coordinates) , but no matter what I do I can't seem to do it without using a huge amount of code. Does anyone have a simple solution for me?

Here is the current code I have to keep the player moving on the grid

GML:
//Combat Grid Width/Height
xMove = 44;
yMove = 26;

//Keys begin disabled
keyLeft = false;
keyRight = false;
keyUp = false;
keyDown = false;

//Coordinates
y1 = 130;
y2 = (y1 + yMove);
y3 = (y2 + yMove);
y4 = (y3 + yMove);
x1 = 44;
x2 = (x1 + xMove);
x3 = (x2 + xMove);
x4 = (x3 + xMove);

//Move Left
if keyboard_check_pressed(vk_left) || keyboard_check_pressed(ord("A"))
&& !place_meeting(x - xMove, y, ob_parentcol)
&& !place_meeting(x - xMove/2, y, ob_thincol)
&& action_points > 0
{
    keyLeft = true;
}
else keyLeft = false;

//Move Left
if x <= x4
&& x > x1
{
    if keyLeft = true
    {
        keyUp = false;
        keyDown = false;
        x -= xMove;
        action_points -= 1;
    }
}

Any ideas or suggestions?
 

Nidoking

Member
You're only storing up to three squares, right? Even if you don't want to learn arrays or grids, surely you could just use six variables and check the value of the move-to square against the most recent square left.
 

TheouAegis

Member
Personally what I would do is push the coordinates for each grid cell that you move to into a list. let the player move whatever direction he wants. When the player attempts to move to a Target cell, find that sell in the list. if the cell is not found in the list, add it to the list and let the player move to that cell. However if the cell is found in the list, get the position of that cell in the list, delete all entries after that cell and give action points back to the player.
 
M

mcglubski

Guest
I sort of did that with my backspace method, just trying to figure out how to do so with the movement is racking my brain somehow. I think what you suggested might have helped though, sometimes I just need to be shown what is right in front of me to figure things out
 
M

mcglubski

Guest
Oh wait I see what you're saying. I might have made the movement overly complicated it seems
 
Top