package nl.joozey.games.asmallworld;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class ASmallWorld extends ApplicationAdapter {

    private SpriteBatch batch;
    private SceneControl sceneControl;

    @Override
    public void create() {
        batch = new SpriteBatch();
        sceneControl = new SceneControl();
    }

    @Override
    public void render() {
        Scene scene = sceneControl.getCurrentScene();
        if (scene != null) {
            scene.act(Gdx.graphics.getDeltaTime());

            Camera camera = sceneControl.getCamera();
            camera.update();
            batch.setProjectionMatrix(camera.combined);

            Gdx.gl.glClearColor(0, 0, 0, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            batch.begin();
            scene.render(batch);
            batch.end();
        }
    }

    @Override
    public void dispose() {
        batch.dispose();
        sceneControl.disposeAll();
    }
}
