Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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;

Please help me. Thanks in advance!

Share this post

Link to post
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.

if player_coordinate.x > destination_coordinate.X


player_movement = move_right


(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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!