com.redthirddivision.astilade.screens.GameScreen.java Source code

Java tutorial

Introduction

Here is the source code for com.redthirddivision.astilade.screens.GameScreen.java

Source

/*   Copyright 2014 Matthew Rogers "BossLetsPlays"
*
*   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 com.redthirddivision.astilade.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.Vector2;
import com.redthirddivision.astilade.Astilade;
import com.redthirddivision.astilade.entities.mobs.DarkMage;
import com.redthirddivision.astilade.entities.mobs.Enemy;
import com.redthirddivision.astilade.entities.mobs.Player;
import com.redthirddivision.astilade.physics.PhysicsWorld;
import com.redthirddivision.astilade.utils.LogHelper;
import com.redthirddivision.astilade.world.World;

/**
 * <strong>Project:</strong> Kingdom of Astilade-core <br>
 * <strong>File:</strong> GameScreen.java
 *
 * @author <a href = "http://redthirddivision.com/team/BossLetsPlays"> Matthew Rogers</a>
 */
public class GameScreen extends BaseScreen {

    private boolean newGame;
    private World world;
    private PhysicsWorld physWorld;
    private Player player;
    private int lastFindX = -1;
    private int lastFindY = -1;

    public GameScreen(boolean newGame) {
        this.newGame = newGame;
    }

    @Override
    public void render(float delta) {
        super.render(delta);
        world.update();
        world.render();
        physWorld.update();
        physWorld.render();
    }

    @Override
    public void show() {
        super.show();
        world = new World(100, 64);
        Preferences prefs = Gdx.app.getPreferences(Astilade.TITLE);

        physWorld = new PhysicsWorld(new Vector2(0, 0), true);

        boolean exists = prefs.contains("playerX");
        if (exists && !newGame) {
            player = world.loadPlayer();
        } else {
            LogHelper.info("Creating new player save data");
            player = new Player(world, new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2));
            Player.savePlayer(player);
        }

        Enemy en = new DarkMage(world, new Vector2(600, 600));
        Enemy en1 = new DarkMage(world, new Vector2(100, 200));

    }

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

    @Override
    public void hide() {
        dispose();
    }

    @Override
    public String getName() {
        return "GameScreen";
    }

}