Im trying to draw 2 image of the asteroid sprite in my program. I can seem to get to display more than one asteroid
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.util.*;
import java.net.*;
public class SpriteTest extends Applet implements Runnable {
int screenWidth = 640;
int screenHeight = 480;
//double buffer objects
BufferedImage backbuffer;
Graphics2D g2d;
Sprite asteroid;
Sprite spaceship;
ImageEntity background;
Thread gameloop;
Random rand = new Random();
public void init() {
//create the back buffer for smooth graphics
backbuffer = new BufferedImage(screenWidth, screenHeight,
BufferedImage.TYPE_INT_RGB);
g2d = backbuffer.createGraphics();
//load the background
background = new ImageEntity(this);
background.load("bluespace.png");
//load the asteroid sprite
asteroid = new Sprite(this, g2d);
asteroid.load("asteroid2.png");
spaceship = new Sprite(this, g2d);
spaceship.load("spaceship1.png");
}
public void start() {
gameloop = new Thread(this);
gameloop.start();
}
public void stop() {
gameloop = null;
}
public void run() {
Thread t = Thread.currentThread();
while (t == gameloop) {
try {
Thread.sleep(30);
}
catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
public void update(Graphics g) {
//draw the background
g2d.drawImage(background.getImage(), 0, 0, screenWidth-1, screenHeight-1, this);
int width = screenWidth - asteroid.imageWidth() - 1;
int height = screenHeight - asteroid.imageHeight() - 1;
int width2 = screenWidth - spaceship.imageWidth() -2;
int height2 = screenHeight - spaceship.imageHeight() -2;
Point2D point = new Point2D(rand.nextInt(width), rand.nextInt(height));
Point2D point2 = new Point2D(rand.nextInt(width2), rand.nextInt(height2));
asteroid.setPosition(point);
asteroid.transform();
asteroid.draw();
}
spaceship.setPosition(point2);
spaceship.transform();
spaceship.draw();
paint(g);
}
public void paint(Graphics g) {
//draw the back buffer to the screen
g.drawImage(backbuffer, 0, 0, this);