Java 类org.newdawn.slick.util.ResourceLoader 实例源码

项目:trashjam2017    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:trashjam2017    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:trashjam2017    文件:SoundTest.java   
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    try {
        engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
    } catch (IOException e) {
        throw new SlickException("Failed to load engine", e);
    }
    music = musica = new Music("testdata/SMB-X.XM");
    //music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
}
项目:Progetto-C    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:Progetto-C    文件:SoundTest.java   
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    try {
        engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
    } catch (IOException e) {
        throw new SlickException("Failed to load engine", e);
    }
    music = musica = new Music("testdata/SMB-X.XM");
    //music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
}
项目:Progetto-C    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:BaseClient    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:BaseClient    文件:SoundTest.java   
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    try {
        engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
    } catch (IOException e) {
        throw new SlickException("Failed to load engine", e);
    }
    music = musica = new Music("testdata/SMB-X.XM");
    //music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
}
项目:BaseClient    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:opsu-dance    文件:Updater.java   
/**
 * Returns the build date, or the current date if not available.
 */
public int getBuildDate() {
    if (buildDate == -1) {
        Date date = null;
        try {
            Properties props = new Properties();
            props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
            String build = props.getProperty("build.date");
            if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
                date = new Date();
            else {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
                date = format.parse(build);
            }
        } catch (Exception e) {
            date = new Date();
        } finally {
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            buildDate = Integer.parseInt(dateFormat.format(date));
        }
    }
    return buildDate;
}
项目:opsu-dance    文件:Fonts.java   
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
    float fontBase = 12f * GameImage.getUIscale();
    Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
    Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
    DEFAULT = new UnicodeFont(font);
    BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
    XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
    LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
    MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
    MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
    SMALL = new UnicodeFont(font.deriveFont(fontBase));
    SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
    ColorEffect colorEffect = new ColorEffect();
    loadFont(DEFAULT, colorEffect);
    loadFont(BOLD, colorEffect);
    loadFont(XLARGE, colorEffect);
    loadFont(LARGE, colorEffect);
    loadFont(MEDIUM, colorEffect);
    loadFont(MEDIUMBOLD, colorEffect);
    loadFont(SMALL, colorEffect);
    loadFont(SMALLBOLD, colorEffect);
}
项目:opsu-dance    文件:SoundController.java   
/**
 * Loads and returns a Clip from a resource.
 * @param ref the resource name
 * @param isMP3 true if MP3, false if WAV
 * @return the loaded and opened clip
 */
private static MultiClip loadClip(String ref, boolean isMP3) {
    try {
        URL url = ResourceLoader.getResource(ref);

        // check for 0 length files
        InputStream in = url.openStream();
        if (in.available() == 0) {
            in.close();
            return new MultiClip(ref, null);
        }
        in.close();

        AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
        return loadClip(ref, audioIn, isMP3);
    } catch (Exception e) {
        explode(String.format("Failed to load file '%s'.", ref), e, DEFAULT_OPTIONS);
        return null;
    }
}
项目:opsu-dance    文件:SoundController.java   
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
    String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
    File skinDir = SkinService.skin.getDirectory();
    if (skinDir != null) {
        File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
        if (skinWAV.isFile())
            return skinWAV.getAbsolutePath();
        if (skinMP3.isFile())
            return skinMP3.getAbsolutePath();
    }
    if (ResourceLoader.resourceExists(wav))
        return wav;
    if (ResourceLoader.resourceExists(mp3))
        return mp3;
    return null;
}
项目:FEMultiPlayer-V2    文件:FEResources.java   
/**
 * Load resources.
 */
public static void loadResources() {
    try {
        //Load bitmap fonts
        loadBitmapFonts();

        // Textures
        textures.put("whoops", new AnimationData("res/whoops.png"));
        loadTextures(); 
        //load audio
        audio.put("miss", AudioLoader.getAudio("WAV",
                ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));

    } catch (IOException e) {
        int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
        System.out.println(max);
        e.printStackTrace();
    }
    System.gc();
}
项目:FEMultiPlayer-V2    文件:FEResources.java   
/**
 * Gets the texture data.
 *
 * @param string the string
 * @return the texture data
 */
public static AnimationData getTextureData(String string) {
    AnimationData t = textures.get(string);
    if(t != null) {
        return t;
    } else {
        //try to get it, in case we forgot
        System.err.println("Warn: " + string + " not explicitly defined");
        for(String loc: searchFolders){
            if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
                AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
                textures.put(string, txt);
                return txt;
            }

        }
        return textures.get("whoops");
    }
}
项目:FEMultiPlayer-V2    文件:FEResources.java   
/**
     * Gets the audio.
     *
     * @param name the name
     * @return the audio
     */
    public static Audio getAudio(String name) {
        Audio a = audio.get(name);
        if(a == null) {
//          System.err.println("Warn: " + name + " not explicitly defined");
            try{
                Audio b = AudioLoader.getAudio("WAV",
                        ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
                audio.put(name, b);
                return b;
            } catch (Exception e){
                return null;
            }
        } else {
            return a;
        }
    }
项目:YellowSquare    文件:TileMap.java   
public void loadMap(String name) {
    try {
        ObjectInputStream oos = new ObjectInputStream(ResourceLoader
                .getResourceAsStream(GamePanel.resfolder + "stages" + File.separator + name + ".map"));
        TileMapData data = (TileMapData) oos.readObject();
        this.tiles = data.tiles;
        width = data.width;
        height = data.height;
        oos.close();

        return;
    } catch (Exception e) {
        System.err.println("Map: '" + name + "' is corrupt");
        e.printStackTrace();
    }
}
项目:Mystic-Bastion    文件:Sounds.java   
public void loadSound(String fileName, String exe) {
    try {
        String withoutDot = exe.replace(".", "");
        if (exe == ".ogg") {
            audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
                    ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
        } else if (exe == ".xm") {
            audio = AudioLoader.getStreamingAudio("MOD",
                    ResourceLoader.getResource("sound/" + fileName + exe.toUpperCase()));
        } else if (exe == ".aif") {
            audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
                    ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
        } else if (exe == ".wav") {
            audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
                    ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
        } else {
            System.out.println("Only Support OGG MOD AIF or WAV");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:code404    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:code404    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:Save-The-Ball    文件:Score.java   
/**
 * Initialise resources
 */
public Score() {
    readHighScore();
    //load a default java font
    Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
    font = new TrueTypeFont(awtFont, antiAlias);

    // load font from file
    try {
        InputStream inputStream = ResourceLoader.getResourceAsStream("res/fonts/brick.ttf");

        Font awtFont2 = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        awtFont2 = awtFont2.deriveFont(50f); // set font size
        font2 = new TrueTypeFont(awtFont2, antiAlias);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:SpaceStationAlpha    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:GameCo    文件:Sounds.java   
public void Sounds(){
        try {
//          oggEffect = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("testdata/restart.ogg"));
//          oggStream = AudioLoader.getStreamingAudio("OGG", ResourceLoader.getResource("testdata/bongos.ogg"));
//          102.modStream = AudioLoader.getStreamingAudio("MOD", ResourceLoader.getResource("testdata/SMB-X.XM"));
            //modStream.playAsMusic(1.0f, 1.0f, true);
//          aifEffect = AudioLoader.getAudio("AIF", ResourceLoader.getResourceAsStream("testdata/burp.aif"));
//          wavEffect = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/cbrown01.wav"));

            wavHitTree = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("/res/sounds/hittree.wav"));
            oggHitTree = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("res/sounds/hittree.ogg"));

            } catch (IOException e) {
                e.printStackTrace();

        }
    }
项目:SpaceStationAlpha    文件:SoundTest.java   
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    try {
        engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
    } catch (IOException e) {
        throw new SlickException("Failed to load engine", e);
    }
    music = musica = new Music("testdata/SMB-X.XM");
    //music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
}
项目:opsu    文件:Updater.java   
/**
 * Returns the build date, or the current date if not available.
 */
public int getBuildDate() {
    if (buildDate == -1) {
        Date date = null;
        try {
            Properties props = new Properties();
            props.load(ResourceLoader.getResourceAsStream(Options.VERSION_FILE));
            String build = props.getProperty("build.date");
            if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
                date = new Date();
            else {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
                date = format.parse(build);
            }
        } catch (Exception e) {
            date = new Date();
        } finally {
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            buildDate = Integer.parseInt(dateFormat.format(date));
        }
    }
    return buildDate;
}
项目:opsu    文件:Options.java   
/**
 * Loads the skin given by the current skin directory.
 * If the directory is invalid, the default skin will be loaded.
 */
public static void loadSkin() {
    File skinDir = getSkinDir();
    if (skinDir == null)  // invalid skin name
        skinName = Skin.DEFAULT_SKIN_NAME;

    // set skin and modify resource locations
    ResourceLoader.removeAllResourceLocations();
    if (skinDir == null)
        skin = new Skin(null);
    else {
        // load the skin
        skin = SkinLoader.loadSkin(skinDir);
        ResourceLoader.addResourceLocation(new FileSystemLocation(skinDir));
    }
    ResourceLoader.addResourceLocation(new ClasspathLocation());
    ResourceLoader.addResourceLocation(new FileSystemLocation(new File(".")));
    ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
}
项目:cretion    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:opsu    文件:SoundController.java   
/**
 * Loads and returns a Clip from a resource.
 * @param ref the resource name
 * @return the loaded and opened clip
 */
private static MultiClip loadClip(String ref) {
    try {
        URL url = ResourceLoader.getResource(ref);

        // check for 0 length files
        InputStream in = url.openStream();
        if (in.available() == 0) {
            in.close();
            return new MultiClip(ref, null);
        }
        in.close();

        AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
        return loadClip(ref, audioIn);
    } catch (Exception e) {
        ErrorHandler.error(String.format("Failed to load audio file '%s'.", ref), e, true);
        return null;
    }
}
项目:opsu    文件:SoundController.java   
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
    String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
    File skinDir = Options.getSkin().getDirectory();
    if (skinDir != null) {
        File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
        if (skinWAV.isFile())
            return skinWAV.getAbsolutePath();
        if (skinMP3.isFile())
            return skinMP3.getAbsolutePath();
    }
    if (ResourceLoader.resourceExists(wav))
        return wav;
    if (ResourceLoader.resourceExists(mp3))
        return mp3;
    return null;
}
项目:cretion    文件:ShaderManagerImpl.java   
/**
 * Gets the program code from the file <tt>filename</tt> and puts it into a
 * <tt>ByteBuffer</tt>.
 *
 * @param filename
 *            the full name of the file.
 * @return a ByteBuffer containing the program code.
 * @throws SlickException
 */
private ByteBuffer getProgramCode(String filename) throws SlickException {
    InputStream fileInputStream;
    byte[] shaderCode;

    fileInputStream = ResourceLoader.getResourceAsStream(filename);
    DataInputStream dataStream = new DataInputStream(fileInputStream);
    try {
        dataStream.readFully(shaderCode = new byte[fileInputStream.available()]);
        fileInputStream.close();
        dataStream.close();
    } catch (IOException e) {
        throw new SlickException(e.getMessage());
    }

    ByteBuffer shaderPro = BufferUtils.createByteBuffer(shaderCode.length);

    shaderPro.put(shaderCode);
    shaderPro.flip();

    return shaderPro;
}
项目:SpaceStationAlpha    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:TeacherSmash    文件:Draw.java   
public static void drawBackGround(){
    initGL(Display.getWidth(),Display.getHeight());
    try {
        Texture background =  TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("imgs/Map_test_1.jpg"));
        background.bind();
        glBegin(GL_QUADS);
        GL11.glTexCoord2f(0,0);
        GL11.glVertex2f(0,0);
        GL11.glTexCoord2f(1,0);
        GL11.glVertex2f(background.getTextureWidth(),0);
        GL11.glTexCoord2f(1,1);
        GL11.glVertex2f(background.getTextureWidth(),background.getTextureHeight());
        GL11.glTexCoord2f(0,1);
        GL11.glVertex2f(0,background.getTextureHeight());
        GL11.glBindTexture(GL_TEXTURE_2D,0);
        glEnd();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:GPVM    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:GPVM    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:cretion    文件:PackedSpriteSheet.java   
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

    try {
        image = new Image(basePath+reader.readLine(), false, filter, trans);
        while (reader.ready()) {
            if (reader.readLine() == null) {
                break;
            }

            Section sect = new Section(reader);
            sections.put(sect.name, sect);

            if (reader.readLine() == null) {
                break;
            }
        }
    } catch (Exception e) {
        Log.error(e);
        throw new SlickException("Failed to process definitions file - invalid format?", e);
    }
}
项目:GPVM    文件:SoundTest.java   
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    try {
        engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
    } catch (IOException e) {
        throw new SlickException("Failed to load engine", e);
    }
    music = musica = new Music("testdata/SMB-X.XM");
    //music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
}
项目:GPVM    文件:XMLPackedSheet.java   
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
    image = new Image(imageRef, false, Image.FILTER_NEAREST);

    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));

        NodeList list = doc.getElementsByTagName("sprite");
        for (int i=0;i<list.getLength();i++) {
            Element element = (Element) list.item(i);

            String name = element.getAttribute("name");
            int x = Integer.parseInt(element.getAttribute("x"));
            int y = Integer.parseInt(element.getAttribute("y"));
            int width = Integer.parseInt(element.getAttribute("width"));
            int height = Integer.parseInt(element.getAttribute("height"));

            sprites.put(name, image.getSubImage(x,y,width,height));
        }
    } catch (Exception e) {
        throw new SlickException("Failed to parse sprite sheet XML", e);
    }
}
项目:trashjam2017    文件:BigImage.java   
/**
 * Create a new big image by loading it from the specified reference
 * 
 * @param ref The reference to the image to load
 * @param filter The image filter to apply (@see #Image.FILTER_NEAREST)
 * @param tileSize The maximum size of the tiles to use to build the bigger image
 * @throws SlickException Indicates we were unable to locate the resource
 */
private void build(String ref, int filter, int tileSize) throws SlickException {
    try {
        final LoadableImageData data = ImageDataFactory.getImageDataFor(ref);
        final ByteBuffer imageBuffer = data.loadImage(ResourceLoader.getResourceAsStream(ref), false, null);
        build(data, imageBuffer, filter, tileSize);
    } catch (IOException e) {
        throw new SlickException("Failed to load: "+ref, e);
    }
}
项目:trashjam2017    文件:GameContainer.java   
/**
 * Get the build number of slick 
 * 
 * @return The build number of slick
 */
public static int getBuildVersion() {
    try {
        Properties props = new Properties();
        props.load(ResourceLoader.getResourceAsStream("version"));

        int build = Integer.parseInt(props.getProperty("build"));
        Log.info("Slick Build #"+build);

        return build;
    } catch (Exception e) {
        Log.error("Unable to determine Slick build number");
        return -1;
    }
}
项目:trashjam2017    文件:CursorLoader.java   
/**
 * Get a cursor based on a image reference on the classpath
 * 
 * @param ref The reference to the image to be loaded
 * @param x The x-coordinate of the cursor hotspot (left -> right)
 * @param y The y-coordinate of the cursor hotspot (bottom -> top)
 * @return The create cursor
 * @throws IOException Indicates a failure to load the image
 * @throws LWJGLException Indicates a failure to create the hardware cursor
 */
public Cursor getCursor(String ref,int x,int y) throws IOException, LWJGLException {
    LoadableImageData imageData = null;

    imageData = ImageDataFactory.getImageDataFor(ref);
    imageData.configureEdging(false);

    ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), true, true, null);
    for (int i=0;i<buf.limit();i+=4) {
        byte red = buf.get(i);
        byte green = buf.get(i+1);
        byte blue = buf.get(i+2);
        byte alpha = buf.get(i+3);

        buf.put(i+2, red);
        buf.put(i+1, green);
        buf.put(i, blue);
        buf.put(i+3, alpha);
    }

    try {
        int yspot = imageData.getHeight() - y - 1;
        if (yspot < 0) {
            yspot = 0;
        }

        return new Cursor(imageData.getTexWidth(), imageData.getTexHeight(), x, yspot, 1, buf.asIntBuffer(), null);
    } catch (Throwable e) {
        Log.info("Chances are you cursor is too small for this platform");
        throw new LWJGLException(e);
    }
}