Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro collision help!

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Allegro collision help!
mrukki
Member #9,433
January 2008

Hello!
Do somebody know how to make collision in allegro? I need help and I'm stuck in my game :'( I've seen a tutorial about it but it just explained how to print "Collision!" if it was true. I thought It would work if I made some variables that switched true or false if the character was in a specific area but it didn't work out. If you have any idea how I should make it please replay or send any links for tutorials.
Thanks! ;D

Mrukki

Yellow_Yackets
Member #9,427
January 2008
avatar

This function might help you:

1/*
2 Sprite structure
3*/
4//SPRITE Structure
5typedef struct SPRITE
6{
7 //Supported elements
8 int dir, alive;
9
10 //Main Elements
11 int x,y;
12 int width, height;
13 int xspeed, yspeed;
14 int xdelay, ydelay;
15 int xcount, ycount;
16 int curframe, maxframe, animdir;
17 int framecount, framedelay;
18}SPRITE;
19 
20/*
21 Check if both sprites are inside each other or touching
22*/
23//Inside Function
24bool Y_YInside(int x,int y,int left,int top,int right,int bottom)
25{
26 if(x > left && x < right && y > top && y < bottom)
27 {return true;}
28
29 return false;
30}
31 
32/*
33 This is the main fuction that you are going to use
34 with this you will know if collition was alive.
35
36 This fuction returns true if collition is made.
37 This fuction will return false if collition is not made.
38*/
39 
40//Collition test
41bool Y_YCollide(SPRITE *a,SPRITE *b)
42{
43 int wa = a->x + a->width;
44 int ha = a->y + a->height;
45 int wb = b->x + b->width;
46 int hb = b->y + b->height;
47 int bx = 5;
48 int by = 5;
49
50 if(Y_YInside(a->x, a->y, b->x+bx, b->y+by, wb-bx,hb-by) ||
51 Y_YInside(a->x, ha, b->x+bx, b->y+by, wb-bx, hb-by) ||
52 Y_YInside(wa, a->y, b->x+bx, b->y+by, wb-bx, hb-by) ||
53 Y_YInside(wa, ha, b->x+bx, b->y+by, wb-bx, hb-by))
54 {
55 return true;
56 }
57
58 return false;
59}

TeamTerradactyl
Member #7,733
September 2006
avatar

Yellow_Yackets: please use [code]...[/code] tags...

mrukki: for collision detection, tell us what kinds of objects you already have. You should both their x/y coordinates and their height/width. You can do rectangular bounds checking (not extremely accurate, but good enough), circular bounds checking (a little more accurate), etc.

For rectangular bounds checking, use Yellow_Yackets' suggestion. For circular, simply determine on both objects where you want to ensure that they collide, and then use the distance formula (sqrt(a^2 + b^2)) and check that they don't. (More accurately: sqrt[(obj1.x - obj2.x)^2 + (obj1.y - obj2.y)^2].)

mrukki
Member #9,433
January 2008

Thanks guys! Now I have one idea! ;D I'm going to make variables for the characters top, bottom, left and right and a function for the other objects with the same idea.
Then I'm going to check if the characters bottom value is smaller then the objects top value and if true it can walk and the same idea for all sides :) But then the character can't pass the top value of the objects, like if I want to go on the right side of the character. How should I do that?

Paul whoknows
Member #5,081
September 2004
avatar

inline bool collide(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2)
{
     if (x2 <= xx1) return false;
     else if (x1 >= xx2) return false;
     else if (y2 <= yy1) return false;
     else if (y1 >= yy2) return false;
     else return true;
}

Tags: Bounding Box Collision

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Timorg
Member #2,028
March 2002

A suggestion if you want to go with circular collisions as TeamTerradactyl suggested

Don't use sqrt(), it can become a bottle neck for the code, instead of taking the square root of the two squares, square what you are comparing it to.

(distance ^ 2) < (a^2 + b^2)

and save on the sqrt() call, also ^ in c/c++ is the xor operator, not power of, so you will have to go

(distance * distance) < ((a * a) + (b * b))

-Tim

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

mrukki
Member #9,433
January 2008

Timorg: Thanks, but I'm using cub like players :)

Paul whoknows: Thanks, I understand but not how I should use it? I have 4 variables called walk_u, walk_d, walk_r and walk_l, and I switching them true or false. How can I switch those when I use the function? Can I return the variables? ???

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

One way is to check an objects future position with the bounding box collision check Paul suggested. That is , if they try to move , find their future position and check it with the bounding box collision function. If there is a collision , then they can't move that direction so don't update their position. However , If an object moves more that it's width combined with another object's width , then it can skip over the object in front of it using this method.

mrukki
Member #9,433
January 2008

Thanks! Pauls function works good but it can't return 3 ???
This is my code:

inline bool collide(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2)
{
if (x2 >= xx1) return 0;
else if (x2 < xx1) return 1;
else if (x1 >= xx2) return false;
else if (y2 <= yy1) return false;
else if (y1 >= yy2) return false;
}

if (collide(image1_bb_left, image1_bb_top, image1_bb_right, image1_bb_bottom, image2_bb_left, image2_bb_top, image2_bb_right, image2_bb_bottom) == 0)
walk_r = false;

else if (collide(image1_bb_left, image1_bb_top, image1_bb_right, image1_bb_bottom, image2_bb_left, image2_bb_top, image2_bb_right, image2_bb_bottom) == 1)
walk_r = true;

thats works good but if I do another statement in the function that I want to return 3 or change 1 to 3 it doesn't work :'(

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Depending on what you want to do when a collision happens , if you just want to prevent the player from moving , then this would work fine.

1bool moveleft = false;
2bool moveright = false;
3bool moveup = false;
4bool movedown = false;
5bool moving = false;
6 
7// player and object positions
8int ptlx = 100;
9int ptly = 100;
10int pbrx = 199;
11int pbry = 199;
12int otlx = 300;
13int otly = 300;
14int obrx = 349;
15int obry = 349;
16 
17const int v = 5;// player x and y velocity when moving
18int pvx = 0;
19int pvy = 0;
20 
21while (playing_game) {
22 if (key[KEY_LEFT]) {moveleft = true;} else {moveleft = false;}
23 if (key[KEY_RIGHT]) {moveright = true;} else {moveright = false;}
24 if (key[KEY_UP]) {moveup = true;} else {moveup = false;}
25 if (key[KEY_DOWN]) {movedown = true;} else {movedown = false;}
26 moving = false;
27 pvx = 0;
28 pvy = 0;
29 if (moveright) {pvx = v;moving = true;}
30 if (moveleft) {pvx = -1*v;moving = true;}
31 if (moveup) {pvy = -1*v;moving = true;}
32 if (movedown) {pvy = v;moving = true;}
33 if (moving) {
34 if (collide(ptlx + pvx , ptly + pvy , pbrx + pvx , pbry + pvy , otlx , otly , obrx , obry)) {
35 moving = false;
36 }
37 }
38 if (moving) {// if moving the player would not cause a collision , move the player and update the screen
39 ptlx += pvx;
40 ptly += pvy;
41 pbrx += pvx;
42 pbry += pvy;
43 update_screen();
44 }
45}

However if you'd like to know which side it collided on , since it can only collide on the sides that it was moving towards , then check for overlaps in those directions.
Altering the previous code would give :

1bool moveleft = false;
2bool moveright = false;
3bool moveup = false;
4bool movedown = false;
5bool moving = false;
6 
7bool collidedonleft = false;
8bool collidedonright = false;
9bool collidedontop = false;
10bool collidedonbottom = false;
11 
12// player and object positions
13int ptlx = 100;
14int ptly = 100;
15int pbrx = 199;
16int pbry = 199;
17int otlx = 300;
18int otly = 300;
19int obrx = 349;
20int obry = 349;
21 
22const int v = 5;// player x and y velocity when moving
23int pvx = 0;
24int pvy = 0;
25 
26while (playing_game) {
27 if (key[KEY_LEFT]) {moveleft = true;} else {moveleft = false;}
28 if (key[KEY_RIGHT]) {moveright = true;} else {moveright = false;}
29 if (key[KEY_UP]) {moveup = true;} else {moveup = false;}
30 if (key[KEY_DOWN]) {movedown = true;} else {movedown = false;}
31 moving = false;
32 pvx = 0;
33 pvy = 0;
34 if (moveright) {pvx = v;moving = true;}
35 if (moveleft) {pvx = -1*v;moving = true;}
36 if (moveup) {pvy = -1*v;moving = true;}
37 if (movedown) {pvy = v;moving = true;}
38 if (moving) {
39 if (collide(ptlx + pvx , ptly + pvy , pbrx + pvx , pbry + pvy , otlx , otly , obrx , obry)) {
40 moving = false;
41 // find out which side collision happened on
42 collidedonright = collidedonleft = collidedontop = collidedonbottom = false;
43 if (moveright) {if (pbrx + pvx >= otlx) {collidedonright = true;}
44 if (moveleft) {if (ptlx + pvx <= obrx) {collidedonleft = true;}
45 if (moveup) {if (ptly + pvy <= obry) {collidedontop = true;}
46 if (movedown) {if (pbry + pvy >= otly) {collidedonbottom = true;}
47 }
48 }
49 if (moving) {// if moving the player would not cause a collision , move the player and update the screen
50 ptlx += pvx;
51 ptly += pvy;
52 pbrx += pvx;
53 pbry += pvy;
54 update_screen();
55 }
56}

mrukki
Member #9,433
January 2008

YES!!! I made it!! I used Pauls idea to make those functions. :)
This is my code:

1inline bool collide_r(int t1, int b1, int r1, int l1, int t2, int b2, int r2, int l2)
2{
3if (r1 == l2 && b1 > t2 && t1 < b2) return false;
4else return true;
5}
6 
7inline bool collide_l(int t1, int b1, int r1, int l1, int t2, int b2, int r2, int l2)
8{
9if (l1 == r2 && b1 > t2 && t1 < b2) return false;
10else return true;
11}
12 
13inline bool collide_t(int t1, int b1, int r1, int l1, int t2, int b2, int r2, int l2)
14{
15if (b1 == t2 && r1 > l2 && l1 < r2) return false;
16else return true;
17}
18 
19inline bool collide_b(int t1, int b1, int r1, int l1, int t2, int b2, int r2, int l2)
20{
21if (t1 == b2 && r1 > l2 && l1 < r2) return false;
22else return true;
23}

Thanks everybody! Now I can continue working on my game!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Your code for the collide_r function :

inline bool collide_r(int t1, int b1, int r1, int l1, int t2, int b2, int r2, int l2)
{
if (r1 == l2 && b1 > t2 && t1 < b2) return false;
else return true;
}

Semantically , that code is :
"If
(the right edge of object 1 is in the same place as the left edge of object 2) and (the bottom edge of object 1 is lower than the top edge of object 2) and
(the top edge of object 1 is higher than the bottom edge of object 2)
then no collision occurred , otherwise a collision occurred."

First of all , that will only work if you only ever move your objects by one at a time. Second , I think you've reversed the value that is returned by it. If all three of the conditions are true then a collision has occurred (The edges are at the same position and their dimensions perpendicular to the direction of movement overlap (collide_r is for when moving right , correct?)) but you return false.

OnlineCop
Member #7,919
October 2006
avatar

Dang, mrukki, that sure is complicated.

Why have all those separate functions (and all those passed-in variables)?!

1enum Collisions
2{
3 COLLISION_NONE, COLLISION_TOP, COLLISION_RIGHT, COLLISION_BOTTOM, COLLISION_LEFT
4};
5 
6struct Objects
7{
8 int x, y; // The center of the object
9 int top, left, right, bottom; // In other words, x1, y1, x2, y2
10 BITMAP *image;
11};
12 
13int collide_rect(Objects &player1, Objects &player2)
14{
15 int result = COLLISION_NONE;
16 
17 // Check if ANY collision has occured
18 if ((player1.left > player2.right) || (player2.left > player1.right) ||
19 (player1.top > player2.bottom) || (player2.top > player1.bottom))
20 {
21 // The two players are not overlapping in any way, so exit early
22 return result;
23 }
24 
25 // A collision occurred. Now, determine where it happened...
26 if (...)
27 
28 // ...
29 
30 return result;
31}

This should tell you where the collision hit (by the returned "Collisions" value), and if it returns "none", then you don't have to do any further tests.

Having the structure such that you represent the x/y coordinates (as being the center of the image), you can even use the same structure to do rounded bounds checking (which can be even faster than rectangular bounds checking).

mrukki
Member #9,433
January 2008

Edgar Reynaldo: I have variables called walk_r, walk_l, walk_u and walk_d and if a collision occurred it turns to false and ex walk_r turns false.

OnlineCop: Thanks! :D I knew that I could made it esier but not that easy! :)

I've tried to use OnlineCops function but I getting errors :( This is my code:

if (collide_rect(image1, image2) == COLLISION_NONE)
{
walk_u = true;
walk_d = true;
walk_l = true;
walk_r = true;
}

And I get the error: invalid initialization of reference of type 'Objects&' from expression of type 'BITMAP*' in passing argument 1 of `int collide_rect(Objects&, Objects&)'

I don't understand the error but it's something with image1 and image2,
How should I do? ???

someone972
Member #7,719
August 2006
avatar

Are you passing a BITMAP* to the function, instead of an object? Here is an example of how to use it if you are:

1Objects object1,object2;
2//set up object1
3object1.left = 20;
4object1.right = 40;
5object1.top = 50;
6object1.bottom = 80;
7object1.image = image1; //assuming that image1 is the bitmap you loaded
8 
9//set up object2
10object2.left = 30;
11object2.right = 55;
12object2.top = 40;
13object2.bottom = 70;
14object2.image = image2;
15 
16if (collide_rect(object1, object2) == COLLISION_NONE)
17{
18walk_u = true;
19walk_d = true;
20walk_l = true;
21walk_r = true;
22}

Hope this helps;D.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

mrukki
Member #9,433
January 2008

Oh yeah! Thanks man! ;D I'll try this right away! ;)

EDITED: OH!! Why won't it work! I've tried all ways but it just don't work!
I used your functions and came up to this:

1enum Collisions
2{
3 COLLISION_NONE, COLLISION_TOP, COLLISION_RIGHT, COLLISION_BOTTOM, COLLISION_LEFT
4};
5 
6struct Objects
7{
8int x, y; // The center of the object
9int top, left, right, bottom; // In other words, x1, y1, x2, y2
10BITMAP *image;
11};
12 
13int collide_rect(Objects &player1, Objects &player2)
14{
15int result = COLLISION_NONE;
16int right = COLLISION_RIGHT;
17int left = COLLISION_LEFT;
18int top = COLLISION_TOP;
19int bottom = COLLISION_BOTTOM;
20 
21if ((player1.left > player2.right) || (player2.left > player1.right) ||
22(player1.top > player2.bottom) || (player2.top > player1.bottom))
23{
24return result;
25}
26 
27if (player1.right == player2.left)
28return right;
29 
30if (player1.left == player2.right)
31return left;
32 
33if ((player1.bottom == player2.top)
34return bottom;
35 
36if (player1.top == player2.bottom)
37return top;
38}
39 
40//-------------------------------------
41 
42int charx = 0;
43int chary = 0;
44 
45int l1 = charx;
46int t1 = chary;
47 
48int r1 = (l1 + image1->w);
49int b1 = (t1 + image1->h);
50 
51int l2 = 100;
52int t2 = 100;
53 
54int r2 = (l2 + image2->w);
55int b2 = (t2 + image2->h);
56 
57Objects object1,object2;
58 
59object1.left = l1;
60object1.right = r1;
61object1.top = t1;
62object1.bottom = b1;
63object1.image = image1;
64 
65object2.left = l2;
66object2.right = r2;
67object2.top = t2;
68object2.bottom = b2;
69object2.image = image2;
70 
71//----------------------------------------------------
72 
73if (collide_rect(object1, object2) == COLLISION_TOP)
74walk_u = false;
75 
76if (collide_rect(object1, object2) == COLLISION_BOTTOM)
77walk_d = false;
78 
79if (collide_rect(object1, object2) == COLLISION_RIGHT)
80walk_r = false;
81 
82if (collide_rect(object1, object2) == COLLISION_LEFT)
83walk_l = false;
84walk_r = true;
85 
86if (collide_rect(object1, object2) == COLLISION_NONE)
87{
88walk_u = true;
89walk_d = true;
90walk_l = true;
91walk_r = true;
92}

And when I get in collision it just ignore it, I don't know how to do?
Please help me! :'(

OnlineCop
Member #7,919
October 2006
avatar

You don't need the lines:

int right = COLLISION_RIGHT;
int left = COLLISION_LEFT;
int top = COLLISION_TOP;
int bottom = COLLISION_BOTTOM;

I've reworked this (haven't tested it, but logically, it should work...), but try something like this:

1enum Collisions
2{
3 COLLISION_NONE,
4 COLLISION_TOPL, COLLISION_TOPR, // top-left and top-right
5 COLLISION_BOTTOML, COLLISION_BOTTOMR // bottom-left and bottom-right
6};
7 
8struct Objects
9{
10 int x, y; // The center of the object
11 int top, left, right, bottom; // In other words, x1, y1, x2, y2
12 BITMAP *image;
13};
14 
15int collide_rect(Objects &player1, Objects &player2)
16{
17 int result = COLLISION_NONE;
18 
19 if ((player1.left > player2.right) || (player2.left > player1.right) ||
20 (player1.top > player2.bottom) || (player2.top > player1.bottom))
21 {
22 return result;
23 }
24 
25 
26 // To simplify testing, create an array where [0] is always left of [1]
27 Objects players[2];
28 if (player1.x < player2.x)
29 {
30 players[0] = player1;
31 players[1] = player2;
32 }
33 else
34 {
35 players[0] = player2;
36 players[1] = player1;
37 }
38
39 if (players[0].right > players[1].left)
40 {
41 // Possible collision on players[0]'s right side and players[1]'s left
42 
43 // Now check for vertical collision
44 if (players[0].bottom > players[1].top)
45 {
46 // players[0] collided with players[1]'s top-left
47 result = COLLISION_TOPL;
48 }
49 else if (players[0].top < players[1].bottom)
50 {
51 // players[0] collided with players[1]'s bottom-left
52 result = COLLISION_BOTTOML;
53 }
54 }
55
56 // There is no reason to do a test for "collided on the left side" since
57 // the sorting above accomplished this for us implicitely.
58 
59 // We'll need to correctly assign where the collision took place, so now
60 // test whether players[0] == player1 or player2, and swap accordingly
61 if ((players[0] == player2) && (result != COLLISION_NONE))
62 {
63 if (result == COLLISION_TOPL)
64 result = COLLISION_TOPR;
65 else
66 result = COLLISION_BOTTOMR;
67 }
68 
69 return result;
70}

It may blow up, but I THINK that it should work now.

someone972
Member #7,719
August 2006
avatar

Mrukki, in the collision detection code you posted you have the checks as '=='. Ex: if(player1.left == player2.right) This wouldn't always work because player1's left could be past player2's right and still be having a collision.

594280
Try OnlineCop's code, it should work.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

mrukki
Member #9,433
January 2008

OnlineCop: Your code is great! But it have an error :( I think this should work!:o
It's in this code thing:

if ((players[0] == player2) && (result != COLLISION_NONE))

Here's the error message:
no match for 'operator==' in 'players[0] == player2' int operator==(fix, fix) int operator==(int, fix) int operator==(fix, long int) int operator==(long int, fix) int operator==(fix, float) int operator==(float, fix) int operator==(fix, double) int operator==(double, fix)

OnlineCop
Member #7,919
October 2006
avatar

It should probably be something like:
if ((players[0] == &player2) && result != COLLISION_NONE))

The "players[0]" should be pointing to the address of player2, instead of to the object itself. See if that helps.

mrukki
Member #9,433
January 2008

I didn't work. I got the same error :-[ But thanks anyway! :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Semantically , there's nothing wrong with the line the way it was when you first got the error. From OnlineCop's code , players[0] and player2 are both 'Objects' objects. There may be some kind of include error. That's usually the only time I see the compiler suggest allegro's fixed class functions. You may have to actually write an equivalence operator for the Objects class(struct) yourself. I can't remember if the compiler supplies a default equivalence operator or not.

From http://www.cplusplus.com/doc/tutorial/classes.html :

cplusplus.com said:

But the compiler not only creates a default constructor for you if you do not specify your own. It provides three special member functions in total that are implicitly declared if you do not declare your own. These are the copy constructor, the copy assignment operator, and the default destructor.

So , no I don't believe the compiler supplies a default equivalence operator.

You could write one like this :

1struct Objects
2{
3 int x, y; // The center of the object
4 int top, left, right, bottom; // In other words, x1, y1, x2, y2
5 BITMAP *image;
6 
7 // pick one of the following two methods
8 
9 // to check if all the members are equivalent
10 bool operator==(const Objects& rightside) {
11 if (x != rightside.x) {return false;}
12 if (y != rightside.y) {return false;}
13 if (top != rightside.top) {return false;}
14 if (left != rightside.left) {return false;}
15 if (right != rightside.right) {return false;}
16 if (bottom != rightside.bottom) {return false;}
17 if (image != rightside.image) {return false;}
18
19 return true;
20 }
21 // or use this version to see if they are in fact the same object (same position in memory)
22 bool operator==(const Objects& rightside) {
23 if (this == &rightside) {return true;}
24 return false;
25 }
26};

However , you could accomplish the same thing in OnlineCop's code by making players[2] an array of two pointers to player1 and player2 instead. You can only do that as long as the function parameters are Objects& (Objects references) though.
So you would use these kind of things instead :

1Objects* players[2];
2if (player1.x < player2.x) {
3 players[0] = &player1;
4 players[1] = &player2;
5} else {
6 players[0] = &player2;
7 players[1] = &player1;
8}
9// but now you have to use the -> (dereference) operator instead of the . (member access) operator to access the data members
10if (players[0]->right > players[1]->left) {
11 // the first pointer to a player , it's player's right edge is right of the
12 // other player's left edge
13}
14 
15 
16/// And to check if the objects are the same , just compare their addresses
17if (players[0] == &player1) {// do stuff}

mrukki
Member #9,433
January 2008

Edgar Reynaldo: Thanks for the code but I think it's to difficult :) I'm just a noob and I don't want to use code that I don't understand ;) I'll tried this code but the collision don't work, the character just pass by :( What have I done wrong? ???

1struct object
2{
3int left;
4int right;
5int top;
6int bottom;
7 
8BITMAP *image;
9};
10 
11enum
12{
13collision_left,
14collision_top,
15collision_right,
16collision_bottom,
17collision_none
18};
19 
20int box_check(object &obj1, object &obj2)
21{
22if (obj1.bottom == obj2.top) { return collision_bottom; }
23if (obj1.top == obj2.bottom) { return collision_top; }
24if (obj1.right == obj2.left) { return collision_right; }
25if (obj1.left == obj2.right) { return collision_left; }
26else collision_none;
27}
28 
29if (box_check(character, tree) == collision_right)
30{
31walk_r = false;
32}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

That will only work if the character moves 1 pixel at a time. Do you remember to update the bottom right corner position values when the character moves?

In my previous post , if the code in the first window is too advanced for right now , the code in the second window was just a very minor modification to what you were using from OnlineCop's code. It was only to prevent the compiler error you were getting by allowing you to check if they were the same objects by checking to see if they had the same address in memory.

mrukki
Member #9,433
January 2008

I've updating the variables like this:

while (!key[KEY_ESC])
{
while (speed > 0)
{
l1 = charx;
t1 = chary;

r1 = (l1 + image1->w);
b1 = (t1 + image1->h);

character.left = l1;
character.right = r1;
character.top = t1;
character.bottom = b1;

Yeah, But I think I'll first try to get my code to work :) But thank for the codes I'll look at it and try to understand ;D

 1   2 


Go to: