All pastes #268781 Raw Edit

Something

public text v1 · immutable
·published 2006-12-06 00:38 UTC
rendered paste body
import element.*;
import java.awt.Color;
public class Assignment {
    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 int rx = 50;
	
	static class TimerThread extends Thread {
        
		boolean running = true;
		
		public void run( ) {
			while ( this.running ) {                             
                            Text status = new Text("" + k, 350,25);
		    
                            d.setForeground(Color.WHITE);
                            d.fill(status);
		
                            k = k + 1;
                            tpause();	
                            d.setForeground(Color.BLACK);
                            d.fill(status);
			}
		}
		
		public void updateRunning( boolean newRunning ) {
			this.running = newRunning;
		}
	}
	
	static class MothershipThread extends Thread {
		boolean running = true;
		
		public void run( ) {
			while ( this.running ) {
                             MoveMotherRight();
                            MoveMotherLeft();
                           
				
			}
		}
		
		public void updateRunning( boolean newRunning ) {
			this.running = newRunning;
		}
	}
    
	public static void StatusText() {	
                Text status = new Text("SURVIVAL TIME: ", 250,25);
		Text statush = new Text("HEALTH:", 25,25);
		d.setForeground(Color.WHITE);
		d.fill(statush);
                d.fill(status);
        }
	
        public static void mothership(DrawingWindow d, int rx){
                        Rect mothership = new Rect (rx , 450, 50, 10);
		d.setForeground(Color.GREEN);
		d.fill(mothership);   
        }
        public static void clearmothership(DrawingWindow d, int rx)
        {
                        Rect mothership = new Rect (rx , 450, 50, 10);
		d.setForeground(Color.BLACK);
		d.fill(mothership);  
        }
        	public static void MoveMotherLeft() {
        for (int loopcounter = 1; loopcounter <= 180; loopcounter++) {
			mpause();
			clearmothership (d, rx);
			mothership (d, rx -= 2);
        }
	}
        	public static void MoveMotherRight() {
        for (int loopcounter = 1; loopcounter <= 180; loopcounter++) {
			mpause();
			clearmothership (d, rx);
			mothership (d, rx += 2);
        }
	}
	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);
	}
	
        public static void GameOver(){
            Text gameo = new Text("Game Over", 220, 250);

            d.setForeground(Color.RED);
            d.fill(gameo);
                    Text gamoe = new Text("You survived for " + k + " seconds", 160, 260);
                    d.setForeground(Color.WHITE);
                    d.fill(gamoe);
        }
        
	// 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.GREEN);
		d.fill(bar1);
		d.fill(bar2);
		d.fill(bar3);
	}
        
	public static void DefenseBlocks() {
		Rect bar11 = new Rect (75, 400, 50, 30);
		Rect bar22 = new Rect (175, 400, 50, 30);
		Rect bar33 = new Rect (275, 400, 50, 30);
                Rect bar44 = new Rect (375, 400, 50, 30);
		d.setForeground(Color.GREEN);
		d.fill(bar11);
		d.fill(bar22);
		d.fill(bar33);
                d.fill(bar44);
	}
	
	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.WHITE);
			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();
        DefenseBlocks();
 
        
        mothershipThread.start( );
        timerThread.start( );
        
        for (int loopcounter = 1; loopcounter <= 9; loopcounter++) {
	        MoveRight();
	        MoveDown();
	        MoveLeft();
	        MoveDown();
                
        }
               GameOver();
        //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 mpause() {
	    long then = System.currentTimeMillis()+1;
	    while (System.currentTimeMillis()<=then){}
	}
	
	public static void tpause() {
	    long then = System.currentTimeMillis()+1000;
	    while (System.currentTimeMillis()<=then){}
	}
}