Alright i shall implement this code and post the results here...
private static final String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
letter = ""+((char)(Greenfoot.getRandomNumber(26)+65));
Here is the code for the bomb...it doesn't appear to work...saying that getImage needs a return type...
public class Bomb extends Actor
{
int animation = 1;
private String letter = ""+((char)(Greenfoot.getRandomNumber(26)+65));
// then in the constructor, select a letter with
// followed by drawing the letter on the bomb
int fontsize = 36; // fontsize of letter (adjust at will)
Color white = Color.white, trans = new Color(0, 0, 0, 0);
GreenfootImage image = new GreenfootImage(letter, fontsize, white, trans); // creates letter image
int xOff = 25; // horizontal letter placement on bomb (adjust at will)
int yOff = 15; // vertical letter placement on bomb (adjust at will)
// puts letter on bomb
getImage().drawImage(image, xOff, 15);
public void act()
{
if (getY()<520)
{
setImage("Missile/"+ animation +".png");
setLocation(getX(), getY()+1);
animation++;
if(animation ==12)
{
animation=1;
}
if (!Greenfoot.isKeyDown(letter)) // check correct letter pressed
{
// create explosion
getWorld().removeObject(this);
}
}
else
{
{
setImage("Explosion/"+ animation +".png");
animation++;
if (animation == 25)
{
getWorld().removeObject(this);
}
}
}
}
}
public class Bomb extends Actor
{
int animation = 1;
private String letter = ""+((char)(Greenfoot.getRandomNumber(26)+65));
public Bomb()
{
int fontsize = 36; // fontsize of letter (adjust at will)
Color white = Color.white, trans = new Color(0, 0, 0, 0);
GreenfootImage image = new GreenfootImage(letter, fontsize, white, trans); // creates letter image
int xOff = 25; // horizontal letter placement on bomb (adjust at will)
int yOff = 15; // vertical letter placement on bomb (adjust at will)
// put letter on bomb
getImage().drawImage(image, xOff, 15);
}
public void act()
{
if (getY()<520)
{
setImage("Missile/"+ animation +".png");
setLocation(getX(), getY()+1);
animation++;
if(animation ==12)
{
animation=1;
}
if (!Greenfoot.isKeyDown(letter)) // check correct letter pressed
{
// create explosion
getWorld().removeObject(this);
}
}
else
{
setImage("Explosion/"+ animation +".png");
animation++;
if (animation == 25)
{
getWorld().removeObject(this);
}
}
}
}import greenfoot.*;
import java.awt.Color;
public class Bomb extends Actor
{
int animation = 1;
private String letter = ""+((char)(Greenfoot.getRandomNumber(26)+65));
public Bomb()
{
int fontsize = 18; // fontsize of letter (adjust at will)
Color white = Color.GREEN, trans = new Color(0, 0, 0, 0);
GreenfootImage image = new GreenfootImage(letter, fontsize, white, trans); // creates letter image
int xOff = 25; // horizontal letter placement on bomb (adjust at will)
int yOff = 15; // vertical letter placement on bomb (adjust at will)
// put letter on bomb
getImage().drawImage(image, xOff, 15);
}
public void act()
{
if (getY()<520)
{
setImage("Missile/"+ animation +".png");
setLocation(getX(), getY()+1);
animation++;
if(animation ==12)
{
animation=1;
}
if (!Greenfoot.isKeyDown(letter)) // check correct letter pressed
{
// create explosion
getWorld().removeObject(this);
}
}
else
{
setImage("Explosion/"+ animation +".png");
animation++;
if (animation == 25)
{
getWorld().removeObject(this);
}
}
}
}
if (!Greenfoot.isKeyDown(letter)) // check correct letter pressed
{
// create explosion
getWorld().removeObject(this);
} if (Greenfoot.isKeyDown(letter))
public class Bomb extends Actor
{
int animation = 0;
private String letter = ""+((char)(Greenfoot.getRandomNumber(26)+65));
private GreenfootImage[] images = new GreenfootImage[12];
private boolean exploding;
public Bomb()
{
int fontsize = 36; // fontsize of letter (adjust at will)
Color white = Color.white, trans = new Color(0, 0, 0, 0);
GreenfootImage image = new GreenfootImage(letter, fontsize, white, trans); // creates letter image
int xOff = 25; // horizontal letter placement on bomb (adjust at will)
int yOff = 15; // vertical letter placement on bomb (adjust at will)
// put letter on bombs
int i = 0;
while (i < 11)
{
images[i] = new GreenfootImage("Missle/"+(i+1)+".png");
images[i].drawImage(image, xOff, yOff);
i = i + 1;
}
setImage(images[0]);
}
public void act()
{
if (!exploding)
{
setLocation(getX(), getY()+1);
animation++;
if(animation ==11)
{
animation=0;
}
setImage(images[animation]);
if (Greenfoot.isKeyDown(letter) || getY()>=520)
{
exploding = true;
animation = 1;
}
}
else
{
setImage("Explosion/"+ animation +".png");
animation++;
if (animation == 25)
{
getWorld().removeObject(this);
}
}
}
}