Advertisement
acegiak

render method

May 23rd, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. //this is a hack till we put level generator into an assetManager loader
  2. private void firstFrame(){
  3.  
  4. LG = new LevelGenerator(game, entities, this);
  5. hero = new Hero(game,rayHandler,"data/Entities/Gruddsheet.png",2,1,1, camera.viewportHeight / 2,1f,1f);
  6.  
  7. entities.add(this.hero);
  8. entities.add(new backgroundobject(game, "data/SCARYCASTLE.png",5f,0f,0f));
  9.  
  10.  
  11. LG.createNewLevel();
  12. entities.addAll(LG.levelPass);
  13.  
  14.  
  15. sun = new DirectionalLight(rayHandler, Gdx.graphics.getHeight(), new Color(1f,1f,1f,SUN_INTENSITY), -90f);
  16. firstframed = true;
  17. }
  18.  
  19.  
  20. @Override
  21. public void render(float delta) {
  22. if(endgame == true){
  23. EndGame();
  24. }
  25.  
  26. if(!firstframed){
  27. firstFrame();
  28. }
  29.  
  30.  
  31.  
  32. accumulator += delta;
  33. int ticks = 0;
  34. while(accumulator>1/TIMESTEP){
  35. ticks += 1;
  36. entities.addAll(spawnqueue);
  37. for(Entity e : deathrow){
  38. e.dispose();
  39. }
  40. entities.removeAll(deathrow);
  41. spawnqueue = new ArrayList<Entity>();
  42. deathrow = new ArrayList<Entity>();
  43.  
  44.  
  45.  
  46. if(LEVEL_MAINTENANCE_TICK == 0f ||(new Random()).nextFloat() < LEVEL_MAINTENANCE_TICK){
  47.  
  48. //Note: Using dst2 for calculating this distance causes the stasis field to be circular
  49. //which can cause some weird effects in our world of axis aligned bounding boxes
  50. //if you can be bothered, changing this to absolute distances on both axes would probably
  51. //reduce the occurrence of events like objects falling through each other at the edge of
  52. //the stasis field
  53. int killLimit = MAX_STASIS_SHIFTS_PER_TICK;
  54. Vector2 hPos = new Vector2(hero.bound.x,hero.bound.y);
  55. for(Entity e : entities){
  56. Vector2 ePos = new Vector2(e.bound.x,e.bound.y);
  57. if(e instanceof SpriteBody){
  58.  
  59. if(ePos.dst2(hPos)>STASIS_DISTANCE){
  60. if (((SpriteBody) e).body != null) {
  61. ((SpriteBody)e).storeBody();
  62. world.destroyBody(((SpriteBody)e).body);
  63. }else{
  64. @SuppressWarnings("unused")
  65. String alert = "wtf";
  66. }
  67. stasis.add(e);
  68. killLimit -=1;
  69. if(killLimit <= 0){
  70. break;
  71. }
  72. }
  73. }
  74.  
  75. }
  76. entities.removeAll(stasis);
  77. killLimit = MAX_STASIS_SHIFTS_PER_TICK;
  78. for(Entity e : stasis){
  79.  
  80. Vector2 ePos = new Vector2(e.bound.x,e.bound.y);
  81. if(e instanceof SpriteBody){
  82. if(ePos.dst2(hPos)<STASIS_DISTANCE){
  83. entities.add(e);
  84. if (e.destroyBody == false) {
  85. ((SpriteBody)e).loadBody(world);
  86. }
  87.  
  88. killLimit -=1;
  89. if(killLimit <= 0){
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. stasis.removeAll(entities);
  96. //END CLOSENESS
  97.  
  98.  
  99. Collections.sort(entities,new EntityZComparator());
  100.  
  101. System.out.println("FPS:"+1/delta);
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108. for(Entity e : entities){
  109. e.update(this, delta);
  110. }
  111.  
  112. sun.setPosition(hero.body.getPosition());
  113.  
  114.  
  115. world.step(1/TIMESTEP, 6, 2);
  116. if(startgame){
  117. accumulator -= 1/TIMESTEP;
  118. }else{
  119. accumulator = 0f;
  120. }
  121.  
  122.  
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. camera.position.set(camPos.x,camPos.y,0f);
  133. camera.update();
  134.  
  135. batch.setProjectionMatrix(camera.combined);
  136.  
  137. rayHandler.setCombinedMatrix(camera.combined);
  138. Gdx.gl.glClearColor(0.12156f,0.23529f,0.44140f,1);
  139. Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  140.  
  141.  
  142.  
  143.  
  144. batch.begin();
  145. for(Entity e : entities){
  146. e.draw(batch);
  147. }
  148.  
  149.  
  150. batch.end();
  151.  
  152.  
  153. m_fbo = new FrameBuffer(Format.Alpha, (int)((width)*CAMERA_SCALE*SHADOW_RESOLUTION), (int)((height)*CAMERA_SCALE*SHADOW_RESOLUTION), true);
  154. m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
  155. m_fboRegion.flip(false, true);
  156.  
  157.  
  158. m_fbo.begin();
  159.  
  160. batch.begin();
  161. for(Entity e : entities){
  162. if(!(e instanceof backgroundobject)){
  163. e.draw(batch);
  164. }
  165. }
  166. batch.end();
  167. m_fbo.end();
  168.  
  169.  
  170. rayHandler.mask = m_fboRegion.getTexture();
  171. rayHandler.updateAndRender();
  172. renderer.render(world, camera.combined);
  173. startgame = true;
  174.  
  175.  
  176.  
  177.  
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement