Cant get good player collision

Hello

Im making a 2d game for school in c++ but i cant get the collosion working
i have to code it so the player cant walk trough walls and floors but i just dont got any idea how to make this work

does someone here have a idea for me to get this problem fixed?

thank you!
You could show what you've done so far.

Aceix.
Let's say you have square 1 - it will be player - and square two - which will be wall.

You have to do four ifs to check if collision happened:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if(player is on the left side of wall)
{
collision = false;
}
else if(player is on the right side of wall)
{
collision = false;
}
else if(player is under the wall)
{
collision = false;
}
else if(player is above the wall)
{
collision = false;
}
else
{
 collision = true // Player isn't outside the box, so he must be inside, or collide with it :)
}

Try to make it yourself.

Cheers!
Last edited on
Topic archived. No new replies allowed.