Example usage for com.badlogic.gdx Gdx files

List of usage examples for com.badlogic.gdx Gdx files

Introduction

In this page you can find the example usage for com.badlogic.gdx Gdx files.

Prototype

Files files

To view the source code for com.badlogic.gdx Gdx files.

Click Source Link

Usage

From source file:awakening.view.menu.Options.java

License:Apache License

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);/*from   w  w  w.  j  a  va2  s.c o  m*/
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.graphics.setDisplayMode(game.getSize().width, game.getSize().height, game.isFullscreen());

    ///Settings
    sound.setVolume(game.getMusicVolume());

    ///Cursor
    Pixmap pm = new Pixmap(Gdx.files.internal("img/cursor.png"));
    Gdx.input.setCursorImage(pm, 0, 0);
    pm.dispose();

    ///Draw Background
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    batch.draw(background, 0, 0, Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getHeight());
    batch.end();

    ///Draw Stage
    stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
    stage.draw();
}

From source file:awakening.view.menu.WaitingRoomClient.java

License:Apache License

/**
 * Constructor/*  ww w .  j  a v a 2  s . c  o m*/
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public WaitingRoomClient(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;

    try {
        socket = new Socket(InetAddress.getByName(null), 1134);
        input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    th1 = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                while (true) {
                    String messagePlayer = input.readLine();
                    if (messagePlayer != null) {
                        TextArea t = new TextArea(messagePlayer, skin);
                        t.setTouchable(Touchable.disabled);
                        chatBox.row();
                        chatBox.add(t).height(75).width(500);
                    }
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    th1.start();

    stage = new Stage();

    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_waiting_room"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_selection.png")));
    widgetsBackground.setSize(Gdx.app.getGraphics().getWidth() - Gdx.app.getGraphics().getWidth() / 8,
            Gdx.app.getGraphics().getHeight() - Gdx.app.getGraphics().getHeight() / 8);

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);

    ///ChatBox
    chatBox = new Table();
    scroll = new ScrollPane(chatBox);
    scroll.setForceScroll(false, true);
    scroll.setFlickScroll(true);
    scroll.setOverscroll(false, false);

    ///Message
    message = new TextField("", skin);
    btnSend = new TextButton(language.getString("button_send"), skin);

}

From source file:awakening.view.menu.WaitingRoomServer.java

License:Apache License

/**
 * Constructor//from   www  .  ja  v  a  2s.  c om
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public WaitingRoomServer(TAGame game, Music sound, Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;

    try {
        serverSocket = new ServerSocket(portEcoute);
    } catch (IOException e) {
        System.err.println("Creation de la socket impossible : " + e);
        System.exit(-1);
    }

    stage = new Stage();

    try {
        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_waiting_room"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_selection.png")));
    widgetsBackground.setSize(Gdx.app.getGraphics().getWidth() - Gdx.app.getGraphics().getWidth() / 8,
            Gdx.app.getGraphics().getHeight() - Gdx.app.getGraphics().getHeight() / 8);

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);

    ///ChatBox
    chatBox = new Table();
    scroll = new ScrollPane(chatBox);
    scroll.setForceScroll(false, true);
    scroll.setFlickScroll(true);
    scroll.setOverscroll(false, false);

    ///Message
    message = new TextField("", skin);
    btnSend = new TextButton(language.getString("button_send"), skin);

    ///Start Button
    btnStart = new TextButton(language.getString("button_start"), skin);

}

From source file:be.ac.ucl.lfsab1509.bouboule.game.body.GameBody.java

License:Open Source License

/**
 * Make a json object with the constructor argument MakeBody.
 * //from w  w  w .  jav a 2 s. com
 * makeJsonBody(BodyDef.BodyType bodyType, float density,
 *    float elasticity, Vector2 pos,float angle, String jsonFile, String jsonName, float size)
 */
private void makeJsonBody(final BodyDef.BodyType bodyType, final float density, final float elasticity,
        final boolean sensor, final Vector2 pos, final float angle, final String jsonFile,
        final String jsonName, final float size) {

    //Basoic Object definition for Physics
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = density;
    fixtureDef.restitution = elasticity;
    fixtureDef.isSensor = sensor;

    //Load the json Loader
    FileHandle json = Gdx.files.internal(jsonFile);
    BodyEditorLoader loader = new BodyEditorLoader(json);

    loader.attachFixture(body, jsonName, fixtureDef, size);
    origin = loader.getOrigin(jsonName, size).cpy();

}

From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.GameLoop.java

License:Open Source License

/**
 * Launch the creation of the batch thanks to the camera. if debug == true,
 * set up the debugger matrix/*from  w w w.j  a va2s . c  om*/
 * 
 * @param cam    : the OrthographicCamera of the game
 * @param debug : load the debugging matrix
 * 
 * GameLoop(OrthographicCamera cam, boolean debug)
 */
public GameLoop(final OrthographicCamera cam, final boolean debug) {

    // creation of the batch and matrix (physical edges of the bodies)
    // debugger
    batch = new SpriteBatch();
    batch.setProjectionMatrix(cam.combined);

    if (debug) {
        debugMatrix = new Matrix4(cam.combined);
        debugMatrix.scale(GraphicManager.getGameToWorld(), GraphicManager.getGameToWorld(), 1f);

        debugRenderer = new Box2DDebugRenderer();
    }

    // Create only once the graphicManager
    graphicManager = new GraphicManager();

    // Load the font
    fontOswald = new BitmapFont(Gdx.files.internal("fonts/Oswald/Oswald.fnt"),
            Gdx.files.internal("fonts/Oswald/Oswald.png"), false);
    fontOsaka = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);

    fontOsakaRed = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);
    fontOsakaRed.setColor(.95f, .05f, .05f, 1f);

    // Pause
    if (GlobalSettings.GAME.isGdxMenus()) {
        fontPause = new BitmapFont(Gdx.files.internal("fonts/OsakaBig/OsakaBig.fnt"),
                Gdx.files.internal("fonts/OsakaBig/OsakaBig.png"), false);
        fontPause.setColor(.95f, .05f, .05f, 1f);
        texturePause = new Texture("buttons/home_button.png");
        pixmapFade = new Pixmap(1, 1, Format.RGB888);
        spriteFade = new Sprite(new Texture(pixmapFade));
        spriteFade.setColor(0, 0, 0, 0);
        spriteFade.setSize(GlobalSettings.APPWIDTH * 2, GlobalSettings.APPHEIGHT * 2); // bigger size to cover all the zone
        spriteFade.setPosition(-GlobalSettings.APPWIDTH / 2, -GlobalSettings.APPHEIGHT / 2);
    }

    // load the counter
    countDown = new CountDown(2, 2, 1f, "anim/countdown.png", true); // 3 sec

    // new randomGenerator
    random = new Random();
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.level.LevelLoader.java

License:Open Source License

/**
 * Contructor of the xml loader.//w  w  w  .  j  a  v  a  2  s  . co  m
 * Automatically load the file : level/newlevels.xml
 * 
 * @catch : ParseException
 * 
 *    public LevelLoader()
 */
public LevelLoader() {
    this.reader = new XmlReader();
    try {
        root = reader.parse(Gdx.files.internal("level/newlevels.xml"));
        GlobalSettings.NBLEVELS = root.getChildCount();
    } catch (IOException e) {
        e.printStackTrace();
    }
    timerListenerArray = new ArrayList<TimerListener>(2);

}

From source file:be.ac.ucl.lfsab1509.bouboule.game.MyGame.java

License:Open Source License

@Override
public void create() {
    // TODO Prod: LOG_ERROR
    Gdx.app.setLogLevel(Application.LOG_ERROR);

    Gdx.app.log("Matth", "Game: Create");
    hitSounds = new Sound[5];
    hitSounds[0] = Gdx.audio.newSound(Gdx.files.internal("music/sounds/hit1.mp3"));
    hitSounds[1] = Gdx.audio.newSound(Gdx.files.internal("music/sounds/hit2.mp3"));
    hitSounds[2] = Gdx.audio.newSound(Gdx.files.internal("music/sounds/hit3.mp3"));
    hitSounds[3] = Gdx.audio.newSound(Gdx.files.internal("music/sounds/hit4.mp3"));
    hitSounds[4] = Gdx.audio.newSound(Gdx.files.internal("music/sounds/hit5.mp3"));
    rand = new Random();

    countdownSound = Gdx.audio.newSound(Gdx.files.internal("music/sounds/countdown.mp3"));

    if (GlobalSettings.GAME == null) // should not happen on Android!!!
        init(true);// w w  w  .  j a  v  a2 s. c o  m

    if (bNeedEndSounds) {
        winSound = Gdx.audio.newSound(Gdx.files.internal("music/sounds/win.mp3"));
        looseSound = Gdx.audio.newSound(Gdx.files.internal("music/sounds/loose.mp3"));
    }

    camera = CameraHelper.getCamera(GlobalSettings.APPWIDTH, GlobalSettings.APPHEIGHT);

    if (GlobalSettings.MENUS == null) {
        bGdxMenus = true;
        GlobalSettings.MENUS = new GdxMenus();
        GlobalSettings.MENUS.launchInitMenu();
    } else // e.g. Android => there is only one screen: Screen Game
        setScreenGame();
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.MyGame.java

License:Open Source License

/**
 * @param cNewMusic should be a file that can be read by GDX
 * in 'assets/music/levels'//  w w w.  j  av a 2 s  .  c o  m
 */
public void setNewLoopMusic(final String cNewMusic) {
    Gdx.app.log("SCREEN", "New music: " + cNewMusic + " " + (screenGame == null));
    if (screenGame == null) { // not loaded yet.
        return;
    }
    if (cNewMusic != null) {
        FileHandle pMusicFile = Gdx.files.internal("music/levels/" + cNewMusic);
        if (pMusicFile.exists()) {
            screenGame.setNewLoopMusic(pMusicFile);
            return;
        }
    } // load the default one (if it's not currently playing)
    screenGame.setDefaultLoopMusicPath();
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.MyGame.java

License:Open Source License

/**
 * @return the music for the menu (create a new one if it doesn't exist)
 *//*from  w w w  .  java 2  s. co m*/
public Music getMenusMusic() {
    if (menusMusic == null) {
        menusMusic = Gdx.audio.newMusic(Gdx.files.internal("music/sounds/menu.mp3"));
        menusMusic.setLooping(true);
    }
    return menusMusic;
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.AbstractScreen.java

License:Open Source License

protected Skin getSkin() {
    if (skin == null) {
        FileHandle skinFile = Gdx.files.internal("skin/uiskin.json");
        skin = new Skin(skinFile);
    }//  w w w.j  ava  2 s.  c  o m
    return skin;
}