r/processing • u/_Rocco22_ • May 17 '24
Help request How can i implements grid based movement(or tile based movement)? As you can see, this is my motion handling code which also takes advantage of the Fisica for Processing library. How could I modify the code in such a way as to obtain movement similar to that of the Pokemon games for DS?
actual type of movement in my game. Anyone interested in seeing the code and giving some advice and feedback is welcome! The working branch is collisionSystem
update method in Player class
map's setup in Level class
updatePosition methods in Sprite class (class extended by Player class)
10
Upvotes
3
u/MGDSStudio May 17 '24
I have never player Pockemon, but I think you need;
In the code you can create a variable with name <statement>. It can take one of next statements:
WAITING_FOR_INPUT,
TIMER_STARTED
MOVEMENT_STARTED
I would like to add two more statements:
INPUT_INTERRUPTED (when the player doesn't hold the key for 1000 ms)
MOVEMENT_COMPLETED
but this statements must be set only for one game frame. After the next frame they will be reset again on WAITING_FOR_INPUT
2
u/Salanmander May 17 '24
My guess is you won't want to use the
setVelocitymethod that you're currently using. Instead you'll want to update the position manually each time the user presses a key. ThekeyPressed()method is a method you can write that will get called automatically (likedraw()is), and it gets called once each time the OS registers a key press. So you can write code in that method which you want to happen once-per-press, rather than continuously.1
u/_Rocco22_ May 17 '24
I posted some time ago in this community, it's my first real video game, I'm doing it in Processing because it was proposed to me in the video game development course and I think it's very educational.
2
u/iddq-tea May 19 '24
The way I did it was to check if the player's position was 0 when %-d by the grid cell size, if true and no key is being held down, stop moving, otherwise keep moving. You can also queue the next move this way by having a variable store the direction the player should turn upon reaching the next grid cell.
EDIT: this method also simplifies collision checks since you only need to check whether or not the next cell is occupied :)