Amiga Cracktro - Starfield

Frank77

Neues Mitglied
Ich möchte ein Intro wie die damaligen Amiga-spiele es hatten programmieren.
Habe schon folgenden Code erhalten, den ich nutzen möchte, aber nicht schlau draus werde.

Wie kann ich Dimension auf Fullscreen festlegen , der vorab ausgelesen wird.
Wo setze ich neuen Code für die weiteren Vorhaben an?
Vielen Dank!
-----

Java:
import java.applet.Applet;
import java.awt.*;
import javax.swing.JFrame;

public class Starfield extends Applet implements Runnable

{
   int STARS = 200;

   int[] x, y, xv, xi;
   Color c[];

   Thread runner;

   // Double Buffer variables
   Image DB_Image;
  Graphics DB_Graphics;
   Dimension DB_Dimension;
  
   // Selbst erstellt
   public int width;
   public int height;


   public void init(){
  
     int i, t;
     String p;
     p = getParameter("stars");
     if (p == null) p = "200";
     STARS = Integer.valueOf(p).intValue();
     if (STARS == 0 || STARS > 200 || STARS < 1) STARS=200;

     x  = new int[STARS];
     y  = new int[STARS];
     xv = new int[STARS];
     xi = new int[STARS];
     c  = new Color[STARS];

     DB_Dimension = size();
     //DB_Dimension.width = 500;
     //DB_Dimension.height = 500;
  
  
  if (DB_Graphics == null) {
       //Ausmasse des Sternenfeldes
       //DB_Image = createImage(DB_Dimension.width, DB_Dimension.height);
     DB_Image = createImage(DB_Dimension.width = 500, DB_Dimension.height = 500);
       DB_Graphics = DB_Image.getGraphics();
     }

     setBackground(new Color(0,0,0));
     for(i=0;i<STARS;i++){
       x[i] = (int)(Math.random()*DB_Dimension.width);
       y[i] = (int)(Math.random()*DB_Dimension.height);
       xi[i] = x[i];
     
     
       while((t = (int)(Math.random()*30)) <0 || t>2){}
         
       switch(t){
         case 0:{
           xv[i] = 2;
    c[i] = Color.gray;
         } break;
         case 1:{
           xv[i] = 4;
    c[i] = Color.lightGray;
         } break;
         case 2:{
           xv[i] = 6;
    c[i] = Color.white;
         } break;
       } // END SWITCH
     } // END FOR INIT LOOP

   }

   public void paint(Graphics g){
     update(g);
   }
 
   public void update(Graphics g){   

     DB_Graphics.setColor(Color.black);
     DB_Graphics.fillRect(0, 0, DB_Dimension.width, DB_Dimension.height);   
   
     // Plotting
       for(int i=0;i<STARS;i++){   
 
       DB_Graphics.setColor(c[i]);
       DB_Graphics.drawLine(x[i],y[i],x[i],y[i]);   
     
       DB_Graphics.setColor(c[++i]);
       DB_Graphics.drawLine(x[i],y[i],x[i],y[i]);
       
       DB_Graphics.setColor(c[++i]);
       DB_Graphics.drawLine(x[i],y[i],x[i],y[i]);
   
       DB_Graphics.setColor(c[++i]);
       DB_Graphics.drawLine(x[i],y[i],x[i],y[i]);
   

     }
     // Position des Sternenbildes (200, 200)
     g.drawImage(DB_Image, 0, 0, this );
   }

   public void run(){
     int i, t;
     while(true){
     for (i=0; i<STARS; i++){
       if ((x[i]+=xv[i])>=DB_Dimension.width) {     // RICHTUNG + -
         x[i] = 0;
         t=4;
         while((t = (int)(Math.random()*30)) <0 || t>2){}
         switch(t){
           case 0:{
             xv[i] = 2;
             c[i] = Color.gray;
           } break;
           case 1:{
             xv[i] = 4;
             c[i] = Color.lightGray;
           } break;
           case 2:{
             xv[i] = 6;
    c[i] = Color.white;
           } break;
         } // END SWITCH
       } // END IF
     } // END FOR INDEX LOOP

    try{
       Thread.sleep(50);
     } catch(InterruptedException e) {stop();}
       repaint();
     }
   }
 
   public void start() {
     if (runner == null); {
       runner = new Thread(this);
       runner.start();
     }
   }

   public void stop() {
     if (runner != null) {
     runner.stop();
     runner = null;
     }
   }

}
 
Zuletzt bearbeitet von einem Moderator:

Neue Themen


Oben