/* * Copyright (c) 1998 Kevan Stannard. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and * without fee is hereby granted. * * Please note that this software comes with * NO WARRANTY * * BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED * BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES * PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS * TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. * * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER * PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, * INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE * THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED * BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER * OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ import java.applet.*; import java.awt.*; ///////////////////////////////////////////////////////////////////// class Sprite extends Panel { // constants final int MAX_ANIMS = 10; final int MAX_FRAMES = 30; // variables Image frame[] = new Image[MAX_FRAMES]; int frameWidth[] = new int[MAX_FRAMES]; int frameHeight[] = new int[MAX_FRAMES]; boolean frameUsed[] = new boolean[MAX_FRAMES]; boolean allLoaded = true; int width = 500; int height = 150; // Animation Processor int interrupt = -1; float xPos = 250-30; float yPos = 0; int xoff = 0; int yoff = 0; int currFrame = -1; int wait = 0; final int SHOW = 100; final int WAIT = 101; final int RANDOM_WAIT = 102; final int LEFT = 103; final int RIGHT = 104; final int END = 999; int animTest[] = { END }; int animStand[] = { SHOW,0,0,0, RANDOM_WAIT,10,30, END }; int animBlink[] = { SHOW,1,3,1, WAIT,1, SHOW,2,4,2, WAIT,1, SHOW,1,3,1, WAIT,1, SHOW,0,0,0, END }; int animAngry[] = { SHOW,3,2,4, WAIT,1, SHOW,4,4,5, RANDOM_WAIT,30,20, SHOW,3,2,4, WAIT,1, SHOW,0,0,0, END }; int animHappy[] = { SHOW,5,1,-1, WAIT,1, SHOW,6,0,-4, RANDOM_WAIT,10,40, SHOW,5,1,-1, WAIT,1, SHOW,0,0,0, END }; int animLeft[] = { SHOW,7,0,4, LEFT,21, WAIT,1, SHOW,8,0,4, LEFT,6, WAIT,1, SHOW,9,0,0, LEFT,11, WAIT,1, SHOW,10,0,4, LEFT,10, WAIT,1, SHOW,11,0,5, LEFT,28, WAIT,1, SHOW,12,0,2, LEFT,6, WAIT,1, SHOW,13,0,1, LEFT,10, WAIT,1, SHOW,14,0,1, LEFT,15, WAIT,1, END }; int animRight[] = { SHOW,15,0,4, RIGHT,8, WAIT,1, SHOW,16,0,4, RIGHT,6, WAIT,1, SHOW,17,0,0, RIGHT,38, WAIT,1, SHOW,18,0,4, RIGHT,5, WAIT,1, SHOW,19,0,5, RIGHT,5, WAIT,1, SHOW,20,0,2, RIGHT,5, WAIT,1, SHOW,21,0,1, RIGHT,40, WAIT,1, SHOW,22,0,1, RIGHT,2, WAIT,1, END }; //int animInterrupt[]; // animation interrupt pointer int anim[] = animStand; // reference to first movement int pc = 0; // program counter // constructors Sprite() { for (int i=0; i=30 && rnd<40) { anim = animAngry; } else if (rnd>=40 && rnd<70) { anim = animHappy; } else if (rnd>=70 && rnd<85) { anim = animLeft; } else { anim = animRight; } } else if (anim == animAngry) { anim = animStand; } else if (anim == animHappy) { anim = animStand; } else if (anim == animLeft) { double rnd = Math.random()*100; if (rnd<80) { anim = animLeft; } else { anim = animStand; } } else if (anim == animRight) { double rnd = Math.random()*100; if (rnd<80) { anim = animRight; } else { anim = animStand; } } else { anim = animStand; } pc = 0; break; } case SHOW: { currFrame = anim[pc+1]; xoff = anim[pc+2]; yoff = anim[pc+3]; pc += 4; break; } case WAIT: { wait = anim[pc+1]; pc += 2; break; } case RANDOM_WAIT: { wait = anim[pc+1] + (int) (Math.random() * anim[pc+2]); pc += 3; break; } case LEFT: { xPos -= anim[pc+1]; pc += 2; if (xPos<-60) { xPos = width; } break; } case RIGHT: { xPos += anim[pc+1]; pc += 2; if (xPos>width) { xPos = -60; } break; } } } if (currFrame >= 0) { g.drawImage(frame[currFrame], xoff + (int) xPos, yoff + (int) yPos, null); } } void addFrame(Image img, int f) { if (frame[f] == null) { frame[f] = img; MediaTracker tracker = new MediaTracker(this); tracker.addImage(frame[f],0); try { tracker.waitForAll(); allLoaded = allLoaded && !tracker.isErrorAny(); } catch (InterruptedException e) { } if (allLoaded) { frameWidth[f] = img.getWidth(this); frameHeight[f] = img.getHeight(this); } else { frameWidth[f] = 0; frameHeight[f] = 0; } } } boolean allLoaded() { return allLoaded; } } ///////////////////////////////////////////////////////////////////// public class JZOODontClickHere extends Applet implements Runnable { // Thread Thread thread = null; // Image boolean allLoaded = false; // Sprite int numSprites = 5; Sprite s[] = new Sprite[numSprites]; // Double buffer Image db; Graphics dbGraphics; // background Image bg; Graphics bgGraphics; // Applet int width = 0; int height = 0; public void init() { // get parameters width = Integer.valueOf(getParameter("width")).intValue(); height = Integer.valueOf(getParameter("height")).intValue(); // allocate space for double buffer db = createImage(width, height); dbGraphics = db.getGraphics(); } private void displayImage(Graphics g) { for (int i=0; i