So I am making a game, where your main objective is to shoot birds and I want a blood.
That means I want a picture of blood to show whenever i shoot one of the birds
And this is my target class, used to shoot the birds
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
This is my bird class
/**
* Write a description of class Bee here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bird extends AnimatedActor
{
public int i=1;
public Bird()
{
super("bird", ".png", 10);
}
/**
* Fly to the left. When we hit the edge, disappear.
*/
public void act()
{
super.act(); // this takes care of the image animation
move(-5.0);
if (atWorldEdge()) {
getWorld().removeObject(this);
//((TestWorld) getWorld()).countBird();
Greenfoot.stop();
}
}
public void location ()
{
super.setLocation(getX (), getY() -5);
if (getX() == 0) {
((TestWorld) getWorld()).gameOver();
}
}
public void pop()
{
Greenfoot.playSound("pop.wav");
getWorld().removeObject(this);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Target here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Target extends Actor
{
/**
* Act - do whatever the Target wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Greenfoot.mouseMoved(null)) {
MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation(mouse.getX(), mouse.getY());
}
// Pop
if(Greenfoot.mouseClicked(null)) {
int x = getImage().getWidth()/2;
int y = getImage().getHeight()/2;
Bird bird = (Bird) getOneObjectAtOffset(x , y, Bird.class);
if(bird != null) {
bird.pop();
((TestWorld) getWorld()).countBird();
}
}
}
}
