This site requires JavaScript, please enable it in your browser!
Greenfoot back
OxiClean
OxiClean wrote ...

2013/3/19

I am in need of some help with my shooting!

OxiClean OxiClean

2013/3/19

#
Alrighty, what I want this code to do is shoot the 'Bullet' OUT OF the character 'Felix' and go in the direction of the mouse all the way to the edge of the screen where it is removed through code in the 'Bullet' class. What is happening now is when I shoot the bullet it comes OUT OF the mouse and goes all the way to the right edge of the screen, so it's not coming out of Felix or going in the direction I want it to. Here is the code:
    public void shoot()
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        if(shootdelay >= mindelay)          
        {
            int rot = getRotation()-10;
            int xOffset = (int)(40 *Math.cos(Math.toRadians(rot)));
            int yOffset = (int)(40 *Math.sin(Math.toRadians(rot)));
            Bullet b = new Bullet(getRotation());

            getWorld().addObject(b, mouse.getX()+xOffset, mouse.getY()+yOffset);
            shootdelay = -20;
 
        }
    }  
In advance, thank you!!!
danpost danpost

2013/3/19

#
This should be closer to what you want. You can use a simple constructor in the Bullet class (without any parameters).
public void shoot()
{
    MouseInfo mouse = Greenfoot.getMouseInfo();
    if (shootdelay >= mindelay)
    {
        int rot = getRotation()-10;
        Bullet b = new Bullet();
        getWorld().addObject(b, getX(), getY());
        b.turnTowards(mouse.getX(), mouse.getY());
        shootdelay = -20;
    }
}
OxiClean OxiClean

2013/3/19

#
Getting an error with this
Bullet b = new Bullet(); 
"Constructor Bullet in class Bullet can not be applied to given types;" Thanks a lot though, danpost! Edit: It is saying that an integer is required
danpost danpost

2013/3/19

#
danpost wrote...
You can use a simple constructor in the Bullet class (without any parameters).
What I meant by this, was that you change your Bullet constructor to the following:
public Bullet()
{
}
OxiClean OxiClean

2013/3/19

#
Oh, I completely forgot, thank you!
You need to login to post a reply.