Descriptive Subject, huh? Okay, the problem is: In _Access, you will sometimes be hunted by tracers. I want the game to play a "beep" sound every x game cycles, where x depends on the distance between the player and the tracer. I use this code to determine the distance:
int distancey=player.y-cTrac.y;
float dy=IntToFloat(distancey*distancey);
distancey=FloatToInt(Maths.Sqrt(dy));
int distancex=player.x-cTrac.x;
float dx=IntToFloat(distancex*distancex);
distancex=FloatToInt(Maths.Sqrt(dx));
int distance=distancex-distancey;
float d=IntToFloat(distance*distance);
distance=FloatToInt(Maths.Sqrt(d));
The sqrt thing is to ensure the result is always positive. Now, the code for playing the sound:
if (IsTimerExpired(1)){
PlaySound(0);
//determine distance
SetTimer(1, distance/2);
But this code somehow screws up pretty fast. It works, yes, but not perfect. Any suggestions how to make this a little more error-resistant?
Your code will beep fastest if the tracer is on a diagonal with the player.
Here's what you want to do:
// startup
SetTimer(1, Random(100));
// repex
if (IsTimerExpired(1)) {
PlaySound(0);
int minTime = 8;
float dx = IntToFloat(player.x - cTrac.x);
float dy = IntToFloat(player.y - cTrac.y); // FIXED player.x -> player.y
int distance = FloatToInt(Maths.Sqrt(dx*dx + dy*dy));
SetTimer(1, minTime + distance/2);
}
Does not work as intended, sorry. :P
Fixed. My apologies.
Works now. Thank you!