SHARE
TWEET
Untitled
a guest
Nov 4th, 2016
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public void render(float delta) {
- /*
- clock += Gdx.graphics.getDeltaTime();
- while (clock >= 1/60f) {
- clock -= 1/60f;
- } */ //For setting a constant framerate
- count += Gdx.graphics.getDeltaTime();
- frames++;
- if(count >= 1)
- {
- System.out.println(frames + " frames per second");
- count = 0;
- frames = 0;
- }
- Matrix4 debugMatrix = batch.getProjectionMatrix().cpy();
- Gdx.gl20.glClearColor(0, 0, 0, 1);
- Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
- Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
- Gdx.gl20.glDepthFunc(GL20.GL_ALWAYS);
- Gdx.gl20.glDepthMask(true);
- if(Gdx.input.isKeyPressed(Keys.E))
- {
- Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
- MapManager.camera.unproject(vec);
- SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.ENEMY, .4f);
- }
- if(Gdx.input.isKeyPressed(Keys.A))
- {
- Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
- MapManager.camera.unproject(vec);
- SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.ALLY, .4f);
- }
- if(Gdx.input.isKeyPressed(Keys.N))
- {
- Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
- MapManager.camera.unproject(vec);
- SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.NEUTRAL, .4f);
- }
- if(Gdx.input.isKeyPressed(Keys.P))
- {
- Vector3 vec = new Vector3(Gdx.input.getX(),Gdx.input.getY(),0); //INPUT.GET IS SUPPOSED TO BE FOR TOUCH BUT WORKS FOR RAW VALUES
- MapManager.camera.unproject(vec);
- SpawnGenerator.spawnAI(world, engine, "Enemy", vec.x + Utils.randomFloat(-2, 2), vec.y + Utils.randomFloat(-2, 2), Hostility.PROVOKEABLE, .4f);
- }
- if(Gdx.input.isKeyJustPressed(Keys.C))
- {
- EntityManager.addHostility(Hostility.PROVOKEABLE, Hostility.NEUTRAL);
- }
- if(Gdx.input.isKeyJustPressed(Keys.K))
- {
- EntityManager.killAllEntities();
- }
- world.step(Gdx.graphics.getDeltaTime(), 6, 2);
- playerLight.setPosition(positionMap.get(EntityManager.getPlayer()).x
- + spriteMap.get(EntityManager.getPlayer()).width / 2f,
- positionMap.get(EntityManager.getPlayer()).y);
- rayHandler.update();
- camera.position.x = Math.min(Math.max(positionMap.get(EntityManager.getPlayer()).x, VIRTUAL_WIDTH / 2), mapWidth - (VIRTUAL_WIDTH / 2));
- camera.position.y = Math.min(Math.max(positionMap.get(EntityManager.getPlayer()).y, VIRTUAL_HEIGHT / 2), mapHeight - (VIRTUAL_HEIGHT / 2));
- camera.update();
- renderer.setView(camera);
- // renderer.render(); //renders entire map
- renderer.getBatch().begin();
- renderer.renderTileLayer((TiledMapTileLayer) renderer.getMap().getLayers().get(0));
- renderer.renderTileLayer((TiledMapTileLayer) renderer.getMap().getLayers().get(1));
- renderer.getBatch().end();
- rayHandler.setCombinedMatrix(camera);
- rayHandler.render();
- zSort.sort();
- renderZSort(delta);
- if(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x), (int) (positionMap.get(EntityManager.getPlayer()).y)) != null)
- {
- if(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x), (int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().containsKey("changeMap"))
- {
- changeMap(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("changeMap", String.class),
- Integer.parseInt(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("takeXTo", String.class)),
- (Integer.parseInt(Collision.getCollisionLayerTop().getCell((int) (positionMap.get(EntityManager.getPlayer()).x),(int) (positionMap.get(EntityManager.getPlayer()).y)).getTile().getProperties().get("takeYTo", String.class))));
- }
- }
- b2dr.render(world, debugMatrix);
- }
- public void renderZSort(float delta)
- {
- batch.begin();
- entityManager.update();
- float extraRange = camera.zoom * 2;
- for(int i = 0; i < zSort.size; i ++)
- {
- if(zSort.get(i).getEntity() != null)
- {
- batch.draw(
- spriteMap.get(zSort.get(i).getEntity()).getCurrentFrame(),
- spriteMap.get(zSort.get(i).getEntity()).x,
- spriteMap.get(zSort.get(i).getEntity()).y,
- spriteMap.get(zSort.get(i).getEntity()).width,
- spriteMap.get(zSort.get(i).getEntity()).height);
- spriteMap.get(zSort.get(i).getEntity()).time += delta;
- if(spriteMap.get(zSort.get(i).getEntity()).time >= .05f)
- {
- spriteMap.get(zSort.get(i).getEntity()).frame ++;
- spriteMap.get(zSort.get(i).getEntity()).time = 0;
- }
- if(spriteMap.get(zSort.get(i).getEntity()).frame >= spriteMap.get(zSort.get(i).getEntity()).frontRun.size)
- {
- spriteMap.get(zSort.get(i).getEntity()).frame = 0;
- }
- }
- else if(zSort.get(i).topSprite != null)
- {
- batch.draw(zSort.get(i).topSprite,
- zSort.get(i).topSprite.getX(),
- zSort.get(i).topSprite.getY(),
- zSort.get(i).topSprite.getWidth(),
- zSort.get(i).topSprite.getHeight());
- }
- }
- batch.setProjectionMatrix(camera.combined);
- batch.end();
- }
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.

