I am sort of new and I have a game where you play as a bee who fires nectar.However the nectar can only go right,but I want it
to go to whatever direction the bee is facing.Here is my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bee here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bee extends Actor
{
/**
* Act - do whatever the bee wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (Greenfoot.isKeyDown ("left"))
{
turn(-4);
}
if (Greenfoot.isKeyDown ("right"))
{
turn(4);
}
if (Greenfoot.isKeyDown ("up"))
{
World world;
world = getWorld();
world.addObject (new nectar(), getX(), getY());
}
}
}
And the code for nectar is;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
I need some sort of variable or boolean to find the direction the bees facing
* Write a description of class nectar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class nectar extends Actor
{
/**
* Act - do whatever the nectar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move (6);
}
}

