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

2015/4/22

Project for class

Regw03 Regw03

2015/4/22

#
Ok so my new issue is getting my bullet to rotate with my Hunter class. Ive got it attached so to speak as well as got it to fire on the use of a comand key but it will not rotate to fire in the direction that my Hunter is facing. Any suggestions?
public void act()
    
    {
       if(canSee(Tree.class))
        {
            turn(180);
        }
       if(Greenfoot.isKeyDown ("up"))
        {
            move();
        }
       if(Greenfoot.isKeyDown ("down"))
        {
            turn(180);
        }
       if(Greenfoot.isKeyDown ("left"))
        {
            turn(-7);
        }
       if(Greenfoot.isKeyDown ("right"))
        {
            turn(7);
        }
       if(Greenfoot.isKeyDown ("space"))
       {
         Fire();
        }
    }
    public void Fire()
     {
       if ("space".equals(Greenfoot.getKey()))
       {
         
          getWorld().addObject(new Bullet(), getX(), getY());
          
         
       }
    }
Regw03 Regw03

2015/4/22

#
And where is a good place to get sounds for my game
azazeel azazeel

2015/4/25

#
    public void Fire()
     {
       if ("space".equals(Greenfoot.getKey()))
       {
          Bullet b = new Bullet();
          b.turn(getRotation());
          getWorld().addObject(b, getX(), getY());         
       }
    }
just google it to find sound effect
danpost danpost

2015/4/25

#
There is another issue with the code you supplied. You are checking for the 'space' key being down to call the fire method and then checking if the key has been released in the fire method. Both will never be true at the same time; so, a bullet will never be fired.
You need to login to post a reply.