Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lx01.libraries.ljgex;
- public final class Game {
- public Game (Graphics out, Supplier<List<GameObject>> objectGetter, BooleanSupplier active) {
- this(out, objectGetter, active, new Thread(() -> {
- while (this.isRunning()) {
- try {
- Thread.sleep(50L);
- } catch (InterruptedException ie) {}
- this.executeFrame();
- }
- }));
- }
- public Game (Graphics out, Supplier<List<GameObject>> objectGetter, BooleanSupplier active, Thread thread) {
- this.graphics = out;
- this.objects = objectGetter;
- this.thread = thread;
- this.isActive = active;
- }
- public void init () {
- this.thread.start();
- }
- public boolean isRunning () {
- return this.isActive.getAsBoolean();
- }
- public void executeFrame () {
- if (this.drawingFrame) return;
- this.drawingFrame = true;
- for (GameObject obj : this.objects.get())
- this.graphics.drawImage(this.render(obj), obj.getX(), obj.getY(), this);
- this.drawingFrame = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement