Hi there,
Im having some trouble with the bounding box collision using allegro 5. Standing on top of the platform works. But when colide to the left side of the platform i go in the platform (but does stop in centre of it) also when i jump against the platform i either go through completly or stop in the middle of the platform.
I hope i explained it good enough. if yuo have questions or need to see code just ask.
note: hdir 1 right, 2 left, 0 none. vdir 1 up, 2 down 0 none
also the number 1 is the platform.
Here is the collision code i wrote.
Your if/else's look a bit screwed up....at one point you say:
if(x > etc etc etc) { //no collision } else { //move x/y etc etc }
...so you're saying "if there is a collision then move the player"...makes no sense!
Then what should i do? because the player moves at a constant speed of 5 to the right. Sorry still a beginner hehe
edit
Also ive been trying to change the code for ages. But what ever i do the result is the same. aka nothing new happens. Also ive been looking at a tutorial, the code that was written in there is practically the same. The only difference is that it works in the tutorial...
So, explain to me exactly what happens, in as much detail as possible, and I'll help you out.
[edit]
Also, show me the code where you draw the player, and map/tiles.
[edit2]
Also, show me how big your player sprite is, and how big your blocks are!
ill explain what happens: i go to the right at a constant speed of 5. When i encouter a tile i will collide with it but it goes within the tile. and then stops in the middle. Same goes for jumping. When i jump i go either through the whole tile or stop in the middle.
Here is the player class:
Collision class:
Global.h:
Ok, first off, adding 5 pixels a time is mega fast! Can you show me your main game loop, where you call all the functions please?
Hehe it's a freaking mess and not commented hope you can find what you are looking for XD
Ok, there's a couple of things going on here that aren't quite right; and that doesn't mean anything negative with regards to you, there's things I do wrong all the time, that's the beauty of this forum, there's so much knowledge you can just keep getting better!...
...ok, first off, do you see that you're updating your player's x & y twice each loop? Once in the player.setPosition, and also in the collision class...
...don't change the players x/y in the collision function, that's what player.setPosition is for!...
...instead, give the player class a new bool, and call it canMove...set it to true when you call the player constructor, and set it to false when you have a collision; then, in your player.setPosition, ONLY allow the change of x/y if player.canMove == true...
...after you've done that, let me know what happens!
[EDIT]
(You're not using the timers quite right either, and a few other bits, but let's do this a problem at a time!
)
[EDIT2]
updated!!
lets see. I dont think i get it... (this gives me the same result. when i colide to the left side of a tile i go in there in stop in the middle.)
this is an if statement in the collision.cpp
this is the player setPosition
I suppose the best way to get this solved fast is if you can send me your code? I could compile it here and find out why it's happening, and send you back the fixed code? Because at the moment I can't see enough to understand why...!