PDA

View Full Version : [FMX,AS2] game help - hittest and distance



Jezik
April 26th, 2005, 03:39 PM
actionscript help in game
i am working on a game called "virus".
you click somewhere on the screen and the virus goes to where you click.
you have to dodge random moving white blood cells, and if you hit them you lose. everything is working. except for one thing.

scoring.

i have made a movieclip with a dynamic textbox in (score), and in the movie clip there is a section where the number in the score textbox goes up really quickly, a section where is goes up medium, and a section where it goes up slowly.
i want to make it so that when you get closer to the center of the movie, for the score to go up quicly, and slower as you get further out.

i have tried hittest with movie clips in the centre of the stage, but it doesnt seem to work.

i have flash mx 2004.

help very much appreciated. thanks a lot in advance!

:)

Ringer
April 26th, 2005, 04:51 PM
You'll want to use distance. If you remember your geometry:



distance = root (x^2 + y^2)


So you can easily enough just use a formula. In fact, screw the three different point earning speeds. Place this on your virus movie clip's onLoad:




var frame = 0;
var secScore = 0;


And this on the onEnterFrame:



//calculates the distance of the virus from the center of the screen, assuming you have a 500*500 screen (adjust as needed)
distance = Math.sqrt(Math.pow(_x-250, 2) + Math.pow(_y-250, 2));
//adds the reciprocal of the distance times 500 to the score for this second
secScore += int(500/distance);
//increments a frame variable. When it hits 30 (or whatever framerate you have) it adds the second's score to the main score and resets to 0
frame ++;
if (frame >= 30) {
//This is assuming the final score is called _root.score
_root.score += secScore;
secScore = 0;
frame = 0;
}


That should do. Nice effect of only integer scores updated every second. ;P

Jezik
April 26th, 2005, 05:11 PM
ok kool but to set up this movie do i have the score counter as a dynamic txt box on the stage called score?

Jezik
April 26th, 2005, 05:15 PM
the AS doesnt work, the text box just says "NaN" for som reason