se.theodor.quiz.Quiz.java Source code

Java tutorial

Introduction

Here is the source code for se.theodor.quiz.Quiz.java

Source

/********************************************************************************
 * 
 *   Copyright 2014 Theodor Angergard
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *******************************************************************************/

package se.theodor.quiz;

import java.lang.reflect.Field;
import java.nio.charset.Charset;

import se.theodor.quiz.screen.SplashScreen;
import se.theodor.quiz.tween.AlphaTween;
import se.theodor.quiz.tween.FloatTween;
import se.theodor.quiz.tween.VectorTween;
import se.theodor.quiz.util.Objects;
import aurelienribon.tweenengine.Tween;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;

public class Quiz extends Game {

    @Override
    public void create() {
        Tween.registerAccessor(Sprite.class, new AlphaTween());
        Tween.registerAccessor(Vector2.class, new VectorTween());
        Tween.registerAccessor(FloatValue.class, new FloatTween());

        System.setProperty("file.encoding", "UTF-8");
        Field charset;
        try {
            charset = Charset.class.getDeclaredField("defaultCharset");
            charset.setAccessible(true);
            charset.set(null, null);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        Gdx.gl.glClearColor(43f / 255f, 65f / 255f, 129f / 255f, 1);

        setScreen(new SplashScreen(this));

    }

    @Override
    public void dispose() {
        super.dispose();
    }

    @Override
    public void render() {
        if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
            Gdx.app.exit();
        } else if (Gdx.input.isKeyJustPressed(Keys.BACK)) {
            //TODO: GO BACK A SCREEN
        }

        Objects.CAMERA.update();
        Objects.STAGE.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Objects.BATCH.setProjectionMatrix(Objects.CAMERA.combined);

        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        super.render();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void resume() {
        super.resume();
    }

    public static float getWidth() {
        return Objects.CAMERA.viewportWidth;
    }

    public static float getHeight() {
        return Objects.CAMERA.viewportHeight;
    }

}