Animation now accounts for X acceleration.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3325 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -66,6 +66,7 @@ public class SparkAnimation extends Animation
|
|||||||
// save things off
|
// save things off
|
||||||
_ox = x;
|
_ox = x;
|
||||||
_oy = y;
|
_oy = y;
|
||||||
|
_xacc = xacc;
|
||||||
_yacc = yacc;
|
_yacc = yacc;
|
||||||
_images = images;
|
_images = images;
|
||||||
_delay = delay;
|
_delay = delay;
|
||||||
@@ -80,27 +81,37 @@ public class SparkAnimation extends Animation
|
|||||||
for (int ii = 0; ii < _icount; ii++) {
|
for (int ii = 0; ii < _icount; ii++) {
|
||||||
// initialize spark position
|
// initialize spark position
|
||||||
int ajog = (jog == 0) ? 0 : RandomUtil.getInt(jog);
|
int ajog = (jog == 0) ? 0 : RandomUtil.getInt(jog);
|
||||||
_xpos[ii] = x + ajog * getDirectionMult();
|
_xpos[ii] = x + ajog * randomDirection();
|
||||||
_ypos[ii] = y + ajog * getDirectionMult();
|
_ypos[ii] = y + ajog * randomDirection();
|
||||||
|
|
||||||
// choose a random x-axis velocity between the minimum and
|
// Choose random X and Y axis velocities between the inputted
|
||||||
// maximum passed in, and moving left or right at random
|
// bounds
|
||||||
_sxvel[ii] = Math.max(RandomUtil.getFloat(xvel), minxvel) *
|
_sxvel[ii] = minxvel + RandomUtil.getFloat(1) * (xvel - minxvel);
|
||||||
getDirectionMult();
|
_syvel[ii] = minyvel + RandomUtil.getFloat(1) * (yvel - minyvel);
|
||||||
|
|
||||||
// choose a random y-axis velocity between the minimum and
|
// If accelerationes were given, make the starting velocities
|
||||||
// maximum passed in. if there is any gravitational
|
// move against that acceleration; otherwise pick directions
|
||||||
// acceleration, make the y-axis velocity negative; else,
|
// at random
|
||||||
// choose to move up or down at random.
|
if (_xacc > 0) {
|
||||||
_syvel[ii] = (Math.max(RandomUtil.getFloat(yvel), minyvel)) *
|
_sxvel[ii] = -_sxvel[ii];
|
||||||
((_yacc != 0) ? -1.0f : getDirectionMult());
|
} else if (_xacc == 0) {
|
||||||
|
_sxvel[ii] *= randomDirection();
|
||||||
|
}
|
||||||
|
if (_yacc > 0) {
|
||||||
|
_syvel[ii] = -_syvel[ii];
|
||||||
|
} else if (_yacc == 0) {
|
||||||
|
_syvel[ii] *= randomDirection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpha = 1.0f;
|
_alpha = 1.0f;
|
||||||
_comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha);
|
_comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getDirectionMult ()
|
/**
|
||||||
|
* Returns at random -1 for negative direction or +1 for positive.
|
||||||
|
*/
|
||||||
|
protected int randomDirection ()
|
||||||
{
|
{
|
||||||
return (RandomUtil.getInt(2) == 0) ? -1 : 1;
|
return (RandomUtil.getInt(2) == 0) ? -1 : 1;
|
||||||
}
|
}
|
||||||
@@ -134,7 +145,8 @@ public class SparkAnimation extends Animation
|
|||||||
// move all sparks and check whether any remain to be animated
|
// move all sparks and check whether any remain to be animated
|
||||||
for (int ii = 0; ii < _icount; ii++) {
|
for (int ii = 0; ii < _icount; ii++) {
|
||||||
// determine the travel distance
|
// determine the travel distance
|
||||||
int xtrav = (int)(_sxvel[ii] * msecs);
|
int xtrav = (int)
|
||||||
|
((_sxvel[ii] * msecs) + (0.5f * _xacc * (msecs * msecs)));
|
||||||
int ytrav = (int)
|
int ytrav = (int)
|
||||||
((_syvel[ii] * msecs) + (0.5f * _yacc * (msecs * msecs)));
|
((_syvel[ii] * msecs) + (0.5f * _yacc * (msecs * msecs)));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user