what's crashing...

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

what's crashing...

Post by Energy »

Hey all

I'm pulling my hair out over this... Here's my code:

Code: Select all

void update_player_explosions()
{
	int i, q;
	int poss_distance;
	int radius_squared;
	int distance_squared;
	int true_distance;

	for&#40;i=0; i<50; i++&#41;
	&#123;
		if&#40;p_missiles&#91;i&#93;.active == 2&#41;
		&#123;
			PlotCircle&#40;p_missiles&#91;i&#93;.final_x, p_missiles&#91;i&#93;.final_y, &#40;int&#41; p_missiles&#91;i&#93;.radius, 0x0000FF&#41;;

			for&#40;q=0; q<50; q++&#41;
			&#123;
				if&#40;e_missiles&#91;q&#93;.active == 1&#41;
				&#123;
					poss_distance = 0;
					radius_squared = &#40;&#40;int&#41;p_missiles&#91;i&#93;.radius * &#40;int&#41;p_missiles&#91;i&#93;.radius&#41;;
					distance_squared = &#40;abs&#40;e_missiles&#91;q&#93;.current_x - p_missiles&#91;i&#93;.final_x&#41;&#41; * &#40;abs&#40;e_missiles&#91;q&#93;.current_x - p_missiles&#91;i&#93;.final_x&#41;&#41;;
					poss_distance = &#40;radius_squared - distance_squared&#41; / &#40;radius_squared - distance_squared&#41;;

					true_distance = abs&#40;e_missiles&#91;q&#93;.current_y - p_missiles&#91;i&#93;.final_y&#41;;

					if&#40;true_distance <= poss_distance&#41;
					&#123;
						//e_missiles&#91;q&#93;.active = 0;
						//missile_count--;
						printf&#40;"X"&#41;;
					&#125;
				&#125;
			&#125;

			p_missiles&#91;i&#93;.radius = p_missiles&#91;i&#93;.radius - 0.2;

			if&#40;p_missiles&#91;i&#93;.radius <= 0&#41;
			&#123;
				p_missiles&#91;i&#93;.active = 0;
			&#125;

		&#125;
	&#125;
&#125;
Now, whenever the :

Code: Select all

if&#40;true_distance <= poss_distance&#41;
&#123;
	//e_missiles&#91;q&#93;.active = 0;
	//missile_count--;
	printf&#40;"X"&#41;;
&#125;
is reached the system will run the code in the brackets and freeze.
I'm just trying to find whether a point is within a circle. I'm testing every drawn explosion and every missile on the screen.

Any ideas? I'm on a 2.0 system, could it be possible that it's that what is making it crash? If I comment out that if statment, then there are no problems.... argh!!!!

The reason those two lines are commented out are to show that it doesn't matter what's in there it will still crash. If you shoot and no missiles are in the explosion then there is uaully no problem... :/

help >_>
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

oh dear... can I really be that stupid????
I guess I can... another thread you can all ignore. Suppose the best way to learn is trial and error... :(

Don't exactly know why it fixes it, but if you put the correct maths in, it does help a lot. AKA try using the sqrt function instead of (radius_squared - distance_squared) / (radius_squared - distance_squared).

I'm what is known as a idiot.
Post Reply