Game.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package me.hammerle.snuviengine.game;
  2. import java.util.LinkedList;
  3. import java.util.List;
  4. import java.util.Random;
  5. import me.hammerle.snuviengine.api.Engine;
  6. import me.hammerle.snuviengine.api.KeyBinding;
  7. import me.hammerle.snuviengine.api.KeyHandler;
  8. import me.hammerle.snuviengine.api.Shader;
  9. import me.hammerle.snuviengine.api.Texture;
  10. import me.hammerle.snuviengine.api.TextureRenderer;
  11. import me.hammerle.snuviengine.util.Clock;
  12. import static org.lwjgl.glfw.GLFW.*;
  13. public class Game extends Engine
  14. {
  15. public final static KeyBinding UP = KeyHandler.register(GLFW_KEY_UP);
  16. public final static KeyBinding DOWN = KeyHandler.register(GLFW_KEY_DOWN);
  17. public final static KeyBinding LEFT = KeyHandler.register(GLFW_KEY_LEFT);
  18. public final static KeyBinding RIGHT = KeyHandler.register(GLFW_KEY_RIGHT);
  19. private final TextureRenderer tr = new TextureRenderer();
  20. private final Texture t = new Texture("images/out3.png");
  21. public BoxList entities = new BoxList(0.0, 0.0, 400.0, 300.0, 1.0);
  22. private final List<Entity> list = new LinkedList<>();
  23. public Game()
  24. {
  25. Random r = new Random(100);
  26. for(int i = 0; i < 4096; i++)
  27. {
  28. Entity ent = new Entity(this, 1.0, 1.0);
  29. ent.setPosition((int) (r.nextDouble() * 400.0), (int) (r.nextDouble() * 300));
  30. ent.node = entities.add(ent);
  31. list.add(ent);
  32. }
  33. Hero hero = new Hero(this, 1.0, 1.0);
  34. hero.setPosition(300.0, 200);
  35. hero.node = entities.add(hero);
  36. list.add(hero);
  37. }
  38. @Override
  39. public void init()
  40. {
  41. setNanosPerTick(10_000_000);
  42. }
  43. @Override
  44. public void tick()
  45. {
  46. CLOCK.start();
  47. list.forEach(ent -> ent.tick());
  48. CLOCK.stop();
  49. //CLOCK.printTime(entities.amount + " Time: ");
  50. /*if(!list.isEmpty())
  51. {
  52. Entity ent = list.remove(c);
  53. entities.remove(ent.node);
  54. }
  55. if(!list.isEmpty())
  56. {
  57. Entity ent = list.remove(c);
  58. entities.remove(ent.node);
  59. }
  60. if(!list.isEmpty())
  61. {
  62. Entity ent = list.remove(c);
  63. entities.remove(ent.node);
  64. }*/
  65. }
  66. private static final Clock CLOCK = new Clock(250);
  67. @Override
  68. public void renderTick(double lag)
  69. {
  70. Shader.setTextureEnabled(false);
  71. Shader.setColorEnabled(true);
  72. list.forEach(ent -> ent.renderTick(lag));
  73. Shader.setTextureEnabled(true);
  74. Shader.setColorEnabled(true);
  75. Shader.getFontRenderer().drawString(5, 5, true, "FPS " + String.format("%.1f", getFps()));
  76. Shader.getFontRenderer().drawString(5, 14, true, "TPS " + String.format("%.1f", getTps()));
  77. //Shader.getColorRenderer().drawRectangle(0.0f, 0.0f, 100.0f, 100.0f, 0xFF0000FF);
  78. /*for(int i = 0; i < 400; i++)
  79. {
  80. Shader.getColorRenderer().drawRectangle(0.0f, i * 2.0f, 20.0f, i * 2.0f + 1, 0xFFFFFFFF);
  81. }*/
  82. //hader.setDepthTestUsing(false);
  83. /*Shader.setBlendingEnabled(false);
  84. Shader.setTextureEnabled(true);
  85. Shader.setColorEnabled(true);
  86. for(int i = 0; i < 20; i++)
  87. {
  88. Shader.getFontRenderer().drawString(0, i * 9, true, "Das ist ein Test.");
  89. }*/
  90. }
  91. }