interesting question
do your characters have the ability to jump?
And if they do, Is the jump based on grid movement?
If it is... Strange feeling
Anyway here is what I would do... I'm actually working on some changing gravity stuff too so I already figured out some stuff like how to unify code for all direction.
Basically I use some vector concept
like in the basic direction you have
Up : (0,-1)
Down : (0,1)
Left : (-1,0)
Right : (0,1)
as vector for each direction.
if you have a character on a wall facing right, his up, left, down and right vector would be something like (1,0), (0,-1), (-1,0) and (1,0)
etc.
So the idea is to have 9 variables for each character (enemy or player).
Only one is really important but the other are better for code readability
so these variables would be :
- direction (the most important one)
- xT and yT (for the top vector)
- xB and yB (for the bottom vector)
- xR and yR (for the right vector)
- xL and yL (for the left vector)
the direction variable can have a value form 0 to 3 representing the 4 possibilities :
- 0 on the ground
- 1 on a wall facing right
- 2 on the ceiling
- 3 on a wall facing left).
This way you can set each of your vector depending on this variable like this :
Top
xT = round(sin('direction'*90))
yT = 0-round(cos('direction'*90))
Right
xR = round(cos('direction'*90))
yR = 0-round(sin('direction'*90))
Bottom
xB= 0-xT
yB= 0-yT
Left
xL= 0-xR
yL= 0-yR
and then if you want to move a character to his right you just have to :
+ MouseKeyboard: On player 1 pressed "Move Right"
-> Character: Set X to 'xR' * 'speed' * TimeDelta
-> Character: Set Y to 'yR' * 'speed' * TimeDelta
Now for the grid movement :
You have to set the size of your grid cell in a global variable
I will name it global('cellSize')
you also need a variable that will carry the direction of your movement during the interpolation between one cell to the other
I propose 'xMove' and 'yMove' this way we will also use the aformentionned vector.
And to be accurate we will store the coordinate of the character before the interpolation in 'xStart' and 'yStart'
Then you wil have something like that :
+ MouseKeyboard: On player 1 pressed "Move Right"
-> Character: Set 'xStart' to .X
-> Character: Set 'yStart' to .Y
-> Character: Set 'xMove' to 'xR'
-> Character: Set 'yMove' to 'yR'
now 'xMove' and 'yMove' carries the direction of the interpolation.
while 'xStart' and 'yStart' keep the origin safe.
Now you just have to do :
+ Character: Value 'xMove' Greater than 0
+ System: Abs(Character('xStart')-Sprite.X) Lower than global('cellSize')
-> Character: set X to X+'speed'*'xMove'*Timedelta
+ else
-> Character: set X to 'xStart'+'xMove'*global('cellSize')
-> Character: set 'xMove' to 0
+ Character: Value 'yMove' Greater than 0
+ System: Abs(Character('yStart')-Sprite.Y) Lower than global('cellSize')
-> Character: set Y to Y+'speed'*'yMove'*Timedelta
+ else
-> Character: set Y to 'yStart'+'yMove'*global('cellSize')
-> Character: set 'yMove' to 0
And that should do.
So to sum up, you just have to put whatever direction you want in 'xMove' and 'yMove' to make your character moves
ah and the 'speed' variable is how many pixel/second you want it to move.