2 Replies - 241 Views - Last Post: 21 April 2013 - 06:56 AM Rate Topic: -----

#1 Bawnawgwa  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 21-January 13

Detect hit from projectile problem

Posted 20 April 2013 - 09:21 PM

void playBoss(){
	int olddirection = 0, newdirection = 0;
	int bossDirection;
	int health = 500;
	int activate = 0;
	initSectors2();
	initSectors3();
	do {
		bossDirection = rand() % 4;
		for(int k = 0; k < 20; k++){
		if(bossDirection == 0)
			newdirection = 1;
		if(bossDirection == 1)
			newdirection = 0;
		if(bossDirection == 2)
			newdirection = 2;
		if(bossDirection == 3)
			newdirection = 3;
			if(boss[newdirection].xCoord == character[0].xCoord){
				if(boss[newdirection].yCoord < character[0].yCoord)
					newdirection = 7;
				if(boss[newdirection].yCoord > character[0].yCoord)
					newdirection = 6;
				k = 19;
			}
			if(boss[newdirection].xCoord == character[1].xCoord){
				if(boss[newdirection].yCoord < character[1].yCoord)
					newdirection = 7;
				if(boss[newdirection].yCoord > character[1].yCoord)
					newdirection = 6;
				k = 19;
			}
			if(boss[newdirection].xCoord == character[2].xCoord){
				if(boss[newdirection].yCoord < character[2].yCoord)
					newdirection = 7;
				if(boss[newdirection].yCoord > character[2].yCoord)
					newdirection = 6;
				k = 19;
			}
			if(boss[newdirection].xCoord == character[3].xCoord){
				if(boss[newdirection].yCoord < character[3].yCoord)
					newdirection = 7;
				if(boss[newdirection].yCoord > character[3].yCoord)
					newdirection = 6;
				k = 19;
			}
			if(boss[newdirection].yCoord == character[0].yCoord){
				if(boss[newdirection].xCoord < character[0].xCoord)
					newdirection = 4;
				if(boss[newdirection].xCoord > character[0].xCoord)
					newdirection = 5;
				k = 19;
			}
			if(boss[newdirection].yCoord == character[1].yCoord){
				if(boss[newdirection].xCoord < character[1].xCoord)
					newdirection = 4;
				if(boss[newdirection].xCoord > character[1].xCoord)
					newdirection = 5;
				k = 19;
			}
			if(boss[newdirection].yCoord == character[2].yCoord){
				if(boss[newdirection].xCoord < character[2].xCoord)
					newdirection = 4;
				if(boss[newdirection].xCoord > character[2].xCoord)
					newdirection = 5;
				k = 19;
			}
			if(boss[newdirection].yCoord == character[3].yCoord){
				if(boss[newdirection].xCoord < character[3].xCoord)
					newdirection = 4;
				if(boss[newdirection].xCoord > character[3].xCoord)
					newdirection = 5;
				k = 19;
			}
						
					

			
	
	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();
	//for(int k = 0; k < 20; k++){
	boss_animation();
	hitBoss();
	Sleep(40);
	check_boss();
	}
	activate = 1;
	}
	while(health > 0);
	
}
void hitBoss(){
	int bossHealth = 500;
	char bossHealthBuff[50];
	int hitBoss = 0;
	sprintf(bossHealthBuff, "Paymon's Health: %d", bossHealth);
	outtextxy(600, 25, bossHealthBuff);

		if(character[4].xCoord > boss[0].xCoord && character[4].yCoord > boss[0].yCoord && character[4].xCoord < boss[0].xCoord+50 && character[4].yCoord < boss[0].yCoord+50
			|| character[5].xCoord > boss[0].xCoord && character[5].yCoord > boss[0].yCoord && character[5].xCoord < boss[0].xCoord+50 && character[5].yCoord < boss[0].yCoord+50
			|| character[6].xCoord > boss[0].xCoord && character[6].yCoord > boss[0].yCoord && character[6].xCoord < boss[0].xCoord+50 && character[6].yCoord < boss[0].yCoord+50
			|| character[7].xCoord > boss[0].xCoord && character[7].yCoord > boss[0].yCoord && character[7].xCoord < boss[0].xCoord+50 && character[7].yCoord < boss[0].yCoord+50){
				hitBoss = 1;}
		if(character[4].xCoord > boss[1].xCoord && character[4].yCoord > boss[1].yCoord && character[4].xCoord < boss[1].xCoord+50 && character[4].yCoord < boss[1].yCoord+50
			|| character[5].xCoord > boss[1].xCoord && character[5].yCoord > boss[1].yCoord && character[5].xCoord < boss[1].xCoord+50 && character[5].yCoord < boss[1].yCoord+50
			|| character[6].xCoord > boss[1].xCoord && character[6].yCoord > boss[1].yCoord && character[6].xCoord < boss[1].xCoord+50 && character[6].yCoord < boss[1].yCoord+50
			|| character[7].xCoord > boss[1].xCoord && character[7].yCoord > boss[1].yCoord && character[7].xCoord < boss[1].xCoord+50 && character[7].yCoord < boss[1].yCoord+50){
				hitBoss = 1;}
		if(character[4].xCoord > boss[2].xCoord && character[4].yCoord > boss[2].yCoord && character[4].xCoord < boss[2].xCoord+50 && character[4].yCoord < boss[2].yCoord+50
			|| character[5].xCoord > boss[2].xCoord && character[5].yCoord > boss[2].yCoord && character[5].xCoord < boss[2].xCoord+50 && character[5].yCoord < boss[2].yCoord+50
			|| character[6].xCoord > boss[2].xCoord && character[6].yCoord > boss[2].yCoord && character[6].xCoord < boss[2].xCoord+50 && character[6].yCoord < boss[2].yCoord+50
			|| character[7].xCoord > boss[2].xCoord && character[7].yCoord > boss[2].yCoord && character[7].xCoord < boss[2].xCoord+50 && character[7].yCoord < boss[2].yCoord+50){
				hitBoss = 1;}
		if(character[4].xCoord > boss[3].xCoord && character[4].yCoord > boss[3].yCoord && character[4].xCoord < boss[3].xCoord+50 && character[4].yCoord < boss[3].yCoord+50
			|| character[5].xCoord > boss[3].xCoord && character[5].yCoord > boss[3].yCoord && character[5].xCoord < boss[3].xCoord+50 && character[5].yCoord < boss[3].yCoord+50
			|| character[6].xCoord > boss[3].xCoord && character[6].yCoord > boss[3].yCoord && character[6].xCoord < boss[3].xCoord+50 && character[6].yCoord < boss[3].yCoord+50
			|| character[7].xCoord > boss[3].xCoord && character[7].yCoord > boss[3].yCoord && character[7].xCoord < boss[3].xCoord+50 && character[7].yCoord < boss[3].yCoord+50){
				hitBoss = 1;}

		if(hitBoss == 1){
			bossHealth = bossHealth - 10;}
}


So this controls the movement and animation of my boss in my game. The playBoss() moves him and when crossing paths with character shoots at character (kinda... haha).

My issue is with my hitBoss(). This is supposed to detect when the character's attack has hit the boss, and when it does it is supposed to subtract 10 from his health. So far this is not doing what I had intended... (btw, 0-3 in boxes([]) is movement, and 4-7 is shooting projectile.

Am I on the right track with getting collision of projectile down? By making a new function? Or does it need to be placed inside somewhere?

Thanks for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: Detect hit from projectile problem

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4017
  • View blog
  • Posts: 12,400
  • Joined: 25-December 09

Re: Detect hit from projectile problem

Posted 21 April 2013 - 05:42 AM

Doesn't really look like a C/C++ question, moving to Game Development.


Jim
Was This Post Helpful? 0
  • +
  • -

#3 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Detect hit from projectile problem

Posted 21 April 2013 - 06:56 AM

Your long if conditions need to be reworked, you can't properly debug what is going on when your code is structured like that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1