import java.applet.*;
import java.awt.*;

public class demo extends Applet implements Runnable {
    
    MediaTracker mt;
    Dimension   d;
    Thread      kicker = null;
    Graphics    grf;
    Image       offs;

	int i;
        
        String imagedir = null;
        String imageprefix = null;
        String backimage = null;
        String      s;

// neue variablen

	Image	pdscreen;
	Image	back01;
	Image	back02;
	Image	back03;
	Image	back04;
	Image	comment1;
	Image	comment2;
	Image	comment3;
	Image	comment4;
	Image	comment5;
	Image	comment6;
	Image	present;
	Image	startlogo;
	Image	theend;

	int	timer;

	Image	torusimage[];
	int	torusmaxgif	= 30;
	int	torusanimspeed = 1;
	int	toruscount = 0;
 
	Image	compimage[];
	int	compmaxgif	= 30;
	int	companimspeed = 2;
	int	compcount = 0;

	Image	displaceimage[];
	int	displacemaxgif	= 30;
	int	displaceanimspeed = 2;
	int	displacecount = 0;

	Image	demoimage[];
	int	demomaxgif	= 30;
	int	demoanimspeed = 2;
	int	democount = 0;

	Image	sandimage[];
	int	sandmaxgif	= 80;
	int	sandanimspeed = 2;
	int	sandcount = 0;


//---------------------------------------------------------------------

    public void init() {


	d = size();	
	imagedir="gfx/";
//screen initialisieren

        offs = createImage(d.width, d.height);
        grf = offs.getGraphics();
        mt = new MediaTracker(this);

	pdscreen = getImage(getCodeBase(),imagedir + "pdtext.jpg");
        mt.addImage(pdscreen, 0);
	back01 = getImage(getCodeBase(),imagedir + "Back01.jpg");
        mt.addImage(back01, 0);
	back02 = getImage(getCodeBase(),imagedir + "Back02.jpg");
        mt.addImage(back02, 0);
	back03 = getImage(getCodeBase(),imagedir + "Back03.jpg");
        mt.addImage(back03, 0);
	back04 = getImage(getCodeBase(),imagedir + "Back04.jpg");
        mt.addImage(back04, 0);
	        
	comment1 = getImage(getCodeBase(),imagedir + "Comment1.jpg");
        mt.addImage(comment1, 0);
	comment2 = getImage(getCodeBase(),imagedir + "Comment2.jpg");
        mt.addImage(comment2, 0);
	comment3 = getImage(getCodeBase(),imagedir + "Comment3.jpg");
        mt.addImage(comment3, 0);
	comment4 = getImage(getCodeBase(),imagedir + "Comment4.jpg");
        mt.addImage(comment4, 0);
	comment5 = getImage(getCodeBase(),imagedir + "Comment5.jpg");
        mt.addImage(comment5, 0);
	comment6 = getImage(getCodeBase(),imagedir + "Comment6.jpg");
        mt.addImage(comment6, 0);	

	present = getImage(getCodeBase(),imagedir + "Present.jpg");
        mt.addImage(present, 0);
	startlogo = getImage(getCodeBase(),imagedir + "Startlogo.jpg");
        mt.addImage(startlogo, 0);
	theend = getImage(getCodeBase(),imagedir + "Theend.jpg");
        mt.addImage(theend, 0);


	imageprefix="TF";
        torusimage = new Image[torusmaxgif];
        for (i = 0; i < torusmaxgif; i++) {
            torusimage[i] = getImage(getCodeBase(),imagedir + imageprefix + (i+1) + ".jpg");
            mt.addImage(torusimage[i], 0);
        }
	
	imageprefix="Comp";
        compimage = new Image[compmaxgif];
        for (i = 0; i < compmaxgif; i++) {
            compimage[i] = getImage(getCodeBase(),imagedir + imageprefix + (i+1) + ".jpg");
            mt.addImage(compimage[i], 0);
        }
	
	imageprefix="place";
        displaceimage = new Image[displacemaxgif];
        for (i = 0; i < displacemaxgif; i++) {
            displaceimage[i] = getImage(getCodeBase(),imagedir + imageprefix + (i+1) + ".jpg");
            mt.addImage(displaceimage[i], 0);
        }

	imageprefix="demo";
        demoimage = new Image[demomaxgif];
        for (i = 0; i < demomaxgif; i++) {
            demoimage[i] = getImage(getCodeBase(),imagedir + imageprefix + (i+1) + ".jpg");
            mt.addImage(displaceimage[i], 0);
        }

	imageprefix="Sand";
        sandimage = new Image[sandmaxgif];
        for (i = 0; i < sandmaxgif; i++) {
            sandimage[i] = getImage(getCodeBase(),imagedir + imageprefix + (i+1) + ".jpg");
            mt.addImage(sandimage[i], 0);
        }


}
    
//------------------------------------------------------------------------

    public void run() {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY-3);
        try {
            mt.waitForID(0);
        } catch(InterruptedException e) {
            System.out.println("Wait Error");
            return;
        }
        
        while (kicker != null) {
            repaint();
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {}
        }
        kicker = null;
    }

//------------------------------------------------------------------------

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

//------------------------------------------------------------------------

public void paint(Graphics g) {
	
        if (mt.isErrorID(0)) {
            g.drawString("Image Load Error....", 10, 30);
            return;
        }

        if (! mt.checkID(0)) {
        grf.drawImage(pdscreen, 0, 0, this);        
	g.drawImage(offs, 0, 0, this);
        return;
        }

//draw objects

	timer=timer+1;
//-----------------------------------------------------

	if (timer==2101)
	{
	grf.drawImage(theend, 0, 0, this);        	
	}

	if (timer==1801)
	{
	grf.drawImage(back02, 0, 0, this);        	
	}

	if ((timer<=2100) & (timer>=1800))
	{
	grf.drawImage(sandimage[sandcount++ / sandanimspeed], 273, 37, this);
       	if (sandcount / sandanimspeed == sandmaxgif ) {
            sandcount = 0;
        }
	}

	if (timer==1701)
	{
	grf.drawImage(comment5, 0, 0, this);        	
	}

//-----------------------------------------------------
	if (timer==1401)
	{
	grf.drawImage(back01, 0, 0, this);        	
	}

	if ((timer<=1700) & (timer>=1400))
	{
	grf.drawImage(demoimage[democount++ / demoanimspeed], 45, 178, this);
       	if (democount / demoanimspeed == demomaxgif ) {
            democount = 0;
        }
	}

	if (timer==1301)
	{
	grf.drawImage(comment4, 0, 0, this);        	
	}

	if (timer==1001)
	{
	grf.drawImage(back03, 0, 0, this);        	
	}

	if ((timer<=1300) & (timer>=1000))
	{
	grf.drawImage(displaceimage[displacecount++ / displaceanimspeed], 46, 37, this);
       	if (displacecount / displaceanimspeed == displacemaxgif ) {
            displacecount = 0;
        }
	}

	if (timer==901)
	{
	grf.drawImage(comment3, 0, 0, this);        	
	}

	if (timer==601)
	{
	grf.drawImage(back02, 0, 0, this);        	
	}

	if ((timer<=900) & (timer>=600))
	{
	grf.drawImage(compimage[compcount++ / companimspeed], 273, 37, this);
       	if (compcount / companimspeed == compmaxgif ) {
            compcount = 0;
        }
	}

	if (timer==501)
	{
	grf.drawImage(comment2, 0, 0, this);        	
	}

	if (timer<=251)
	{
	grf.drawImage(back01, 0, 0, this);        	
	}

	if ((timer<=500) & (timer>=250)){
	grf.drawImage(torusimage[toruscount++ / torusanimspeed], 45, 178, this);
       	if (toruscount / torusanimspeed == torusmaxgif ) {
            toruscount = 0;
        }
	}

	if ((timer<=250) & (timer>=200))
	{
	grf.drawImage(comment1, 0, 0, this);        	
	}

	if ((timer<=200) & (timer>=100))
	{
	grf.drawImage(startlogo, 0, 0, this);        	
	}

	if ((timer<=100) & (timer>=50))
	{
	grf.drawImage(present, 0, 0, this);        	
	}

	if ((timer<=50) & (timer>=0))
	{
	grf.drawImage(comment6, 0, 0, this);        	
	}

//--------------------------------------------------------------------------------------
	g.drawImage(offs, 0, 0, this);
    }

//--------------------------------------------------------------------------------------
    public void start() {
        if (kicker == null) {
            kicker = new Thread(this);
            kicker.start();
        }
    }
    
    public void stop() {
        if (kicker != null) {
            kicker.stop();
            kicker = null;
        }
    }
}




