misc changes (abstract game)

This commit is contained in:
Sebastian Cabrera 2019-08-28 19:23:27 -04:00
parent ffd9ed775c
commit fd22091920
8 changed files with 18 additions and 2 deletions

View file

@ -1,3 +1,5 @@
# pixels # pixels
x, y - 2D Game engine in the works... x, y - 2D Game engine in the works...
idk why i use java for everything...

Binary file not shown.

View file

@ -0,0 +1,6 @@
package bz.bronze.pixels;
public abstract class AbstractGame {
public abstract void update(float dt);
public abstract void render(Renderer r);
}

View file

@ -6,12 +6,17 @@ public class Gameloop implements Runnable {
private Thread thread; private Thread thread;
private Renderer renderer; private Renderer renderer;
private Input input; private Input input;
private AbstractGame game;
private boolean running = false; private boolean running = false;
private final double TPS = 1.0/60.0; private final double TPS = 1.0/60.0;
private String metrics; private String metrics;
public Gameloop(AbstractGame game) {
this.game = game;
}
public void start() { public void start() {
renderer = new Renderer(); renderer = new Renderer();
input = new Input(); input = new Input();
@ -53,6 +58,8 @@ public class Gameloop implements Runnable {
render = true; render = true;
//TODO: Gameloop //TODO: Gameloop
game.update((float)TPS);
metrics = "TPS: " + tps + " | " + "Mouse X: " + input.mouseX + " | " + "Mouse Y: " + input.mouseY + " | " + "Scroll: " + input.scroll; metrics = "TPS: " + tps + " | " + "Mouse X: " + input.mouseX + " | " + "Mouse Y: " + input.mouseY + " | " + "Scroll: " + input.scroll;
Window.window.setTitle(Window.title + " | " + metrics); Window.window.setTitle(Window.title + " | " + metrics);
@ -68,6 +75,7 @@ public class Gameloop implements Runnable {
if (render) { if (render) {
renderer.test(); renderer.test();
//renderer.clear(); //renderer.clear();
game.render(renderer);
Window.update(); Window.update();
ticks++; ticks++;

View file

@ -15,7 +15,7 @@ public class Window {
static int width = 800; static int width = 800;
static int height = 600; static int height = 600;
static int scale = 1; static int scale = 1;
static String title = "pixels | v0.02"; static String title = "pixels | v0.03";
static BufferedImage pixels = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); static BufferedImage pixels = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
static Canvas viewport = new Canvas(); static Canvas viewport = new Canvas();