summaryrefslogtreecommitdiff
path: root/java/gjt/test/TwoDrinkersAnimationTest.java
diff options
context:
space:
mode:
authorpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 18:12:58 +0000
committerpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 18:12:58 +0000
commit193064fe76af85d8963bba3f1e91b873d955c6d8 (patch)
treeba4b0a7a26bf46ea298496a434496695db55bdc1 /java/gjt/test/TwoDrinkersAnimationTest.java
parent40e0a419db16f5c42865615794fdcf5d76329726 (diff)
downloadATCD-193064fe76af85d8963bba3f1e91b873d955c6d8.tar.gz
Added gjt to CVS
Diffstat (limited to 'java/gjt/test/TwoDrinkersAnimationTest.java')
-rw-r--r--java/gjt/test/TwoDrinkersAnimationTest.java130
1 files changed, 130 insertions, 0 deletions
diff --git a/java/gjt/test/TwoDrinkersAnimationTest.java b/java/gjt/test/TwoDrinkersAnimationTest.java
new file mode 100644
index 00000000000..ae4041b9eb6
--- /dev/null
+++ b/java/gjt/test/TwoDrinkersAnimationTest.java
@@ -0,0 +1,130 @@
+package gjt.test;
+
+import java.net.URL;
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.Panel;
+
+import gjt.Util;
+import gjt.Orientation;
+import gjt.animation.*;
+
+/**
+ * An animation playfield containing two "java drinkers", that
+ * both bounce off the sides of the playfield.<p>
+ *
+ * One of the java drinkers moves slow and spins fast, while
+ * the other java drinker moves fast and spins slow. When
+ * the two java drinkers collide, they both play a bump
+ * sequence - at different speeds.<p>
+ *
+ * @version 1.0, Apr 1 1996
+ * @author David Geary
+ * @see gjt.test.AnimationTest
+ * @see gjt.animation.Playfield
+ * @see gjt.animation.Sprite
+ */
+public class TwoDrinkersAnimationTest extends UnitTest {
+ public String title() {
+ return
+ "TwoDrinkers Animation - Mouse Down Starts/Stops";
+ }
+ public Panel centerPanel() {
+ return new TwoDrinkersAnimationTestPanel(this);
+ }
+}
+
+class TwoDrinkersAnimationTestPanel extends Panel {
+ public TwoDrinkersAnimationTestPanel(Applet applet) {
+ setLayout(new BorderLayout());
+ add("Center", new TwoDrinkersPlayfield(applet));
+ }
+}
+
+class TwoDrinkersPlayfield extends Playfield {
+ private Applet applet;
+ private URL cb;
+ private Sprite moveFastSpinSlow, moveSlowSpinFast;
+ private Sequence fastSpinSequence,
+ slowSpinSequence,
+ fastBumpSequence,
+ slowBumpSequence;
+
+ public TwoDrinkersPlayfield(Applet applet) {
+ this.applet = applet;
+ cb = applet.getCodeBase();
+ makeSequencesAndSprites();
+ }
+ public void paintBackground(Graphics g) {
+ Image bg = applet.getImage(cb, "gifs/background.gif");
+ Util.wallPaper(this, g, bg);
+ }
+ public boolean mouseDown(Event event, int x, int y) {
+ if(running() == true) stop ();
+ else start();
+ return true;
+ }
+ public void spriteCollision(Sprite sprite, Sprite sprite2) {
+ if(moveSlowSpinFast.getSequence() != fastBumpSequence) {
+ sprite.reverse();
+ sprite2.reverse();
+
+ moveSlowSpinFast.play(fastBumpSequence, 3);
+ moveFastSpinSlow.play(slowBumpSequence, 3);
+ }
+ }
+ public void edgeCollision(Sprite sprite,
+ Orientation orientation) {
+ if(orientation == Orientation.RIGHT ||
+ orientation == Orientation.LEFT)
+ sprite.reverseX();
+ else
+ sprite.reverseY();
+ }
+ private void makeSequencesAndSprites() {
+ String file;
+ Image[] spinImages = new Image[19];
+ Image[] bumpImages = new Image[6];
+ Image[] volleyball = new Image[4];
+
+ for(int i=0; i < spinImages.length; ++i) {
+ file = "gifs/spin";
+
+ if(i < 10) file += "0" + i + ".gif";
+ else file += i + ".gif";
+
+ spinImages[i] = applet.getImage(cb, file);
+ }
+ for(int i=0; i < bumpImages.length; ++i) {
+ file = "gifs/bump0" + i + ".gif";
+ bumpImages[i] = applet.getImage(cb, file);
+ }
+ fastSpinSequence = new Sequence(this, spinImages);
+ slowSpinSequence = new Sequence(this, spinImages);
+
+ fastBumpSequence = new Sequence(this, bumpImages);
+ slowBumpSequence = new Sequence(this, bumpImages);
+
+ moveFastSpinSlow =
+ new Sprite(this,
+ slowSpinSequence, new Point(25, 75));
+
+ moveSlowSpinFast =
+ new Sprite(this,
+ fastSpinSequence, new Point(250,250));
+
+ fastSpinSequence.setAdvanceInterval(50);
+ slowSpinSequence.setAdvanceInterval(300);
+
+ fastBumpSequence.setAdvanceInterval(25);
+ slowBumpSequence.setAdvanceInterval(200);
+
+ moveFastSpinSlow.setMoveVector(new Point(2,3));
+ moveSlowSpinFast.setMoveVector(new Point(-1,-1));
+
+ moveSlowSpinFast.setMoveInterval(100);
+
+ addSprite(moveFastSpinSlow);
+ addSprite(moveSlowSpinFast);
+ }
+}