com.codefiddler.libgdx.spinit.Spinit.java Source code

Java tutorial

Introduction

Here is the source code for com.codefiddler.libgdx.spinit.Spinit.java

Source

/*
Copyright [2014] [James Thomas Hayes]
    
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.codefiddler.libgdx.spinit;

import java.util.Random;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.codefiddler.libgdx.spinit.assets.SoundEffects;
import com.codefiddler.libgdx.spinit.level.Level;
import com.codefiddler.libgdx.spinit.level.LevelFactory;

public class Spinit implements ApplicationListener {

    public static final Random RANDOM = new Random();

    private OrthographicCamera camera;
    private SpriteBatch batch;
    private Level level;

    private LevelFactory levelFactory;

    private SoundEffects soundEffects;

    @Override
    public void create() {
        float w = Gdx.graphics.getWidth();
        float h = Gdx.graphics.getHeight();
        camera = new OrthographicCamera(1, h / w);
        batch = new SpriteBatch();
        soundEffects = new SoundEffects();
        levelFactory = new LevelFactory(soundEffects);

        level = levelFactory.startLevel();

        soundEffects.playIntro();

    }

    @Override
    public void dispose() {
        batch.dispose();
        level.dispose();
        soundEffects.dispose();
    }

    @Override
    public void render() {
        if (level.isLevelEnded()) {
            level.resetLevel();
            level = levelFactory.nextLevel(level);
        }

        if (Gdx.input.isTouched()) {
            level.pushingBottleSignal();

        } else {
            level.notPushingBottleSignal();
        }

        Gdx.gl.glClearColor(0.1f, 0.4f, 0.7f, 0.5f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        level.draw(batch);
        batch.end();

    }

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

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }
}