...
I am haviing difficulty seeing it at your URL,
probably because you did not supply one.
Also, your code is not very clear, probably
because you did not supply it either (though
linking to it from your URL would be best).
Here is my code:
game.java:
package gg;
import java.awt.*;
import java.lang.*;
import gg.Ball;
import gg.Gorilla;
public class game extends java.applet.Applet
{
double angle=0.0;
int power=0;
int stage=0;
int turn=0;
Gorilla gorilla1,gorilla2;
public boolean mouseDown(Event evt, int x, int y)
{
if ((x>=500) && (x<=550) && (y>=25) && (y<=50))
if (stage==-9) start();
else stop();
if ((x>=275) && (x<=325) && (y>=190) && (y<=217))
{
stage=1;
repaint();
}
return true;
}
public boolean keyDown(Event evt, int key)
{
if (key==Event.UP)
power+=5;
if (key==Event.DOWN)
power-=5;
if (key==Event.LEFT)
angle-=.1;
if (key==Event.RIGHT)
angle+=.1;
if(angle>90) angle=90;
if(angle<-45) angle=-45;
if(power<0) power=0;
stage=2;
repaint();
return true;
}
public void init()
{
gorilla1 = new Gorilla();
gorilla2 = new Gorilla();
gorilla1.config(40,285,20,30,0);
gorilla2.config(560,285,20,30,1);
}
public void start()
{
stage=0;
repaint();
}
public void stop()
{
stage=-9;
repaint();
}
public Image drawTerrain()
{
Image offscreenImage;
Graphics offscg;
offscreenImage = createImage(size().width, size().height);
offscg=offscreenImage.getGraphics();
offscg.setColor(Color.red);
//int x1s[]={0,200,300,350,446,500,600,600,0,0};
//int y1s[]={300,300,150,300,250,300,300,400,400,300};
Image img = getImage(getDocumentBase(), "terrain.gif");
offscg.drawImage(img,0,0,this);
return offscreenImage;
}
public Image drawGorillas()
{
Image offscreenIm;
offscreenIm= drawTerrain();
Graphics offscg=offscreenIm.getGraphics();
offscg.setColor(Color.blue);
offscg.fillRect(30,270,20,30);
offscg.fillRect(600-(30+20),270,20,30);
return offscreenIm;
}
public void paint(Graphics g)
{
if (stage==2)
{
Image back;
Font f = new Font("TimesRoman",Font.BOLD, 16);
FontMetrics fmetrics = getFontMetrics(f);
int fontheight=fmetrics.getHeight();
back=drawGorillas();
g.drawImage(back,0,0,this);
g.setColor(Color.black);
g.setFont(f);
//Draw Angle and Power Info
g.drawString("Angle: " + angle, 30,350);
g.drawString("Power: " + power, 30, 350+fontheight);
if (turn == 0)
{
int x1,y1,x2,y2;
Double dx1 = new Double(40); //replace with gorilla1.xC
Double dy1 = new Double(285); //replace with gorilla.yC
Double dx2,dy2;
dx2 = new Double(dx1.doubleValue() + 40.0 * ( Math.cos( Math.toRadians(angle))));
dy2 = new Double(dy1.doubleValue() - 40.0 * Math.sin( Math.toRadians(angle)));
x2=dx2.intValue();
y2=dy2.intValue();
x1=dx1.intValue();
y1=dy1.intValue();
g.setColor(Color.yellow);
g.drawLine(x1,y1,x2,y2);
}
if (turn==1)
{
int x1,y1,x2,y2;
Double dx1 = new Double(560); //replace with gorilla1.xC
Double dy1 = new Double(285); //replace with gorilla.yC
Double dx2,dy2;
dx2 = new Double(dx1.doubleValue() + 40.0 * ( Math.cos( Math.toRadians(180-angle))));
dy2 = new Double(dy1.doubleValue() - 40.0 * Math.sin( Math.toRadians(180-angle)));
x2=dx2.intValue();
y2=dy2.intValue();
x1=dx1.intValue();
y1=dy1.intValue();
g.setColor(Color.yellow);
g.drawLine(x1,y1,x2,y2);
}
g.setColor(Color.black);
//Draw Quit Box
g.drawRoundRect(500,25,50,25,10,20);
String quit="Quit";
int xstart = 500+(50 - fmetrics.stringWidth(quit)) / 2;
int ystart = 20+(25 + fmetrics.getHeight()) / 2;
g.drawString(quit,xstart,ystart);
}
if (stage==0)
{
g.setColor(Color.black);
g.fillRect(0,0,600,400);
Font f = new Font("timesRoman",Font.BOLD,16);
FontMetrics fmetrics = getFontMetrics(f);
g.setFont(f);
g.setColor(Color.red);
g.drawRoundRect(275,190,50,26,10,20);
String start="Start";
int xstart = 275+(50 - fmetrics.stringWidth(start)) / 2;
int ystart = 188+(20 + fmetrics.getHeight()) / 2;
g.drawString(start,xstart,ystart);
}
if (stage==01)
{
Image back;
Font f = new Font("TimesRoman",Font.BOLD, 16);
FontMetrics fmetrics = getFontMetrics(f);
int fontheight=fmetrics.getHeight();
back=drawGorillas();
g.drawImage(back,0,0,this);
g.setColor(Color.black);
g.setFont(f);
g.drawString("Angle: " + angle, 30,350);
g.drawString("Power: " + power, 30, 350+fontheight);
g.setColor(Color.red);
g.drawRoundRect(500,25,50,25,10,20);
String quit="Quit";
int xstart = 500+(50 - fmetrics.stringWidth(quit)) / 2;
int ystart = 20+(25 + fmetrics.getHeight()) / 2;
g.drawString(quit,xstart,ystart);
}
if (stage==-9)
{
int xstart,ystart;
Font f = new Font("TimesRoman", Font.BOLD, 16);
g.setFont(f);
FontMetrics fmetrics = getFontMetrics(f);
String thanks = "Thank You For Playing";
xstart=(600-fmetrics.stringWidth(thanks))/2;
ystart=(400-fmetrics.getHeight())/2;
g.setColor(Color.black);
g.fillRect(0,0,600,400);
g.setColor(Color.red);
g.drawString(thanks,xstart,ystart);
}
}
public void update(Graphics g)
{
paint(g);
}
}
------
Ball.java
------
package gg;
public class Ball
{
//fill in later
}
------
Gorilla.java
------
package gg;
public class Gorilla
{
int x1,y1,x2,y2,player,xC,yC;
Ball myball;
int score=0;
public void config(int mxc,int myc,int wid,int hei,int pla)
{
xC=mxc;
yC=myc;
player=pla;
x1=xC-wid/2;
x2=xC+wid/2;
y1=yC-hei/2;
y2=yC+hei/2;
myball = new Ball();
}
}
------
m.htm
------
<html>
<head>
<body>
<p>
<applet width="600" height="400" code="c:\javaproj\gg\game.class">
</applet></p>
</body>
</html>