Hi big investors,
I’m trying to compile my code and and get the following message:
PassTheKetchup.java
// import required libraries
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.applet.Applet;
import java.awt.event.KeyEvent;
import java.util.Random;
public class PassTheKetchup extends Applet implements Runnable, KeyListener {
//global constants
static int SCREENWIDTH = 320;
static int SCREENHEIGHT = 240;
// the main thread becomes the game loop
Thread gameloop;
// double buffer
BufferedImage backbuffer;
// the main drawing object for the back buffer
Graphics2D g2d;
// identity transform
AffineTransform identity;
// random number generator
Random rand;
// background image
ImageEntity background;
// applet init event
public void init() {
// create the back buffer for smooth graphics
backbuffer = new BufferedImage(640, 480,
BufferedImage.TYPE_INT_RGB);
g2d = backbuffer.createGraphics();
// create instance of imageentity for background
//background = new ImageEntity(this);
// load the background image
//background.load("background.png");
//start the user input listener
addKeyListener(this);
}
// applet update event to redraw the screen
public void update(Graphics g) {
// start off transforms at identity
g2d.setTransform(identity);
// erase the background
g2d.setPaint(Color.BLACK);
g2d.fillRect(0, 0, getSize().width, getSize().height);
// draw the background
//g2d.drawImage(background.getImage(), 0, 0, SCREENWIDTH - 1, SCREENHEIGHT - 1,this);
// print some status information
g2d.setColor(Color.WHITE);
g2d.drawString("Score: 0", 0, 0);
// draw the game graphics
//repaint the applet window
paint(g);
}
// applet window repaint event - draw the back buffer
public void paint(Graphics g) {
// draw the back buffer onto the applet window
g.drawImage(backbuffer, 0, 0, this);
}
// thread start event - start the game loop running
public void start() {
// create the gameloop thread for real-time updates
gameloop = new Thread(this);
// start the game loop
gameloop.start();
}
// thread stop event
public void stop() {
// kill the gameloop thread
gameloop = null;
}
// main game loop
public void run() {
//acquire the current thread
Thread t = Thread.currentThread();
//keep going as long as the thread is alive
while (t == gameloop) {
try {
// update the game loop
gameUpdate();
// target framerate is 50 fps
Thread.sleep(20);
}
catch(InterruptedException e) {
// print error on stack
e.printStackTrace();
}
// repaint the screen
repaint();
}
}
// move and animate the objects in the game
private void gameUpdate() {
// update player object
updatePlayer();
// update all box entities
updateBoxes();
// check for collisions
checkCollisions();
}
// Update the players position
public void updatePlayer() {}
// Update the boxes position
public void updateBoxes() {}
// check for collisions for all entities
public void checkCollisions() {}
// key handling code
public void keyReleased(KeyEvent k) {}
public void keyTyped(KeyEvent k) {}
public void keyPressed(KeyEvent k) {}
}
ImageEntity.java
// base game image class for bitmapped game entities
// import required libraries
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.net.*;
public class ImageEntity extends BaseGameEntity {
// image
protected Image image;
// container
protected JFrame frame;
// affinetransformation
protected AffineTransform at;
// graphics context
protected Graphics2D g2d;
// default constructor
ImageEntity(JFrame a) {
// set frame container
frame = a;
// set image
setImage(null);
// set alive to true
setAlive(true);
}
// returns image
public Image getImage() { return image; }
// sets entities image
public void setImage(Image image) {
// set image
this.image = image;
// calculate x
double x = frame.getSize().width / 2;
// calculate y
double y = frame.getSize().height / 2 - height() / 2;
// calculate affine transform
at = AffineTransform.getTranslateInstance(x, y);
}
// returns image width
public int width() {
// if the image isn't null
if(image != null)
// return image width
return image.getWidth(frame);
else
// otherwise return 0
return 0;
}
// returns image height
public int height() {
// if the image isn't null
if(image != null)
// return image height
return image.getHeight(frame);
else
// otherwise return 0
return 0;
}
// returns x center
public double getCenterX() {
// return the x center
return getX() + width() / 2;
}
// returns x center
public double getCenterY() {
// return the y center
return getY() + height() / 2;
}
// sets graphic context
public void setGraphics(Graphics2D g) {
// set graphic context
g2d = g;
}
// returns a url
public URL getURL(String filename) {
// url resource
URL url = null;
try {
// attempt to load resource
url = this.getClass().getResource(filename);
}
catch(Exception e) {}
// return resource
return url;
}
// load image resource
public void load(String filename) {
// create instance of toolkit
Toolkit tk = Toolkit.getDefaultToolkit();
// load the image
image = tk.getImage(getURL(filename));
// while width is less then or equal to 0
while(getImage().getWidth(frame) <= 0);
// calculate x
double x = frame.getSize().width / 2 - width() / 2;
// calculate y
double y = frame.getSize().height / 2 - height() / 2;
// calculate affine transform
at = AffineTransform.getTranslateInstance(x, y);
}
// sets transform of image
public void transform() {
// set identity
at.setToIdentity();
// translate it
at.translate((int)getX() + width() / 2, (int)getY() + height() / 2);
// translate rotation
at.rotate(Math.toRadians(getFaceAngle()));
// translate proportions
at.translate(-width() / 2, -height() / 2);
}
// draw the image
public void draw() {
// draw it
g2d.drawImage(getImage(), at, frame);
}
// bounding rectangle
public Rectangle getBounds() {
// temporary rectangle instance for calculations
Rectangle r;
// calculate bounding rectangle
r = new Rectangle((int)getX(), (int)getY(), width(), height());
// return bounding rectangle
return r;
}
}
BaseGameEntity.java
public class BaseGameEntity extends Object {
// player alive
private boolean alive;
// x position
private double x;
// y position
private double y;
// x velocity
private double vx;
// y velocity
private double vy;
// move angle
private double moveAngle;
// face angle
private double faceAngle;
// accessor methods
public boolean isAlive() { return alive; }
public double getX() { return x; }
public double getY() { return y; }
public double getVX() { return vx; }
public double getVY() { return vy; }
public double getMoveAngle() { return moveAngle; }
public double getFaceAngle() { return faceAngle; }
// mutator methods
public void setAlive(boolean alive) { this.alive = alive; }
public void setX(double x) { this.x = x; }
public void incX(double i) { this.x += i; }
public void decX(double i) { this.x -= i; }
public void setY(double y) { this.y = y; }
public void incY(double i) { this.y += i; }
public void decY(double i) { this.y -= i; }
public void setVX(double vx) { this.vx = vx; }
public void incVX(double i) { this.vx += i; }
public void decVX(double i) { this.vx -= i; }
public void setVY(double vy) { this.vy = vy; }
public void incVY(double i) { this.vy += i; }
public void decVY(double i) { this.vy -= i; }
public void setMoveAngle(double angle) { this.moveAngle = angle; }
public void incMoveAngle(double i) { this.moveAngle += i; }
public void decMoveAngle(double i) { this.moveAngle -= i; }
public void setFaceAngle(double angle) { this.faceAngle = angle; }
public void incFaceAngle(double i) { this.faceAngle += i; }
public void decFaceeAngle(double i) { this.faceAngle -= i; }
// default constructor
BaseGameEntity() {
setAlive(false);
setX(0.0);
setY(0.0);
setVX(0.0);
setVY(0.0);
setMoveAngle(0.0);
setFaceAngle(0.0);
}
}
Any assistance would be greatly appreciated.
Sincerely,
The Boss