SHARE
TWEET

Untitled

a guest Nov 4th, 2016 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void render(float delta) {
  2.         /*
  3.         clock += Gdx.graphics.getDeltaTime();
  4.         while (clock >= 1/60f) {
  5.             clock -= 1/60f;
  6.         } */ //For setting a constant framerate
  7.  
  8.         count += Gdx.graphics.getDeltaTime();
  9.  
  10.         frames++;
  11.         if(count >= 1)
  12.         {
  13.             System.out.println(frames + " frames per second");
  14.             count = 0;
  15.             frames = 0;
  16.         }
  17.         Matrix4 debugMatrix = batch.getProjectionMatrix().cpy();
  18.  
  19.         Gdx.gl20.glClearColor(0, 0, 0, 1);
  20.         Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
  21.            
  22.         Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
  23.         Gdx.gl20.glDepthFunc(GL20.GL_ALWAYS);
  24.         Gdx.gl20.glDepthMask(true);
  25.        
  26.         if(Gdx.input.isKeyPressed(Keys.E))
  27.         {
  28.             Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
  29.             MapManager.camera.unproject(vec);
  30.             SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.ENEMY, .4f);
  31.         }
  32.         if(Gdx.input.isKeyPressed(Keys.A))
  33.         {
  34.             Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
  35.             MapManager.camera.unproject(vec);
  36.             SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.ALLY, .4f);
  37.         }
  38.         if(Gdx.input.isKeyPressed(Keys.N))
  39.         {
  40.             Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
  41.             MapManager.camera.unproject(vec);
  42.             SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.NEUTRAL, .4f);
  43.         }
  44.         if(Gdx.input.isKeyPressed(Keys.P))
  45.         {
  46.             Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
  47.             MapManager.camera.unproject(vec);
  48.             SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.PROVOKEABLE, .4f);
  49.         }
  50.         if(Gdx.input.isKeyJustPressed(Keys.C))
  51.         {
  52.             EntityManager.addHostility(Hostility.PROVOKEABLE, Hostility.NEUTRAL);
  53.         }
  54.         if(Gdx.input.isKeyJustPressed(Keys.K))
  55.         {
  56.             EntityManager.killAllEntities();
  57.         }
  58.        
  59.         world.step(Gdx.graphics.getDeltaTime(), 6, 2);
  60.         playerLight.setPosition(positionMap.get(EntityManager.getPlayer()).x
  61.                 + spriteMap.get(EntityManager.getPlayer()).width / 2f,
  62.                 positionMap.get(EntityManager.getPlayer()).y);
  63.         rayHandler.update();
  64.        
  65.         camera.position.x = Math.min(Math.max(positionMap.get(EntityManager.getPlayer()).x, VIRTUAL_WIDTH / 2), mapWidth - (VIRTUAL_WIDTH / 2));
  66.         camera.position.y = Math.min(Math.max(positionMap.get(EntityManager.getPlayer()).y, VIRTUAL_HEIGHT / 2), mapHeight - (VIRTUAL_HEIGHT / 2));
  67.         camera.update();
  68.         renderer.setView(camera);
  69.     //  renderer.render(); //renders entire map
  70.         renderer.getBatch().begin();
  71.         renderer.renderTileLayer((TiledMapTileLayer) renderer.getMap().getLayers().get(0));
  72.         renderer.renderTileLayer((TiledMapTileLayer) renderer.getMap().getLayers().get(1));
  73.         renderer.getBatch().end();
  74.  
  75.         rayHandler.setCombinedMatrix(camera);
  76.         rayHandler.render();
  77.         zSort.sort();
  78.         renderZSort(delta);    
  79.                
  80.         if(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x), (int) (positionMap.get(EntityManager.getPlayer()).y)) != null)
  81.         {
  82.             if(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x), (int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().containsKey("changeMap"))
  83.             {
  84.                 changeMap(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("changeMap", String.class),
  85.                         Integer.parseInt(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("takeXTo", String.class)),
  86.                         (Integer.parseInt(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("takeYTo", String.class))));
  87.             }
  88.         }
  89.         b2dr.render(world, debugMatrix);        
  90.     }
  91.    
  92.     public void renderZSort(float delta)
  93.     {
  94.         batch.begin();
  95.         entityManager.update();
  96.         float extraRange = camera.zoom * 2;
  97.         for(int i = 0; i < zSort.size; i ++)
  98.         {
  99.             if(zSort.get(i).getEntity() != null)
  100.             {
  101.                 batch.draw(
  102.                         spriteMap.get(zSort.get(i).getEntity()).getCurrentFrame(),
  103.                         spriteMap.get(zSort.get(i).getEntity()).x,
  104.                         spriteMap.get(zSort.get(i).getEntity()).y,
  105.                         spriteMap.get(zSort.get(i).getEntity()).width,
  106.                         spriteMap.get(zSort.get(i).getEntity()).height);
  107.                 spriteMap.get(zSort.get(i).getEntity()).time += delta;
  108.                 if(spriteMap.get(zSort.get(i).getEntity()).time >= .05f)
  109.                 {
  110.                     spriteMap.get(zSort.get(i).getEntity()).frame ++;
  111.                     spriteMap.get(zSort.get(i).getEntity()).time = 0;
  112.                 }
  113.                 if(spriteMap.get(zSort.get(i).getEntity()).frame >= spriteMap.get(zSort.get(i).getEntity()).frontRun.size)
  114.                 {
  115.                     spriteMap.get(zSort.get(i).getEntity()).frame = 0;
  116.                 }
  117.             }
  118.             else if(zSort.get(i).topSprite != null)
  119.             {
  120.                 batch.draw(zSort.get(i).topSprite,
  121.                         zSort.get(i).topSprite.getX(),
  122.                         zSort.get(i).topSprite.getY(),
  123.                         zSort.get(i).topSprite.getWidth(),
  124.                         zSort.get(i).topSprite.getHeight());
  125.             }
  126.         }
  127.         batch.setProjectionMatrix(camera.combined);
  128.         batch.end();
  129.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top