Discussion of Activity 12.2

Sample solution

Code for method whoosh():


        void whoosh()
        {
            try
            {
                InputStream is = getClass().getResourceAsStream("/res/whoosh.wav");
                Player player = Manager.createPlayer(is, "audio/X-wav");
                player.start();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    

Code inserted in game loop:

 
        // is the robot at the star portal?
        if (robot.collidesWith(starPortal, false))
        {
            whoosh();
            layerManager.remove(robot);
            draw(g);
            return;
        }