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

2019/1/4

Need help with shooting mechanic in the code.

EpicBaller5621 EpicBaller5621

2019/1/4

#
Hello, I recently started on a project and watched some Youtube tutorials, and I am getting stuck on how to turn my bullet to the left side. It only shoots to the right even if I change the direction. I need some help please! My shooting methods for my character are :
public boolean shooting()
    {
        if(Greenfoot.isKeyDown("x") && ShootingCounter <= 0 && facing == 1)
        {
            getWorld().addObject(new ShootRight(), getX(), getY());
            ShootingCounter = 100;
            return true;
        }
        
        return false;
    }
    public  boolean shooting2()
    {
        if(Greenfoot.isKeyDown("c") && ShootingCounter <= 0 && facing == -1)
        {
            getWorld().addObject(new ShootLeft(), getX(), getY());
            
            ShootingCounter = 100;
            return true;
        }
        return false;
    }
and this is my shoot right and shoot left sub class
private int shootingSpeed = 8;
    /**
     * Act - do whatever the ShootRight wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        fly();
        killBadGuys();
    }    
    public void fly()
    {
        setLocation(getX() + shootingSpeed, getY());
    }
danpost danpost

2019/1/4

#
In your ShootLeft class, do you have a minus where the plus ('+') is in line 13 above in the ShootRight code?
EpicBaller5621 EpicBaller5621

2019/1/4

#
Oh my god, I feel so stupid right now. I literally spent so much time trying to figure what was wrong. It was just the change of the "+" in line 13 to a "-". Thank you so much for the help!!!!!
You need to login to post a reply.