You might have to wait a few seconds for the sound to load. Also i took out the image because it caused extreme flickering.

WARNING: If you play the game for longer than 5 min, it will pop out of the browser and take over your computer, dont ask me why...

CODE

/*
kevin zhang
infotech 11
jan. 2004
block D
pong assignment

*/

import java.applet.*;
import java.awt.*;
public class moviecircle extends Applet implements Runnable
{
int player;
int ax=250, ay=100;
int ar=10;
int adx=0, ady=0;
int delay=20;
int speed=0;
int cx=0, cy=10, cdy;
Image pongpic;
int asdf=1;
int acceleration=0;
int timerstart;
int cc=8, cv=100;
int x=492, y=10;
int c=8, v=100;
int dx,dy;
int compspeed;
int time = 0;
int timebar=400;
int scoreme=0, scorecomp=0;
AudioClip paddle;
AudioClip wall;
AudioClip ex;
AudioClip au;
AudioClip speedup;
AudioClip loser;
AudioClip step;
int pass=0;

//hi = getAudioClip(getCodeBase(), "hi.wav");
//paddle.play();
String instructions2=" ";
String pick="Please pick how many players are playing";
String pick1="press q for one player ";
String pick2="Press w for two players ";
String instructions3=" ";
String win;
String a=" ";
String end=" ";
String b=" ";
String sc=" ";
String d=" ";
String se=" ";
String player1="";
String player2="";

/*String a="Please select the computer's skill level";
String b="Press 1 for DUMB";
String sc="Press 2 for AVERAGE";
String d="Press 3 for MASTER";
String se="Press 4 for GOD-LIKE";*/
String ins="Press i for Instructions";
String instructions=" ";
String back=" ";
Thread running;
public void init()
{paddle = getAudioClip(getCodeBase(), "bong.au");
wall = getAudioClip(getCodeBase(), "ding.au");
pongpic= this.getImage(this.getCodeBase(), "pongpic.gif");
ex = getAudioClip(getCodeBase(), "glass.wav");
au = getAudioClip(getCodeBase(), "applause.au");
speedup = getAudioClip(getCodeBase(), "speedup.au");
loser = getAudioClip(getCodeBase(), "suck.wav");
step = getAudioClip(getCodeBase(), "harp2.au");
}
public void paint (Graphics g)
{ g.drawImage(pongpic,184,137,this);
g.setColor(Color.yellow);
g.drawString(pick,100,150);
g.drawString(pick1,200,160);
g.drawString(pick2,200,170);
g.drawString(end,190,140);
g.drawString("Time Left : ",20,313);
g.fillRect(80,303,timebar,10);
g.setColor(Color.red);
g.fillRect(180,303,3,10);
g.fillRect(280,303,3,10);
g.fillRect(380,303,3,10);
g.setColor(Color.yellow);
g.drawString(player1+scorecomp,30,20);
g.drawString(player2+scoreme,410,20);
g.drawString(a,150,150);
g.drawString(b,200,160);
g.drawString(sc,200,170);
g.drawString(d,200,180);
g.drawString(se,200,190);
g.drawString(ins,200,205);
g.drawString(back,150,180);
g.setColor(Color.yellow);
g.drawString(instructions,15,150);
g.drawString(instructions2,15,160);
g.drawString(instructions3,15,170);
setBackground(Color.black);
g.setColor(Color.blue);
g.fillRect(0,0,500,3);
g.fillRect(497,0,3,320);
g.fillRect(0,297,500,3);
g.fillRect(0,317,500,3);
g.fillRect(0,0,3,320);
g.setColor(Color.yellow);
g.fillRect(x,y,c,v);
g.setColor(Color.blue);
g.fillOval(ax,ay,ar,ar);
g.setColor(Color.red);
g.fillRect(cx,cy,cc,cv);
g.drawString(win,210,140);


}
public void start(){
if (running==null)
{running = new Thread(this,"running");
running.start();
}
}
public void stop(){
if (running!=null && running.isAlive()){
running.stop();
}
running=null;
}
public boolean keyDown(Event e, int key){
if (e.id==Event.KEY_PRESS && key=='q'){
if (pass==0)
{timerstart=0;end=" ";
pick=" ";
pick1=" ";
pick2=" ";
instructions3=" ";
a="Please select the computer's skill level";
b="Press 1 for DUMB";
sc="Press 2 for AVERAGE";
d="Press 3 for MASTER";
se="Press 4 for GOD-LIKE";
ins="Press i Instructions";
ax=250;
ay=100;
adx=0;
ady=0;
acceleration=0;
timebar=400;
time=0;
scoreme=0;
scorecomp=0;
player=1;
player1="Computer ";
player2="You ";
pass=1;
step.play();
}pass=2;
return true;
}
if (e.id==Event.KEY_PRESS && key=='w'){
if (pass==0)
{timerstart=1;
pick=" ";
pick1=" ";
step.play();
pick2=" ";
a=" ";end=" ";
instructions3=" ";
b=" ";
sc=" ";
d=" ";
se=" ";
ins = " ";
repaint();
player1="Player One ";
player2="Player Two ";
adx=2;
ady=2;
acceleration=0;
player=2;}pass=2;
return true;
}
if (e.id==Event.KEY_ACTION && key ==Event.UP){
if (y>=5)
{y=y-10;

repaint();
return true;
}
}
if (e.id==Event.KEY_ACTION && key==Event.DOWN){
if (y<=190)
{y=y+10;

repaint();
}


return true;
}
if (player==2)
{
if (e.id==Event.KEY_PRESS && key=='a'){
if (cy>=5)
{cy=cy-10;

repaint();
return true;
}
}
if (e.id==Event.KEY_PRESS && key=='f'){
if (adx>0)
{adx=adx+3;
}
if (adx<0)
{adx=adx-3;
}
if (ady>0)
{ady=ady+3;
}
if (ady<0)
{ady=ady-3;
}
repaint();
return true;

}
if (e.id==Event.KEY_PRESS && key=='v'){
if (adx>0)
{adx=adx-3;
}
if (adx<0)
{adx=adx+3;
}
if (ady>0)
{ady=ady-3;
}
if (ady<0)
{ady=ady+3;
}

repaint();
return true;

}
if (e.id==Event.KEY_PRESS && key=='z'){
if (cy<=190)
{cy=cy+10;

repaint();
}
return true;
}
}
if (e.id==Event.KEY_PRESS && key=='r'){
timebar=400;
scorecomp=0;
step.play();
scoreme=0;
timerstart=0;a=" ";end=" ";
instructions3=" ";
b=" ";
sc=" ";
d=" ";
se=" ";
ins = " ";
pass=0;
pick="Please pick how many players are playing";
pick1="press q for one player ";
pick2="Press w for two players ";
instructions=" ";
back=" ";
ins="Press i for Instructions";
acceleration=0;
repaint();
ax=250;
ay=100;
adx=0;
ady=0;
return true;
}
if (e.id==Event.KEY_PRESS && key=='1'){
if (pass ==2)
{timerstart=1;
instructions3=" ";
a=" ";end=" ";
step.play();
b=" ";
sc=" ";
d=" ";
se=" ";
ins = " ";
repaint();
compspeed=1;
adx=2;
ady=2;
acceleration=0;
}pass=3;
return true;
}
if (e.id==Event.KEY_PRESS && key=='2'){
if (pass ==2)
{timerstart=1;
a=" ";end=" ";
instructions3=" ";
step.play();
b=" ";
sc=" ";
d=" ";
se=" ";
ins = " ";
repaint();
compspeed=2;
adx=2;
acceleration=0;
ady=2;}pass=3;
return true;
}
if (e.id==Event.KEY_PRESS && key=='3'){
if (pass ==2)
{timerstart=1;
a=" ";end=" ";
instructions3=" ";
b=" ";
step.play();
sc=" ";
d=" ";
se=" ";
ins = " ";
repaint();
compspeed=3;
adx=2;
ady=2;
acceleration=0;}pass=3;
return true;
}
if (e.id==Event.KEY_PRESS && key=='4'){
if (pass ==2)
{timerstart=1;
instructions3=" ";
a=" ";end=" ";
b=" ";
sc=" ";
d=" ";
se=" ";
step.play();
ins = " ";
repaint();
compspeed=10;
adx=2;
ady=2;
acceleration=0;
}pass=3;
return true;
}
if (e.id==Event.KEY_PRESS && key=='i'){
timerstart=0;
pick=" ";
pick1=" ";
pick2=" ";
step.play();
a=" ";
b=" ";
sc=" ";
d=" ";
se=" ";
ins=" ";
pass =0;
instructions2="Every time the time reaches a red line the ball will accellerate. So watch out...";
instructions="You are yellow , move with UP/DOWN, and A/Z for player 2. R to restart. ";
instructions3="To give you an advantage, only YOU can angle the ball.";
back="Press B to go back";
acceleration=0;end=" ";
pass=4;
repaint();

return true;
}
if (e.id==Event.KEY_PRESS && key=='b'){
timerstart=0;
a=" ";end=" ";
b=" ";
sc=" ";
d=" ";
step.play();
se=" ";
ins="Press i for Instructions";
instructions3=" ";
pick="Please pick how many players are playing";
pick1="press q for one player ";
pick2="Press w for two players ";
instructions=" ";
instructions2=" ";
back=" ";
pass=0;
acceleration=0;
pass=0;
repaint();

return true;
}
else return false;
}
public void run() {

for (; ; )
{

if (timerstart==1)
{time=time+1;
if (time ==8)
{timebar=timebar-1;
time=0;

if (timebar==300)
{
speedup.play();
if (adx>0)
{adx=adx+1;
}if (adx<0)
{adx=adx-1;
}
}
if (timebar==200)
{
speedup.play();
if (adx>0)
{adx=adx+1;
}if (adx<0)
{adx=adx-1;
}
}
if (timebar==100)
{
speedup.play();
if (adx>0)
{adx=adx+1;
}if (adx<0)
{adx=adx-1;
}
}
}
if (timebar==0)
{adx=0;
ady=0;
ay=150;
ax=250;

}
}

if (player==1)
{

if (cy>=3)
{
if (ay<cy+20)
{cy=cy-compspeed;
}
if (ay>cy+80)
{cy=cy+compspeed;
}
}
else cy=cy+compspeed;
if (cy<=197)
{
if (ay<cy+20)
{cy=cy-compspeed;
}
if (ay>cy+80)
{cy=cy+compspeed;
}
}
else cy=cy-compspeed;
}

ax=ax+adx;
ay=ay+ady;

if (ay>=y&&ay<=y+100&&ax>=495)
{ady =-ady;
}
if (ay<=cy&&ay>=cy+100&&ax<=5)
{ady =-ady;
}

if (ax<3)
{adx=-adx;
}
if (ax>497)
{adx=-adx;
}
if (ay>287)
{ady = -ady;
wall.play();
}
if (ay<3)
{ady=-ady;
wall.play();
}

if (ax>=x-10 && ay>=y && ay<=y+10 )
{
adx = -adx;
ady=ady-2;
paddle.play();

}
if (ax>=x-10 && ay>=y+10 && ay<y+30 )
{
adx = -adx;
ady=ady-1;
paddle.play();
}
if (ax>=x-10 && ay>=y+30 && ay<y+70 )
{
adx = -adx;
paddle.play();
}
if (ax>=x-10 && ay>=y+70 && ay<y+90 )
{
adx = -adx;
ady=ady+1;
paddle.play();

}
if (ax>=x-10 && ay>=y+90 && ay<=y+100 )
{
adx = -adx;
ady=ady+2;
paddle.play();
}
if (ax<=8 && ay>=cy && ay<=cy+100 )
{adx = -adx;
paddle.play();
}
if (ax <=3)
{scoreme=scoreme+1;
ax=250;
ay=150;
adx=1;
ady=1;
acceleration=0;
ex.play();
}
if (ax >=487)
{ax=250;
scorecomp=scorecomp+1;
ay=150;
adx=1;
ady=1;
acceleration=0;
ex.play();
}
if (player==1)
{if (timebar==0)
{if (scoreme>scorecomp)
{end="Your WIN! press R to restart";
au.play();
}
if (scoreme<scorecomp)
{end="Your Lose! press R to restart";
loser.play();
}
if (scoreme==scorecomp)
{end="TIE! press R to restart";
au.play();
}
}
}
if (player==2)
{if (timebar==0)
{if (scoreme>scorecomp)
{end="Player Two wins! press R to restart";
au.play();
}
if (scoreme<scorecomp)
{end="Player One wins! press R to restart";
au.play();
}
if (scoreme==scorecomp)
{end="TIE! press R to restart";
au.play();
}
}
}
repaint();
try{running.sleep(delay);}
catch(InterruptedException e) {;}
}
}
}

Hosted by www.Geocities.ws

1 1 1