/** Loop a sound file (in .wav, .mid, or .au format) in a background thread. */ public static void loop(String filename) { URL url = null; try { File file = new File(filename); if (file.canRead()) url = file.toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } // URL url = StdAudio.class.getResource(filename); if (url == null) throw new RuntimeException("audio " + filename + " not found"); AudioClip clip = Applet.newAudioClip(url); clip.loop(); }
/** * Gets an AudioClip. * * @return the audio clip */ public AudioClip getAudioClip() { if (clip == null && getURL() != null) { clip = Applet.newAudioClip(getURL()); } return clip; }
public GamePanel(String name, int l) { setFocusable(true); grabFocus(); addMouseListener(this); addMouseMotionListener(this); addKeyListener(this); keys = new boolean[10000]; try { scoreFont = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf"))) .deriveFont(0, 32); } catch (IOException ioe) { System.out.println("error loading BRLNSB.tff"); } catch (FontFormatException ffe) { System.out.println("Something went wrong with the font."); } gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage(); for (int i = 1; i < 7; i++) { magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage()); } coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage(); player1 = new Player(200, 300, 100, "sheldon"); click = false; ground = true; pause = false; lvlClear = false; die = false; musicOn = true; player1.setVelo(150); player1.setInvi(true); // ------------------------------------------------------------------------------------------------------------------------------------ // Sound coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav")); clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav")); starSound = Applet.newAudioClip(getClass().getResource("star.wav")); bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav")); bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav")); bckGrndMusic.loop(); // ------------------------------------------------------------------------------------------------------------------------------------ // distance=0; score = 0; coins = 0; level = 1; prevLvl = level; backy = 0; height = backy; dieHeight = 0; dieMenuHeight = 0; pauseB = new SButton(400, 670, "pause", ""); resumeB = new SButton(100, 500, "resume", ""); menuB = new SButton(100, 620, "back", ""); muteB = new SButton(400, 600, "mute", ""); unmuteB = new SButton(400, 600, "unmute", ""); // System.out.println("characters/"+name+"/"+name+"35.png"); }