|
| = Collision line.
|
I have been able to create these two collision lines, using
int x2 = -10; int y2 = 465; int x3 = 625; int y3 = 10;
this comes out.
| | | | | | | |
when I try to add collision on the top with:
int x4 = 515; int y4 = -3;
this comes out:
| | | | | | | | | | | |
So I was wondering how to make it look like this:
|||||||||| | | | | | |
Hope that makes sense! 
Thanks in advance.
Are you trying to draw lines? Or are the lines just imaginary and used for collision testing? Allegro 4 or 5?
They are imaginary and are setting a border(Invisible), for collision.
Pretty sure its 5.0.5
Could you post your code, at least the relevant parts of it? I'm still not sure exactly what you're doing.
I'm not sure if I missed anything important, but that gives you the idea.
x, y = Sprite
All the x2 and others are invisible rectangles that I'm using as walls.
x4, y4 is the one I want to go horizontally.
Sorry man, I'm not a psychic. What does the Collision function look like? Just post the lot.
Basically I wanna rotate which way my collision line is facing.
Basically I wanna rotate which way my bounding box is facing.
Well, here is a generic reply. If this doesn't answer your question, please post more of your code.
If you have a sprite moving inside a box (imaginary or not) where the upper left and lower right corners are defined by (box_x1, box_y1) and (box_x2, box_y2), you can do collision testing like this:
if (sprite_x <= box_x1 || (sprite_x + sprite_width) > box_x2) { /* reverse horizontal direction here */ } if (sprite_y <= box_y1 || (sprite_y + sprite_height) > box_y2) { /* reverse vertical direction here */ }
If you want the box to be open at the bottom, just remove the comparison with box_y2.
Thats the thing! I'm trying to make the top of the box.
So, did you get it working?
I got it... Kinda. Check this out for me? (Walk to top) The collision is messed up for some reason that I don't understand.
if (sprite_y < top_boundary) {sprite_y = top_boundary;}
where did I put that?
Just do the same thing you would for a vertical collision.
I did but there is something wrong with how I did it and Im not sure what it is, I posted the code and stuff as attachment. Up a few posts.
No matter what I try I can't get a collision stretching across the top, no idea what i'm dong wrong.
if (Collision2(x, y, x4, y4) == true) { if (dir1 == 360) x -= 5; if (dir1 == 180) x += 5; }
It's because you are changing x instead of y here.
EDIT: And you are also using dir1 instead of dir2.
You could use an enum for the direction, like this:
enum Direction { North, East, South, West }; Direction dir = North;
Then use that instead of dir1 and dir2. And you could simplifiy your collision testing a lot, but let's take one step at a time.
if (sprite_y < top_boundary) {sprite_y = top_boundary;}
where did I put that?
You didn't, but if you had it would have solved all of your problems. If you don't want the top of a sprite to go above a certain y level, that is all you would have to do.....
Oh my god, that's so beautifully easily!!! Thank-you very much.