Added construction interface for X axis acceleration.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3324 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ted V
2005-02-01 20:22:09 +00:00
parent bf463e46e9
commit 6206d9f71b
@@ -1,5 +1,5 @@
// //
// $Id: SparkAnimation.java,v 1.4 2004/08/27 02:12:38 mdb Exp $ // $Id$
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -50,21 +50,23 @@ public class SparkAnimation extends Animation
* @param minyvel the minimum starting y-velocity of the sparks. * @param minyvel the minimum starting y-velocity of the sparks.
* @param xvel the maximum x-velocity of the sparks. * @param xvel the maximum x-velocity of the sparks.
* @param yvel the maximum y-velocity of the sparks. * @param yvel the maximum y-velocity of the sparks.
* @param g the gravitational acceleration, or 0 if none is desired. * @param xacc the x axis acceleration, or 0 if none is desired.
* @param yacc the y axis acceleration, or 0 if none is desired.
* @param images the spark images to be animated. * @param images the spark images to be animated.
* @param delay the duration of the animation in milliseconds. * @param delay the duration of the animation in milliseconds.
*/ */
public SparkAnimation (Rectangle bounds, int x, int y, int jog, public SparkAnimation (Rectangle bounds, int x, int y, int jog,
float minxvel, float minyvel, float minxvel, float minyvel,
float xvel, float yvel, float xvel, float yvel,
float g, Mirage[] images, long delay) float xacc, float yacc,
Mirage[] images, long delay)
{ {
super(bounds); super(bounds);
// save things off // save things off
_ox = x; _ox = x;
_oy = y; _oy = y;
_g = g; _yacc = yacc;
_images = images; _images = images;
_delay = delay; _delay = delay;
@@ -91,7 +93,7 @@ public class SparkAnimation extends Animation
// acceleration, make the y-axis velocity negative; else, // acceleration, make the y-axis velocity negative; else,
// choose to move up or down at random. // choose to move up or down at random.
_syvel[ii] = (Math.max(RandomUtil.getFloat(yvel), minyvel)) * _syvel[ii] = (Math.max(RandomUtil.getFloat(yvel), minyvel)) *
((g != 0) ? -1.0f : getDirectionMult()); ((_yacc != 0) ? -1.0f : getDirectionMult());
} }
_alpha = 1.0f; _alpha = 1.0f;
@@ -134,7 +136,7 @@ public class SparkAnimation extends Animation
// determine the travel distance // determine the travel distance
int xtrav = (int)(_sxvel[ii] * msecs); int xtrav = (int)(_sxvel[ii] * msecs);
int ytrav = (int) int ytrav = (int)
((_syvel[ii] * msecs) + (0.5f * _g * (msecs * msecs))); ((_syvel[ii] * msecs) + (0.5f * _yacc * (msecs * msecs)));
// update the position // update the position
_xpos[ii] = _ox + xtrav; _xpos[ii] = _ox + xtrav;
@@ -179,8 +181,11 @@ public class SparkAnimation extends Animation
/** The number of images we're animating. */ /** The number of images we're animating. */
protected int _icount; protected int _icount;
/** The gravitational acceleration in pixels per millisecond. */ /** The x axis acceleration in pixels per millisecond. */
protected float _g; protected float _xacc;
/** The y axis acceleration in pixels per millisecond. */
protected float _yacc;
/** The starting x-axis velocity of each chunk. */ /** The starting x-axis velocity of each chunk. */
protected float[] _sxvel; protected float[] _sxvel;