Für diejenigen, die es interessiert, gibt es hier
den Java-Quelltext:
/*** Die Katze Im Weltraum ***/
//Anfang: etwa Mitte Oktober 1998
import java.awt.Graphics; import java.awt.Image;
import java.awt.Color; import java.applet.AudioClip;
import java.awt.Event; import java.awt.*;
public class GatoP extends java.applet.Applet implements Runnable {
int mau;
int weit, hoch; //Breite und Höhe des Applets
int up; //Kontrolle für paint()-Ausführung
int w, wach=23; //Zähler für die Wach-Bilder
int s, schlaf=16; //Zähler für Schlafen
int vx=2, vy=1; //Geschwindigkeit, x und y
int p=20; //Pause in jedem Zyklus
int ri=24, ra=50; //Radius, innen und außen
int umx=1, umy=-1; //Umschalter, = 1 oder = -1
Image gatos, gato2, gatow; //drei Katzenbilder
Image gato; //das aktuelle Bild
int x=40, y=200; //die aktuelle Position, oben, links
Image off; //Zwischen-Bild-Speicher
Graphics o; //Grafik-Objekt für das Zwischen-Bild
AudioClip bim; //der "Piep"
Thread runner;
public void start() {
if (runner==null) {runner=new Thread(this); runner.start();} }
public void stop() {
if (runner!=null) {runner.stop(); runner=null;} }
public void init() {
gatos = getImage(getDocumentBase(), "images/sleep1.gif");
gato2 = getImage(getDocumentBase(), "images/sleep2.gif");
gatow = getImage(getDocumentBase(), "images/awake.gif");
bim = getAudioClip(getDocumentBase(), "audio/ding.au");
setBackground(new Color(175,191,255)); }
public void update(Graphics g) {
g.clipRect(x-vx-3, y-vy-3, 2*(ra+vx)+6, 2*(ra+vy)+6);
paint(g); }
public void paint (Graphics g) {
g.drawImage(off, 0, 0, this);
up=0; }
// public boolean mouseDown(Event evt, int x,int y) {
// if (mau == 0) { mau=1; stop(); }
// else { mau=0; start(); }
// return true; }
public boolean keyDown(Event evt, int key) {
if (key==Event.RIGHT) vx=vx+1;
else if(key==Event.LEFT && vx>0) vx=vx-1;
else if(key==Event.UP) vy=vy+1;
else if(key==Event.DOWN && vy>0) vy=vy-1;
else if(key==Event.PGUP) ra=ra+1;
else if(key==Event.PGDN && ra>0) ra=ra-1;
return true; }
public void run() {
s=schlaf;
bim.play();
while (true) {
if (up == 0) {
up=1;
if (this.size().width != weit | this.size().height != hoch) {
off = createImage(this.size().width, this.size().height);
o = off.getGraphics();
weit=this.size().width;
hoch=this.size().height;
o.setColor(getBackground());
o.fillRect(0, 0, weit, hoch);
try {Thread.sleep(200);}
catch (InterruptedException e) {}
}
x = x+vx*umx;
y = y+vy*umy;
if (x > weit-2*ra) {
x=weit-2*ra;
umx=umx*(-1);
w=wach;
bim.play(); }
if (x < 0) {
x=0;
umx=umx*(-1);
w=wach;
bim.play(); }
if (y > hoch-2*ra) {
y=hoch-2*ra;
umy=umy*(-1);
w=wach;
bim.play(); }
if (y < 0) {
y=0;
umy=umy*(-1);
w=wach;
bim.play(); vy=vy; }
if (w > 0) { gato = gatow; s=schlaf; }
else {
if (s > 0) { gato = gatos; }
else gato = gato2;
if (s < -1*schlaf) s=schlaf;
s=s-1; }
w=w-1;
o.setColor(getBackground());
o.fillRect(x-vx-3, y-vy-3, 2*(ra+vx)+6, 2*(ra+vy)+6);
o.setColor(Color.yellow);
o.fillOval (x, y, 2*ra, 2*ra);
o.setColor(Color.white);
o.fillOval (x+ra-ri, y+ra-ri, 2*ri, 2*ri);
o.drawImage (gato, x+ra-16, y+ra-16, this);
o.setColor(Color.black);
o.drawOval (x, y, 2*ra-1, 2*ra-1);
o.drawOval (x+ra-ri, y+ra-ri, 2*ri-1, 2*ri-1);
repaint();
try {Thread.sleep(p);}
catch (InterruptedException e) {}
}
}
}
}