import java.awt.*;
import java.util.*;
import java.applet.*;
import java.net.*;
public class SampleThread extends Applet implements Runnable
{
Thread t;
//int i;
//DOUBLE-BUFFER
Image dbImage;
Graphics dbg;
//SPIELELEMENTE
ball PongBall;
player MyPlayer;
enemy YourEnemy;
//SOUND
sound Game_sound;
//Zeichensatz
//noch keiner
public void init()
{
PongBall = new ball (200,200);
MyPlayer = new player (100, PongBall);
YourEnemy = new enemy();
Game_sound = new sound ();
Game_sound.bounce_wall = getAudioClip(getCodeBase(), "wall_bounce2.au");
Game_sound.bounce_player_paddle = getAudioClip(getCodeBase(), "player_bounce.au");
Game_sound.uppon_bottom_bounce = getAudioClip(getCodeBase(), "uppon_bottom_bounce.au");
//i = 0;
}
public void start()
{
t = new Thread(this);
t.start();
}
public void stop()
{
t.stop();
}
public void run()
{
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while(true)
{
//i++;
if(PongBall.ball_speed_x < 0)
{
//PongBall.checkCollision(MyPlayer, Game_sound);
MyPlayer.checkCollision(PongBall, Game_sound);
}
if((PongBall.ball_speed_x > 0) && (PongBall.ball_x > YourEnemy.enemy_reaction))
{
YourEnemy.move(Game_sound, PongBall);
}
MyPlayer.checkCollisionUP(PongBall, Game_sound);
MyPlayer.checkCollisionDOWN(PongBall, Game_sound);
YourEnemy.checkCollisionUP(PongBall, Game_sound);
YourEnemy.checkCollisionDOWN(PongBall, Game_sound);
PongBall.isBallOut(Game_sound, YourEnemy, MyPlayer);
PongBall.move();
repaint();
try
{
Thread.sleep(0);
}
catch (InterruptedException e)
{
break;
}
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
public void destroy()
{
}
public void update (Graphics g)
{
// init of Double Buffer
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
// delete image in the background
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
// draw foreground on deleted background
dbg.setColor (getForeground());
paint (dbg);
// displays complete image on screen
g.drawImage (dbImage, 0, 0, this);
}
public void paint(Graphics g)
{
g.drawString("SCORE = " + MyPlayer.player_points, 10, 415);
g.drawString("COMPUTER SCORE = " + YourEnemy.enemy_score, 340, 415);
//g.drawImage(PCpaddle, x, y, this);
//g.drawImage(ball, ball_x, ball_y, this);
PongBall.paint(g);
MyPlayer.paint(g);
YourEnemy.paint(g);
g.setColor(Color.black);
g.drawRect(10, 10, 475, 385); //draws the game-area tollerating the width/height of the ball!
}
public boolean keyDown(Event e, int key)
{
if(key == 1005)
{
MyPlayer.moveDOWN();
}
if(key == 1004)
{
MyPlayer.moveUP();
}
return true;
}
}