I'm trying to make it where the bullets and enemies disappear both when the bullet hits them. Also, I'm trying to make it where the bullet shoots in the direction its facing. Lastly, I'm trying to make it where the enemy only shoots one bullet at a time. Here is my code for my bullet class and enemy class.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Stinger extends Actor
{
public void act()
{
move(5);
checkCollision();
}
public void checkCollision()
{
Actor bee2 = (Actor) getOneIntersectingObject(Bee2.class);
if(bee2 != null)
{
getWorld().removeObject(bee2);
getWorld().removeObject(this);
}
}
}
and enemy class
import greenfoot.*;
/**
* Write a description of class Ladybug1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bee2 extends Actor
{
private int beehivesEaten;
private int health;
private GreenfootImage image3;
private GreenfootImage image4;
/**
* Act - do whatever the Ladybug1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Bee2()
{
beehivesEaten = 0;
image3 = new GreenfootImage("bee.png");
image4 = new GreenfootImage("bee2.png");
setImage(image3);
}
public void act()
{
followBeehive();
lookForBeehive();
switchImage();
}
public void followBeehive()
{
turnTowards(150,500);
Actor beehive = (Actor) getOneIntersectingObject(Beehive.class);
move(3);
if(beehive !=null)
{
getWorld().removeObject(beehive);
}
}
public void attackBeehive()
{
if(!getObjectsInRange(500, Beehive.class).isEmpty())
{
Actor beehive=(Actor) getObjectsInRange(200, Beehive.class).get(0);
if(beehive !=null)
{
followBeehive();
}
}
}
private void lookForBeehive()
{
if (isTouching(Beehive.class))
{
Greenfoot.playSound("munch.mp3");
removeTouching(Beehive.class);
beehivesEaten = beehivesEaten + 1;
}
}
public void switchImage()
{
if (getImage() == image3)
{
setImage(image4);
}
else
{
setImage(image3);
}
}
}
// References
//www.youtube.com/watch?v=DoElE2f_QdM
//www.youtube.com/watch?v=aiNg8ChsyUg
//www.greenfoot.org/topics/60455/0

