88 lines
2.5 KiB
Java
Executable File
88 lines
2.5 KiB
Java
Executable File
package com.darkrp2d;
|
|
|
|
import com.badlogic.ashley.core.Engine;
|
|
import com.badlogic.gdx.Game;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
import com.badlogic.gdx.utils.TimeUtils;
|
|
import com.darkrp2d.input.CommandStream;
|
|
import com.darkrp2d.input.InputHandler;
|
|
import com.darkrp2d.input.commands.Command;
|
|
|
|
|
|
public class DarkRP2D extends Game {
|
|
|
|
public BitmapFont font;
|
|
public SpriteBatch batch;
|
|
private Engine engine;
|
|
|
|
@Override
|
|
public void create () {
|
|
font = new BitmapFont();
|
|
batch = new SpriteBatch();
|
|
engine = new Engine();
|
|
//Sets inputs
|
|
Gdx.input.setInputProcessor(new InputHandler(this));
|
|
}
|
|
|
|
private double lag = 0.;
|
|
private static final double MS_PER_UPDATE = 16.66;
|
|
|
|
private int ups = 0;
|
|
private double timer = 0.;
|
|
|
|
@Override
|
|
// GameLoop
|
|
public void render () {
|
|
lag += Gdx.graphics.getDeltaTime() * 1e3; //Seconds to milliseconds
|
|
timer += Gdx.graphics.getDeltaTime();
|
|
|
|
//Process Input
|
|
Command currentCommand = CommandStream.pollCommand();
|
|
if(currentCommand != null) {
|
|
currentCommand.execute();
|
|
}
|
|
|
|
//Update Stuff
|
|
while(lag >= MS_PER_UPDATE) {
|
|
update();
|
|
ups++;
|
|
lag -= MS_PER_UPDATE;
|
|
}
|
|
|
|
if(timer >= 1) {
|
|
System.out.println(ups);
|
|
ups = 0;
|
|
timer = 0.;
|
|
}
|
|
|
|
trueRender();
|
|
}
|
|
|
|
public void update() {
|
|
|
|
}
|
|
|
|
public void trueRender() {
|
|
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
|
|
//Render current Screen
|
|
super.render();
|
|
|
|
batch.begin();
|
|
GlyphLayout layout = new GlyphLayout(font, "Hello World");
|
|
font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2);
|
|
batch.end();
|
|
}
|
|
|
|
@Override
|
|
public void dispose () {
|
|
}
|
|
|
|
|
|
}
|