Change project structure & added GameManager

This commit is contained in:
Sebastian Cabrera 2019-08-28 23:07:02 -04:00
parent fd22091920
commit ece217c7f6
15 changed files with 52 additions and 21 deletions

4
.vscode/launch.json vendored
View file

@ -12,9 +12,9 @@
}, },
{ {
"type": "java", "type": "java",
"name": "Debug (Launch)-Init<pixels>", "name": "Debug (Launch)-GameManager<pixels>",
"request": "launch", "request": "launch",
"mainClass": "bz.bronze.pixels.Init", "mainClass": "bz.bronze.pixels.game.GameManager",
"projectName": "pixels" "projectName": "pixels"
} }
] ]

Binary file not shown.

View file

@ -1,4 +1,4 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
public abstract class AbstractGame { public abstract class AbstractGame {
public abstract void update(float dt); public abstract void update(float dt);

View file

@ -1,11 +1,10 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
import java.awt.event.KeyEvent; public class GameContainer implements Runnable {
public class Gameloop implements Runnable {
private Thread thread; private Thread thread;
private Window window;
private Renderer renderer; private Renderer renderer;
private Input input; public Input input;
private AbstractGame game; private AbstractGame game;
private boolean running = false; private boolean running = false;
@ -13,11 +12,12 @@ public class Gameloop implements Runnable {
private String metrics; private String metrics;
public Gameloop(AbstractGame game) { public GameContainer(AbstractGame game) {
this.game = game; this.game = game;
} }
public void start() { public void start() {
window = new Window();
renderer = new Renderer(); renderer = new Renderer();
input = new Input(); input = new Input();

View file

@ -1,9 +1,8 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
public class Init { public class Init {
static Window window = new Window(); static Window window = new Window();
static Gameloop game = new Gameloop(); //static Gameloop game = new Gameloop();
public static void print(String out) { public static void print(String out) {
System.out.println(out); System.out.println(out);
@ -11,13 +10,13 @@ public class Init {
public static void init() { public static void init() {
window.create(); window.create();
game.start(); //game.start();
print("Window Initialized!"); print("Window Initialized!");
print("Gameloop Started!"); print("Gameloop Started!");
} }
public static void main(String[] args) throws Exception { //public static void main(String[] args) throws Exception {
init(); //init();
} //}
} }

View file

@ -1,4 +1,4 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;

View file

@ -1,4 +1,4 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
import java.awt.image.DataBufferInt; import java.awt.image.DataBufferInt;

View file

@ -1,4 +1,4 @@
package bz.bronze.pixels; package bz.bronze.pixels.engine;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Canvas; import java.awt.Canvas;

View file

@ -0,0 +1,32 @@
package bz.bronze.pixels.game;
import java.awt.event.KeyEvent;
import bz.bronze.pixels.engine.AbstractGame;
import bz.bronze.pixels.engine.GameContainer;
import bz.bronze.pixels.engine.Renderer;
public class GameManager extends AbstractGame {
static GameContainer gc;
public GameManager() {
}
@Override
public void update(float dt) {
if (gc.input.isKey(KeyEvent.VK_SPACE)) {
System.out.println("pop goes the weasel");
}
}
@Override
public void render(Renderer r) {
}
public static void main(String[] args) {
gc = new GameContainer(new GameManager());
gc.start();
}
}