All pastes #268481 Raw Edit

Anonymous

public java v1 · immutable
·published 2006-12-05 19:42 UTC
rendered paste body
import element.*;import java.awt.Color;public class Assignment {    // on click the mouse will fire a laser but MISS    // the laser will fire 3 times and kill 3 invaders    static int x = 50;	static int y = 75;	final static int radius = 15;    static DrawingWindow d = new DrawingWindow(500,500);    static int q = 1000;	static boolean z = true;    //static int k = 0;		static class TimerThread extends Thread {		boolean running = true;				public void run( ) {			while ( this.running ) {				// Update timer			}		}				public void updateRunning( boolean newRunning ) {			this.running = newRunning;		}	}		static class MothershipThread extends Thread {		boolean running = true;				public void run( ) {			while ( this.running ) {				// Do something with the mothership			}		}				public void updateRunning( boolean newRunning ) {			this.running = newRunning;		}	}    	public static void StatusText() {				Text statush = new Text("HEALTH:", 25,25);		d.setForeground(Color.WHITE);		d.fill(statush);			/*		Text status = new Text("SURVIVAL TIME: " + k, 250,25);		              		d.setForeground(Color.WHITE);		d.fill(status);		tpause();		k = k + 1;		   				d.setForeground(Color.BLACK);		d.fill(status);		*/	}		public static void FooterText() {	    Text footy = new Text("You are watching an animation attempting to replicate the game", 30, 485);	    Text footy2 = new Text("Space Invaders, please enjoy", 30, 499);	    d.setForeground(Color.WHITE);		d.fill(footy);	    d.fill(footy2);	}		// Health Bars	public static void HealthBars() {		Rect bar1 = new Rect (80, 15, 5, 15);		Rect bar2 = new Rect (95, 15, 5, 15);		Rect bar3 = new Rect (110, 15, 5, 15);		d.setForeground(Color.WHITE);		d.fill(bar1);		d.fill(bar2);		d.fill(bar3);	}		public static void FooterBar() {	    Rect bar4 = new Rect (25, 475, 450, 50);	    d.setForeground(Color.DARK_GRAY);	    d.fill(bar4);	}		// Border Start	public static void Border() {		d.setForeground(Color.WHITE);		Line lone = new Line(25,500,25,50);		Line ltwo = new Line(25,50,475,50);		Line lthree = new Line(475,50,475,500);		d.fill(lone);		d.fill(ltwo);		d.fill(lthree);	// Border End	}		// Invader Drawing	public static void Circles (DrawingWindow d, int x, int y) {		Circle invader = new Circle(x, y, radius);	        Circle invader2 = new Circle(x += 50, y, radius);	        Circle invader3 = new Circle(x += 50, y, radius);	        Circle invader4 = new Circle(x += 50, y, radius);	        Circle invader5 = new Circle(x += 50, y, radius);	        Circle invader6 = new Circle(x += 50, y, radius);	        Circle invader7 = new Circle(x += 50, y, radius);	        	        d.setForeground(Color.GREEN);			d.fill(invader);	        d.fill(invader2);	        d.fill(invader3);	        d.fill(invader4);	        d.fill(invader5);	        d.fill(invader6);	        d.fill(invader7);	// End invader Drawing       	}		// Invader Clearing	public static void ClearCircles (DrawingWindow d, int x, int y) {		Circle invader = new Circle(x, y, radius);	    Circle invader2 = new Circle(x += 50, y, radius);	    Circle invader3 = new Circle(x += 50, y, radius);	    Circle invader4 = new Circle(x += 50, y, radius);        Circle invader5 = new Circle(x += 50, y, radius);        Circle invader6 = new Circle(x += 50, y, radius);        Circle invader7 = new Circle(x += 50, y, radius);	        	    d.setForeground(Color.BLACK);		d.fill(invader);        d.fill(invader2);        d.fill(invader3);        d.fill(invader4);        d.fill(invader5);        d.fill(invader6);        d.fill(invader7);	// End Invader Clearing	}		// Invader Movement Start	public static void MoveRight() {		for (int loopcounter = 1; loopcounter <= 10; loopcounter++) {            pause();            ClearCircles (d, x , y);            Circles (d, x += 10, y);	    }	}		public static void MoveLeft() {        for (int loopcounter = 1; loopcounter <= 10; loopcounter++) {			pause();			ClearCircles (d, x , y);			Circles (d, x -= 10, y);        }	}		public static void MoveDown() {         pause();         ClearCircles (d, x, y);         Circles (d, x, y += 20);         q = q - 50;      	}	// Invader Movement End		public static void main(String args[]) {        MothershipThread mothershipThread = new Assignment.MothershipThread( );        TimerThread timerThread = new Assignment.TimerThread( );			    d.setForeground(Color.BLACK);		d.fill(new Rect(0,0,500,500));        FooterBar();        Border();        StatusText();        HealthBars();        FooterText();                mothershipThread.start( );        timerThread.start( );                for (int loopcounter = 1; loopcounter <= 10; loopcounter++) {	        MoveRight();	        MoveDown();	        MoveLeft();	        MoveDown();        }                z = false;        mothershipThread.updateRunning( false );        timerThread.updateRunning( false );        //Circles (d, x, y);        //int loopcounter;		        		//Circles(d, x, y);		//Circles (d, x + 30, y);		//Circles (d, x + 60, y);	}		public static void pause() {	    long then = System.currentTimeMillis()+q;	    while (System.currentTimeMillis()<=then){}	}		public static void tpause() {	    long then = System.currentTimeMillis()+1000;	    while (System.currentTimeMillis()<=then){}	}}