trial game collision detection problem

Hello! I have just started using Allegro to create a simple game and I'm having problems with the collision detection. here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
void InitBad(BadGuy &bad)
{
	bad.x = 600;
	bad.y = 200;
	bad.ID = ENEMY;
	bad.boundx = bad.x + 30;
	bad.boundy = bad.y + 30;
	bad.live = true;
}
void DrawBad(BadGuy &bad)
{
	if(bad.live)
	{
		al_draw_filled_rectangle(bad.x, bad.y, bad.x + 30, bad.y + 30, al_map_rgb(0, 0, 255));
		}
}
void InitSword(Sword &sword)
{
	sword.ID = SWORD;
	sword.live = false;
	sword.boundx = sword.x + 30;
	sword.boundy = sword.y + 15;
}
void DrawSword(Sword &sword, Dude &dude)
{
	if(sword.live)
	{
		al_draw_filled_rectangle(dude.x + 30, dude.y + 12, dude.x + 60, dude.y + 17, al_map_rgb(127, 127, 127));
	}
}
void SwingSword(Sword &sword, Dude &dude)
{
	if(!sword.live)
	{
		sword.x = dude.x + 30;
		sword.y = dude.y + 15;
		sword.live = true;
	}
}
void UpdateSword(Sword &sword)
{
	if(sword.live)
		sword.live = false;
}
void CollideSword(Sword &sword, BadGuy &bad)
{
	if(sword.live)
	{
		if(bad.live)
		{
			if(sword.boundx < (bad.x + bad.boundx) &&
				sword.boundx > (bad.x - bad.boundx) &&
				sword.boundy < (bad.y + bad.boundy) &&
				sword.boundy > (bad.y - bad.boundy))
			{
				bad.live = false;
			}
		}
	}
}


these are all my functions that have to do with collision. If you have any suggestions or need help understanding this just let me know. Thank you for any help.
Last edited on
Topic archived. No new replies allowed.