Advertisement
SforzandoCF

ljgex

Oct 2nd, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package lx01.libraries.ljgex;
  2.  
  3. public final class Game {
  4.     public Game (Graphics out, Supplier<List<GameObject>> objectGetter, BooleanSupplier active) {
  5.         this(out, objectGetter, active, new Thread(() -> {
  6.             while (this.isRunning()) {
  7.                 try {
  8.                     Thread.sleep(50L);
  9.                 } catch (InterruptedException ie) {}
  10.                 this.executeFrame();
  11.             }
  12.         }));
  13.     }
  14.    
  15.     public Game (Graphics out, Supplier<List<GameObject>> objectGetter, BooleanSupplier active, Thread thread) {
  16.         this.graphics = out;
  17.         this.objects = objectGetter;
  18.         this.thread = thread;
  19.         this.isActive = active;
  20.     }
  21.    
  22.     public void init () {
  23.         this.thread.start();
  24.     }
  25.    
  26.     public boolean isRunning () {
  27.         return this.isActive.getAsBoolean();
  28.     }
  29.    
  30.     public void executeFrame () {
  31.         if (this.drawingFrame) return;
  32.         this.drawingFrame = true;
  33.         for (GameObject obj : this.objects.get())
  34.             this.graphics.drawImage(this.render(obj), obj.getX(), obj.getY(), this);
  35.         this.drawingFrame = false;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement