93 lines
2.0 KiB
Java
93 lines
2.0 KiB
Java
package com.me.pacman;
|
|
|
|
import com.badlogic.gdx.Game;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.Screen;
|
|
import com.badlogic.gdx.graphics.Camera;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
|
import com.me.pacman.state.MenuState;
|
|
import com.me.pacman.state.State;
|
|
|
|
public class PacDude extends Game {
|
|
|
|
public Camera cam;
|
|
public Viewport viewport;
|
|
|
|
public Assets assets;
|
|
public Sound sound;
|
|
|
|
public SpriteBatch batch;
|
|
public FontRenderer fontRenderer;
|
|
|
|
public HighScores highScores;
|
|
|
|
private State nextState;
|
|
|
|
@Override
|
|
public void create () {
|
|
cam = new OrthographicCamera();
|
|
viewport = new FitViewport(Constants.GAME_WIDTH, Constants.GAME_HEIGHT, cam);
|
|
viewport.apply(true);
|
|
|
|
assets = new Assets();
|
|
assets.loadAssets();
|
|
sound = new Sound(this);
|
|
|
|
batch = new SpriteBatch();
|
|
fontRenderer = new FontRenderer(assets.font);
|
|
|
|
highScores = new HighScores();
|
|
|
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
|
setNextState(new MenuState(this));
|
|
}
|
|
|
|
@Override
|
|
public void render () {
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
if (nextState != null) {
|
|
Screen currScreen = getScreen();
|
|
if (currScreen != null) currScreen.dispose();
|
|
nextState.setup();
|
|
super.setScreen(nextState);
|
|
nextState = null;
|
|
}
|
|
|
|
batch.begin();
|
|
if (Constants.DEBUG) {
|
|
fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE);
|
|
}
|
|
super.render();
|
|
batch.end();
|
|
}
|
|
|
|
@Override
|
|
public void resize(int width, int height) {
|
|
viewport.update(width, height);
|
|
|
|
batch.setProjectionMatrix(cam.combined);
|
|
|
|
super.resize(width, height);
|
|
}
|
|
|
|
@Override
|
|
public void dispose () {
|
|
batch.dispose();
|
|
assets.dispose();
|
|
}
|
|
|
|
@Override
|
|
public void setScreen(Screen screen) {
|
|
throw new IllegalStateException("Use setNextState instead.");
|
|
}
|
|
|
|
public void setNextState(State state) {
|
|
this.nextState = state;
|
|
}
|
|
|
|
}
|