Checking for images crossing paths with each other?

Write your question here.

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
61
62
63
64
65
66
  void playBoss(){
	int olddirection = 0, newdirection = 0; //initial values
	int bossDirection;
	int activate = 0;
	bossRoom();

	do {
		bossDirection = rand() % 4; //random starting direction
		for(int k = 0; k < 20; k++){ //keeps boss moving in same direction for more than one movement
		if(bossDirection == 0)
			newdirection = 1;
		if(bossDirection == 1)
			newdirection = 0;
		if(bossDirection == 2)
			newdirection = 2;
		if(bossDirection == 3)
			newdirection = 3;
	
		//This next chunk of code determines if the character's x and y coordinates cross paths with the boss's.
		//If they do, the boss will shoot at the character in the proper direction.

		/*for(int j = boss[newdirection].xCoord-5; j < boss[newdirection].xCoord+55; j++){
			for(int k = boss[newdirection].yCoord-5; k < boss[newdirection].yCoord+55; k++){			
			
				for(int i = 0; i < 4; i++){	
						if(j == character[i].xCoord-5 || j == character[i].xCoord+55){
							if(boss[newdirection].yCoord > character[i].yCoord+50)
								newdirection = 6;
							if(boss[newdirection].yCoord+50 < character[i].yCoord)
								newdirection = 7;
						k = 20;
						}
						if(k == character[i].yCoord-5 || k == character[i].yCoord+55){
							if(boss[newdirection].xCoord+50 < character[i].xCoord)
								newdirection = 4;
							if(boss[newdirection].xCoord > character[i].xCoord+50)
								newdirection = 5;
						k = 20;
						}
					}
				}*/
			//}
						
			//printf("DONE\n");	
	if(olddirection != newdirection){
		boss[newdirection].xCoord = boss[olddirection].xCoord;
		boss[newdirection].yCoord = boss[olddirection].yCoord;
		
		boss[olddirection].drawable = 0;
		boss[newdirection].drawable = 1;
		boss[newdirection].currentFrame = 0;
		if(newdirection == 0 || newdirection == 1 || newdirection == 2 || newdirection == 3){
		olddirection = newdirection;}
	}
	checkSectorsBoss();
	shadowballSectors();
	boss_animation();
	//Sleep(20);
	check_boss();
	}
	if(bossHealth <= 0)
		Victory(); //when boss dies, victory screen and music appear
	}//end while
	while(bossHealth > 0);
	
}//end playBoss 


Yeah yeah the first if statements dealing with newdirection waste space and are unnecessary. I'll fix eventually but it works just fine and doesn't need to be fixed NOW.

So my issue... The commented out portion, just below those first if statements, is an attempt to detect when character and boss cross paths. Either x coordinates or y coordinates match up.

This is not working. He sometimes shoots in the wrong direction or just doesn't shoot.

I was wondering if anyone could help me devise a simple way in which I could test for cross passing. And if they cross paths, then have him shoot int he proper direction.

Btw: newdirection = 4 - shoot right, 5 - shoot left, 6 - shoot up, 7 - shoot down.
0 - boss moves right, 1 - moves left, 2 - moves up, 3 - moves down.
an attempt to detect when character and boss cross paths. Either x coordinates or y coordinates match up.

Do you mean something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if ( boss.x == player.x && boss.y == player.y )
{
  // Spot on, bite, stomp, ...
}
else if ( boss.x == player.x )
{
  if ( boss.y < player.y ) // Shoot up
  else // Shoot down
}
else if ( boss.y == player.y )
{
  if ( boss.x < player.x ) // Shoot right
  else // Shoot left
}
Topic archived. No new replies allowed.