Stuck on code

I'm trying to make it so that when pacman hits the left wall it stops him from going out the left screen. I got the right wall working but cant seem to figure out the left wall code any suggestions would be helpful please?

1
2
3
4
5
6
7
8
9
10
11
if (_pacman->Position->X + _pacman->SourceRect->Width > 1024)
	{
		//pacman hit right wall reset his position
		_pacman->Position->X = 1024 - _pacman->SourceRect->Width;
		
	}
	else if (_pacman->Position->X - _pacman->SourceRect->Width > 1024)
	{
		//Hit left wall
		_pacman->Position->X = 1024 + _pacman->SourceRect->Width;
	}
I don't know if you're using a library for 2D graphics and such, but what I did with space invaders was. I got pacman's position in x relative to the window. The very right of the window is in your case 1024. But the very left of the window is 0, no? window goes from 0 to 1024 if your window width if 1024.

So you might be checking the right wall twice.
thank you that worked strangely though it wasn't 0 for the left wall but thank you for the advice.
Topic archived. No new replies allowed.