# Help with a PacMan clone

This topic is 3791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone! I'm having trouble with my PacMan clone... I'm using my game engine which uses delta values for framerate-independent movement. I have three variable couples: X/Y (int, the current player's position on the grid), DestX/Y (int, the destination position on the grid), and PhysicalX/Y (float, the player's position on the screen, in pixels). So PhysicalX/Y is moved on every iteration, and whenever it is equal to X/Y, a new DestX/Y is calculated based on the specified direction. The problem is that, since PhysicalX/Y is a float, X/Y aren't very accurate. So whenever the player reaches DestX/Y, I synchronize the two (PlayerX/Y and X/Y, check the line labeled with "HERE" below). That fixes the problem but introduces another one: whenever DestX/Y is reached, the smiley quickly moves to that exact position on the grid and that causes non-smooth movement.
void MovePlayer(float movement)
{
if (X < DestX) PhysicalX += movement;
else if (X > DestX) PhysicalX -= movement;

else if (Y < DestY) PhysicalY += movement;
else if (Y > DestY) PhysicalY -= movement;

// HERE:
if (X == DestX && Y == DestY)
{
PhysicalX = X * 16 + 16/2;
PhysicalY = Y * 16 + 16/2;
ChangeDirection();
}
}



##### Share on other sites
I am not sure I understand the problem... based on the code provided, X/Y never changes! So how could X/Y==DestX/DestY?

##### Share on other sites
Maybe I totally misunderstand it. but.(pseudocode)

whatever it's called in your language, make this in your movement class:
player_movement : (move_right, move_left)if the player starts to move right (player_coordinate.x < destination_coordinate.X), set player_movement to : move_right.check:if player_coordinate.x > destination_coordinate.X  Andplayer_movement = move_rightThen(Do Something, change direction)

In thios way you avoid integer/float issues. Make all float. Anyway this is how I did programmed movement in my game, and it worked without glitches. make sure to do it before rendering.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013275
×