All pastes #270163 Raw Edit

Someone

public text v1 · immutable
·published 2006-12-07 03:52 UTC
rendered paste body
import element.*;
import java.awt.Color;
public class Assignment {
    static int x = 50;
    static int y = 75;
    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 int lx = 75;
    
    
	static class LaserFire extends Thread {
        
		boolean running = true;
		
		public void run( ) {
			while ( this.running ) {                             
                            
                           
             MoveLaserRight();
                            MoveLaserLeft();

			}
		}
		
		public void updateRunning( boolean newRunning ) {
			this.running = newRunning;
		}
	}
	
	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);   
                                                  

		d.setForeground(Color.RED);

        }
        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 Laser1(DrawingWindow d, int lx){
                     
                Line Laser = new Line (lx , 399, lx , 350);
                Line Laser2 = new Line (lx ,300, lx , 250); 
                Line Laser3 = new Line (lx  ,200, lx , 150);; 

		d.setForeground(Color.RED);
	
                d.fill (Laser);
                d.fill (Laser2);
                  d.fill(Laser3);
        }
        
                public static void ClearLaser1(DrawingWindow d, int lx){
                        
               Line Laser = new Line (lx, 399, lx, 350);
                Line Laser2 = new Line (lx ,300, lx, 250); 
                Line Laser3 = new Line (lx ,200, lx , 150);; 

		d.setForeground(Color.BLACK);
	
                d.fill (Laser);
                d.fill (Laser2);
                  d.fill(Laser3);
        }
                        public static void Laser2(DrawingWindow d, int lx){
                        
                Line Laser = new Line (lx, 350, lx, 300);
                Line Laser2 = new Line (lx,250, lx, 200); 
                Line Laser3 = new Line (lx ,150, lx, 100);

		d.setForeground(Color.RED);
	
                d.fill (Laser);
                d.fill (Laser2);
                  d.fill(Laser3);
        }
        
                public static void ClearLaser2(DrawingWindow d, int lx){
                        
                Line Laser = new Line (lx, 350, lx, 300);
                Line Laser2 = new Line (lx ,250, lx, 200); 
                Line Laser3 = new Line (lx,150, lx, 100);


		d.setForeground(Color.BLACK);
	
                d.fill (Laser);
                d.fill (Laser2);
                  d.fill(Laser3);
        }
                	public static void MoveLaserLeft() {
        for (int loopcounter = 1; loopcounter <= 18; loopcounter++) {
	                   lpause();
            ClearLaser2(d, lx);
                               Laser1(d, lx -= 10);
                           
                                 lpause();
                               ClearLaser1(d, lx);
                               Laser2(d, lx -= 10);
                              
        }        
                        }
                                	public static void MoveLaserRight() {
        for (int loopcounter = 1; loopcounter <= 18; loopcounter++) {
	                //     ClearLaser2();
                           lpause();
            ClearLaser2(d, lx);
                               Laser1(d, lx += 10);
                           
                                 lpause();
                               ClearLaser1(d, lx);
                               Laser2(d, lx += 10);
                                
                             
                           // Laser2();
                          // mpause();
        }  

        
	}
        	public static void MoveMotherLeft() {
        for (int loopcounter = 1; loopcounter <= 36; loopcounter++) {
			mpause();
			clearmothership (d, rx);
			mothership (d, rx -= 10);
        }
	}
        	public static void MoveMotherRight() {
        for (int loopcounter = 1; loopcounter <= 36; loopcounter++) {
			mpause();
			clearmothership (d, rx);
			mothership (d, rx += 10);
        }  

        
	}
                
        public static void Laser(){
     //                            Line Laser = new Line (25,400, 0, 100); 
	//	d.setForeground(Color.RED);
	//	d.fill(Laser);   
        }
        

	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( );
		        LaserFire laserFire = new Assignment.LaserFire( );
		
	    d.setForeground(Color.BLACK);
		d.fill(new Rect(0,0,500,500));
        FooterBar();
        Border();
        StatusText();
        HealthBars();
        FooterText();
        DefenseBlocks();

        
        mothershipThread.start( );
        timerThread.start( );
           laserFire.start( );
        
        for (int loopcounter = 1; loopcounter <= 9; loopcounter++) {
	        MoveRight();
	        MoveDown();
	        MoveLeft();
	        MoveDown();

        }
               GameOver();
ClearLaser1(d, lx);
ClearLaser2(d, lx);
        mothershipThread.updateRunning( false );
        timerThread.updateRunning( false );
               laserFire.updateRunning( false );

	}
	
	public static void pause() {
	    long then = System.currentTimeMillis()+q;
	    while (System.currentTimeMillis()<=then){}
	}
		public static void mpause() {
	    long then = System.currentTimeMillis()+100;
	    while (System.currentTimeMillis()<=then){}
	}
			public static void lpause() {
	    long then = System.currentTimeMillis()+100;
	    while (System.currentTimeMillis()<=then){}
	}
	public static void tpause() {
	    long then = System.currentTimeMillis()+1000;
	    while (System.currentTimeMillis()<=then){}
	}

}