:::: MENU ::::

Pucaj Update – Grid Based Movement

I’ve been thinking about what Pucaj should actually become and I’ve decided on a turn-based RPG with tanks/robots. The vehicles would have parts you can upgrade, or buy, or collect maybe, and you’d move and fight on a grid based map. None of it is really completely decided on and it’s all a blur right now, but one thing I can be pretty sure of – I need grid based movement.

I ditched Box2D, because there really isn’t any need for it, and also ditched the “rotate the tank towards touch coordinates feature I had.

Instead, I implemented the movement based on a grid system.

The first thing I needed to do was to set up scaling of coordinates, so I can work with what are basically integers, instead of screen coordinates.

Since the current map size is 10×10, the player’s position can be stored in a [0..9][0..9] vector. Based on the provided input, it then changes . Since it needs to also look nice, I added a class with static easing methods to interpolate between the new and the old position. The easing methods will be very universal, so I can use them for other things as well. They will require the initial value, the amount that value needs to change for, the duration of the entire process and our current position in the process, as in elapsed time.

Basically, we have something like this:

newValue = easeFunction(elapsedTime, initialValue, totalChange, totalDuration);

For now, all I have is a quadratic easeIn function, but I will be adding more as I need them.

I’m having trouble on deciding how to detect the player’s desired action via touch. For now, I determine the four rectangles the player can move to from the current position and then look if the player has touched a coordinate in any of these rectangles. This works, but it might not be the best approach.

A possible alternative would be to calculate the centers of these four rectangles and then move into the rectangle with the closest center to the touch coordinates.

The first option has the advantage of precise movement, but it also feels a bit stiff. On the other hand, the second approach allows for more freedom, but could also cause unwanted movement.

With the keyboard, this is much more straightforward. You use arrow keys to move and that’s it.

Also, since I don’t want diagonal motion, direction is prioritized in the order of UP, LEFT, DOWN, RIGHT. In the context of the keyboard, this means that if you push UP and LEFT at the same time, you will go up, etc.

In any case, I made a video of what I have and uploaded it on my painfully slow connection. Here it is:

My laptop is complete crap, so it stutters even with this. I promise that if I ever have anything substantial to show, I will use my more powerful PC.

You can see in the video that both touch/mouse and keyboard support exists. When the mouse cursor isn’t moving, but the tank is, it means I’m using keyboard keys.

Impressive, right? /s