Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is a hack till we put level generator into an assetManager loader
- private void firstFrame(){
- LG = new LevelGenerator(game, entities, this);
- hero = new Hero(game,rayHandler,"data/Entities/Gruddsheet.png",2,1,1, camera.viewportHeight / 2,1f,1f);
- entities.add(this.hero);
- entities.add(new backgroundobject(game, "data/SCARYCASTLE.png",5f,0f,0f));
- LG.createNewLevel();
- entities.addAll(LG.levelPass);
- sun = new DirectionalLight(rayHandler, Gdx.graphics.getHeight(), new Color(1f,1f,1f,SUN_INTENSITY), -90f);
- firstframed = true;
- }
- @Override
- public void render(float delta) {
- if(endgame == true){
- EndGame();
- }
- if(!firstframed){
- firstFrame();
- }
- accumulator += delta;
- int ticks = 0;
- while(accumulator>1/TIMESTEP){
- ticks += 1;
- entities.addAll(spawnqueue);
- for(Entity e : deathrow){
- e.dispose();
- }
- entities.removeAll(deathrow);
- spawnqueue = new ArrayList<Entity>();
- deathrow = new ArrayList<Entity>();
- if(LEVEL_MAINTENANCE_TICK == 0f ||(new Random()).nextFloat() < LEVEL_MAINTENANCE_TICK){
- //Note: Using dst2 for calculating this distance causes the stasis field to be circular
- //which can cause some weird effects in our world of axis aligned bounding boxes
- //if you can be bothered, changing this to absolute distances on both axes would probably
- //reduce the occurrence of events like objects falling through each other at the edge of
- //the stasis field
- int killLimit = MAX_STASIS_SHIFTS_PER_TICK;
- Vector2 hPos = new Vector2(hero.bound.x,hero.bound.y);
- for(Entity e : entities){
- Vector2 ePos = new Vector2(e.bound.x,e.bound.y);
- if(e instanceof SpriteBody){
- if(ePos.dst2(hPos)>STASIS_DISTANCE){
- if (((SpriteBody) e).body != null) {
- ((SpriteBody)e).storeBody();
- world.destroyBody(((SpriteBody)e).body);
- }else{
- @SuppressWarnings("unused")
- String alert = "wtf";
- }
- stasis.add(e);
- killLimit -=1;
- if(killLimit <= 0){
- break;
- }
- }
- }
- }
- entities.removeAll(stasis);
- killLimit = MAX_STASIS_SHIFTS_PER_TICK;
- for(Entity e : stasis){
- Vector2 ePos = new Vector2(e.bound.x,e.bound.y);
- if(e instanceof SpriteBody){
- if(ePos.dst2(hPos)<STASIS_DISTANCE){
- entities.add(e);
- if (e.destroyBody == false) {
- ((SpriteBody)e).loadBody(world);
- }
- killLimit -=1;
- if(killLimit <= 0){
- break;
- }
- }
- }
- }
- stasis.removeAll(entities);
- //END CLOSENESS
- Collections.sort(entities,new EntityZComparator());
- System.out.println("FPS:"+1/delta);
- }
- for(Entity e : entities){
- e.update(this, delta);
- }
- sun.setPosition(hero.body.getPosition());
- world.step(1/TIMESTEP, 6, 2);
- if(startgame){
- accumulator -= 1/TIMESTEP;
- }else{
- accumulator = 0f;
- }
- }
- camera.position.set(camPos.x,camPos.y,0f);
- camera.update();
- batch.setProjectionMatrix(camera.combined);
- rayHandler.setCombinedMatrix(camera.combined);
- Gdx.gl.glClearColor(0.12156f,0.23529f,0.44140f,1);
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- batch.begin();
- for(Entity e : entities){
- e.draw(batch);
- }
- batch.end();
- m_fbo = new FrameBuffer(Format.Alpha, (int)((width)*CAMERA_SCALE*SHADOW_RESOLUTION), (int)((height)*CAMERA_SCALE*SHADOW_RESOLUTION), true);
- m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
- m_fboRegion.flip(false, true);
- m_fbo.begin();
- batch.begin();
- for(Entity e : entities){
- if(!(e instanceof backgroundobject)){
- e.draw(batch);
- }
- }
- batch.end();
- m_fbo.end();
- rayHandler.mask = m_fboRegion.getTexture();
- rayHandler.updateAndRender();
- renderer.render(world, camera.combined);
- startgame = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement