I have just completed tutorial 13 of the beginners tutorial series and I'm about to start the snake tutorial.
I am trying to modify the poo game by creating some box(obstacles to reduce the amount of movement space for the dude) with the drawrect function in its own(box) class (the collision function is in the dudeclass). but I am facing a issue with the collision. I am using a function similar to the ClamptoScreen() to decect the collision and restict the movement of the dude. And its not working as I thought. Its detecting the collision but the problem is with dudes position update. what method should I apply to slove the problem? would love to know the answers. Thanks in advance!
screen shots of the problem:
https://drive.google.com/file/d/1TKQl1r ... sp=sharing
https://drive.google.com/file/d/1t0RyAX ... sp=sharing
https://drive.google.com/file/d/1sIpDrs ... sp=sharing
https://drive.google.com/file/d/1R-g5WM ... sp=sharing
.
.
.
.
.
(type of code i am using to update dudes position)
Code: Select all
int Wallright = wall.GetX() + wall.GetWidth();
int Wallleft = wall.GetX();
int WallDown = wall.GetY() + wall.GetHeight();
int WallUp = wall.GetY();
const int left = x + width;
const int bottom = y + height;
if (left >= Wallleft && bottom >= WallUp && y <= WallDown && x <= Wallright)
{
x = (Wallleft - 1) - width;
y = WallDown + 1;
y = (WallUp - 1) - height;
x = Wallright + 1;
}