Hi,
I am working on a duck hunt type game, which use the mouse as the cursor and shoots towards it whenever the mouse is pressed. Unfortunately, the bullets never shoot the right way. Here is my Cursor Class:
What is going wrong?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Cursor here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cursor extends Level2Objects
{
MouseInfo mi;
HeliBullet b;
GreenfootImage img;
public Cursor()
{
img = new GreenfootImage("cursor.png");
img.scale(50, 50);
setImage(img);
}
public void act()
{
mi = Greenfoot.getMouseInfo();
if(mi != null)
{
int x = mi.getX();
int y = mi.getY();
setLocation(x, y);
Level2 theWorld = (Level2)getWorld();
Player2nd player = (Player2nd)theWorld.getPlayer();
if(Greenfoot.mouseClicked(null))
{
if(player.getDirection())
{
b = new HeliBullet();
b.turnTowards(getX(), getY());
getWorld().addObject(b, 420, 275);
}
else
{
b = new LeftHeliBullet();
b.turnTowards(getX(), getY());
getWorld().addObject(b, 150, 275);
}
}
}
}
}

