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

2015/12/4

Gun problem help

jasper079 jasper079

2015/12/4

#
please help!!!!!!!!!!!!!!!!!!!!!!!!!!! the error message: method move in class greenfoot.Actor cannot be applied to given types; required: int; found: no arguments; reason: actual and formal argument lists differ in length
    private void fire() 
    {
        if(reloadDelayCount >= gunReloadTime) {
            MachineGun b = new MachineGun(getMovement().copy(), 0);
            getWorld().addObject(b, getX(), getY());
            b.move();
            shotsFired++;
            reloadDelayCount = 0;
        }
    }
}
the move() in Mover witch is my sub class that player class comes under:
    public void move() 
    {
      x = x + movement.getX();
        y = y + movement.getY();
        if(x >= getWorld().getWidth()) {
            x = 0;
        }
        if(x < 0) {
            x = getWorld().getWidth() - 1;
        }
        if(y >= getWorld().getHeight()) {
            y = 0;
        }
        if(y < 0) {
            y = getWorld().getHeight() - 1;
        }
        setLocation(x, y);
    }
Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Super_Hippo Super_Hippo

2015/12/4

#
Are you firing a MachineGun? Shouldn't it firing a bullet? Anyway, the MachineGun is probably not a subclass of it, so it can't use the method. To use the normal 'move' method, you could use
b.move(2);
jasper079 jasper079

2015/12/6

#
it is compiling but not moving it is just showing up and not moving help
jasper079 jasper079

2015/12/6

#
Super_Hippo wrote...
Are you firing a MachineGun? Shouldn't it firing a bullet? Anyway, the MachineGun is probably not a subclass of it, so it can't use the method. To use the normal 'move' method, you could use
b.move(2);
it is a bullet but i named it MachineGun as i am going to add different wepons
danpost danpost

2015/12/7

#
Actually, you do not need a 'move' call there in the 'fire' method unless you want to have the initial location of the bullet at the end of the barrel of the weapon. The code given is representing the instance in time that the bullet it added into the world. The moving of the bullet will, or should, occur on upcoming act cycles by way of the class that creates it where 'move' should be called from the 'act' method. Now, if that class does extend the Mover class, then the issue may be what the values of 'movement' are set to (if they are zero, then, of course, the actor will not move).
You need to login to post a reply.