// Java Rocket by Exner Enterprises C. 1999 import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.URL; import java.util.*; import java.applet.AudioClip; public class Rocket extends Applet implements Runnable { Image offscreenImage; Graphics h; int appSizeX, appSizeY; Vector objVect; boolean threadRun=true; Thread runner; AudioClip launch; public void init(){ appSizeX=this.size().width; appSizeY=this.size().height; launch = getAudioClip(getCodeBase(),"launch.au"); offscreenImage = createImage(appSizeX, appSizeY); h = offscreenImage.getGraphics(); Back.loadImages(this); objVect = new Vector(); objVect.addElement(new Back()); repaint(); } public void paint(Graphics g) { Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.show(h); } g.drawImage(offscreenImage,0,0,this); } public boolean mouseDown(Event evt, int x, int y) { if (ShowableObject.launch) launch.stop(); else launch.loop(); System.out.println("x: "+(x)+"y: "+(y)); // Debug position Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.setMousePoint(x,y); } repaint(); return true; } public boolean mouseUp(Event evt, int x, int y) { //b.contactUp(); return true; } public boolean mouseDrag(Event evt, int x, int y) { //b.objectDrag(x,y); return true; } public void update(Graphics g) { paint(g); } /// Start Thread stuff public void start() { if (runner == null) { runner= new Thread(this); runner.start(); threadRun = true; } } public synchronized void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { while (true) { //execute try { Thread.sleep(50); repaint(); } catch (InterruptedException e) {} } // End While } // End Run } // End class Rocket /////////////////// Back Class /////////////////////////////// class Back extends ShowableObject { static Image imageStrip; int rocketX=252, rocketY=139; int height=300, width=300; public Back() { //Constructor } public static void loadImages(Applet parent){ imageStrip = parent.getImage(parent.getCodeBase(),"data.gif"); } public void show(Graphics g) { // Draw Sky // drawStripImage(g, imageStrip,0, 0,10,height); for (int i=0; i -300) rocketY-=3; } public void drawStripImage(Graphics g, Image imagePtr, int drawX, int drawY,int imageWidth, int imageHeight,int newX, int newY) { Graphics subArea = g.create(newX, newY, imageWidth, imageHeight); subArea.drawImage(imagePtr,-drawX,-drawY, this); subArea.dispose(); } public void drawStripImage(Graphics g, Image imagePtr, int drawX, int drawY,int imageWidth, int imageHeight) { Graphics subArea = g.create(drawX, drawY, imageWidth, imageHeight); subArea.drawImage(imagePtr,-drawX,-drawY, this); subArea.dispose(); } } // End Class Back /////////////////// ShowableObject Class //////////////////////////// class ShowableObject extends Applet { static boolean launch=false; public void show (Graphics g) { return; } public void keyPress(Event evt, int key) { return; } public void setMousePoint(int x ,int y) { if (x > 14 && x < 114) if (y > 35 && y < 75) launch = true; return; } }