package me.hammerle.snuviengine.game; import java.util.LinkedList; import java.util.List; import java.util.Random; import me.hammerle.snuviengine.api.Engine; import me.hammerle.snuviengine.api.KeyBinding; import me.hammerle.snuviengine.api.KeyHandler; import me.hammerle.snuviengine.api.Shader; import me.hammerle.snuviengine.api.Texture; import me.hammerle.snuviengine.api.TextureRenderer; import me.hammerle.snuviengine.util.Clock; import static org.lwjgl.glfw.GLFW.*; public class Game extends Engine { public final static KeyBinding UP = KeyHandler.register(GLFW_KEY_UP); public final static KeyBinding DOWN = KeyHandler.register(GLFW_KEY_DOWN); public final static KeyBinding LEFT = KeyHandler.register(GLFW_KEY_LEFT); public final static KeyBinding RIGHT = KeyHandler.register(GLFW_KEY_RIGHT); private final TextureRenderer tr = new TextureRenderer(); private final Texture t = new Texture("images/out3.png"); public BoxList entities = new BoxList(0.0, 0.0, 400.0, 300.0, 1.0); private final List list = new LinkedList<>(); public Game() { Random r = new Random(100); for(int i = 0; i < 4096; i++) { Entity ent = new Entity(this, 1.0, 1.0); ent.setPosition((int) (r.nextDouble() * 400.0), (int) (r.nextDouble() * 300)); ent.node = entities.add(ent); list.add(ent); } Hero hero = new Hero(this, 1.0, 1.0); hero.setPosition(300.0, 200); hero.node = entities.add(hero); list.add(hero); } @Override public void init() { setNanosPerTick(10_000_000); } @Override public void tick() { CLOCK.start(); list.forEach(ent -> ent.tick()); CLOCK.stop(); //CLOCK.printTime(entities.amount + " Time: "); /*if(!list.isEmpty()) { Entity ent = list.remove(c); entities.remove(ent.node); } if(!list.isEmpty()) { Entity ent = list.remove(c); entities.remove(ent.node); } if(!list.isEmpty()) { Entity ent = list.remove(c); entities.remove(ent.node); }*/ } private static final Clock CLOCK = new Clock(250); @Override public void renderTick(double lag) { Shader.setTextureEnabled(false); Shader.setColorEnabled(true); list.forEach(ent -> ent.renderTick(lag)); Shader.setTextureEnabled(true); Shader.setColorEnabled(true); Shader.getFontRenderer().drawString(5, 5, true, "FPS " + String.format("%.1f", getFps())); Shader.getFontRenderer().drawString(5, 14, true, "TPS " + String.format("%.1f", getTps())); //Shader.getColorRenderer().drawRectangle(0.0f, 0.0f, 100.0f, 100.0f, 0xFF0000FF); /*for(int i = 0; i < 400; i++) { Shader.getColorRenderer().drawRectangle(0.0f, i * 2.0f, 20.0f, i * 2.0f + 1, 0xFFFFFFFF); }*/ //hader.setDepthTestUsing(false); /*Shader.setBlendingEnabled(false); Shader.setTextureEnabled(true); Shader.setColorEnabled(true); for(int i = 0; i < 20; i++) { Shader.getFontRenderer().drawString(0, i * 9, true, "Das ist ein Test."); }*/ } }