@Override public void render() { delta = Gdx.graphics.getDeltaTime() * 60; Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); player.update(delta); if (player.atLimit()) backgroundPos -= 20 * delta; else backgroundPos -= 10 * delta; if (backgroundPos <= -background.getHeight()) backgroundPos = 0; spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.begin(); spriteBatch.draw(background, -1080 / 2, +background.getHeight() / 2 + backgroundPos); spriteBatch.draw(background, -1080 / 2, -background.getHeight() / 2 + backgroundPos); player.draw(spriteBatch); enemies.update(spriteBatch, delta); tweenManager.update(delta / 60); spriteBatch.end(); rayHandler.setCombinedMatrix(camera.combined); rayHandler.updateAndRender(); controls.handleInput(camera); }
public void dispose() { m_BorderTexture.dispose(); m_BackgroundMusic.stop(); m_BackgroundMusic.dispose(); m_RayHandler.dispose(); m_PhysicsWorld.dispose(); }
@Override public void create() { tweenManager = new TweenManager(); Tween.registerAccessor(Sprite.class, new SpriteAccessor()); // Box2d world = new World(new Vector2(0, 0), true); // No gravity, space dah. world.step(1 / 60f, 6, 2); rayHandler = new RayHandler(world); rayHandler.setAmbientLight(0, 0, 0, 1f); // rayHandler.setAmbientLight(1f, 1f, 1f, 1f); rayHandler.setCulling(true); rayHandler.setBlur(true); rayHandler.setBlurNum(3); rayHandler.setShadows(true); RayHandler.isDiffuse = true; RayHandler.setGammaCorrection(true); controls = new GameControls(this); Gdx.input.setCursorCatched(true); camera = new OrthographicCamera(1080, 1920); spriteBatch = new SpriteBatch(); player = new PlayerShip(rayHandler, tweenManager); background = new Texture("backgroundbw.png"); enemies = new EnemyHandler(rayHandler, tweenManager); }
public void render() { Gdx.gl.glClearColor(.2f, .2f, .2f, 1); // 0->1 = 0->255 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); rayHandler.updateAndRender(); if (this.started) { float deltaTime = Gdx.app.getGraphics().getDeltaTime(); if (deltaTime > .1f) deltaTime = .1f; world.step(deltaTime, 10, 10); // Increase the score score.addValue((int) this.joe.getSpeed() * 10 * Gdx.app.getGraphics().getDeltaTime()); joe.render(); if (joe.isOutOfScreen()) { this.Pause(); RunningJoe.getInstance().setScreen(new GameOverScreen()); } this.camera.translate(RunningJoe.PixToMeter(this.joe.getSpeed()), 0); } camera.update(); if (RunningJoe.DEV_MODE) RunningJoe.debugRenderer.render(world, camera.combined); // Draw bodies textures spriteBatch.begin(); for (Background bg : this.vecBg) { bg.DrawTexture(spriteBatch); } // Draw Joe in the World joe.draw(spriteBatch); // Generate ground and draw it in the World this.listBlock.render(); this.listBlock.draw(spriteBatch); this.obstacleFactory.generateRjObstacles(this, spriteBatch); fire.draw(spriteBatch); foreground.DrawTexture(spriteBatch); spriteBatch.end(); }
public RjWorld() { camera = new OrthographicCamera( RunningJoe.PixToMeter(RunningJoe.SCREEN_WIDTH) * RunningJoe.BOX2D_WIDTH_SCALE, RunningJoe.PixToMeter(RunningJoe.SCREEN_HEIGHT) * RunningJoe.BOX2D_HEIGHT_SCALE); camera.position.set( RunningJoe.PixToMeter(RunningJoe.SCREEN_WIDTH) / 2 * RunningJoe.BOX2D_WIDTH_SCALE, RunningJoe.PixToMeter(RunningJoe.SCREEN_HEIGHT) / 2 * RunningJoe.BOX2D_HEIGHT_SCALE, 0); spriteBatch = new SpriteBatch(); Vector2 gravity = new Vector2( 0.0f, -9.81f); // we have to flip ALL y values- AS3 uses down int he y duirection as // increasing, whereas OpenGL uses UP in the y direction as positive Boolean sleep = true; world = new World(gravity, sleep); this.listBlock = new RjBlockList(this); this.obstacleFactory = new RjObstacleFactory(); rayHandler = new RayHandler(world); rayHandler.setCombinedMatrix(camera.combined); new PointLight(rayHandler, 5, new Color(0.5f, 0.5f, 0.5f, 0.8f), 100, 0, 0); TextureRegion region = new TextureRegion(AssetsManager.getInstance().getBackground(0)); // FirstBackground this.foreground = new Background(this, region, 1.5f); this.joe = new Joe(this); this.score = new Score(); this.createBackground(); this.fire = new Fire(this); Gdx.app.log("Running Joe", "GAME STARTED"); }
public void Update(float delta) { if (m_FadeIn < 1) { m_FadeIn += delta / 10; m_BackgroundMusic.setVolume(m_GameScreen.m_Settings.m_BackgroundMusicVolume * m_FadeIn); } // update and render the tilemap m_TiledMapRenderer.setView(m_GameScreen.m_Camera); m_TiledMapRenderer.render(); // update physics system m_PhysicsWorld.step(1f / 60f, 6, 2); // update and render the artemis entity system m_ArtemisWorld.setDelta(delta); m_ArtemisWorld.process(); m_SpineRenderSystem.process(); m_GameScreen.m_Camera.update(); m_GameScreen.GetSpriteBatch().setProjectionMatrix(m_GameScreen.m_Camera.combined); // update the player's light distance from watch float distance = 225; if (!m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { m_ClockTicking = false; } if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { if (!m_ClockTicking) { m_ClockTick.play(m_GameScreen.m_Settings.m_GameSoundVolume / 2); m_ClockTicking = true; } float time = m_WatchSpine.m_State.getTime(); if (time < 10.0f) { float timePercentageComplete = (10 - time) / 10.0f; distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } } else if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("wind")) { float time = m_WatchSpine.m_State.getTime(); float timePercentageComplete = time / m_WatchSpine.m_State.getAnimation().getDuration(); distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } // update the players light distance sensor m_PlayerEntity .m_LightDistanceSensor .getShape() .setRadius((m_LightPowerDistance * WORLD_TO_BOX) / 2); if (m_PlayerEntity.m_Entity != null) { BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); if (bodyComponent != null) { bodyComponent.m_Light.setDistance(distance * WORLD_TO_BOX); } } // render the lighting m_RayHandler.setCombinedMatrix(m_GameScreen.m_Camera.combined.scl(BOX_TO_WORLD)); m_RayHandler.updateAndRender(); // draw border m_BorderSprite.setColor(1, 1, 1, m_FadeIn * 0.5f); m_BorderSprite.setPosition( m_GameScreen.m_Camera.position.x - 400, m_GameScreen.m_Camera.position.y - 300); m_GameScreen.GetSpriteBatch().begin(); m_BorderSprite.draw(m_GameScreen.GetSpriteBatch()); m_GameScreen.GetSpriteBatch().end(); // draw the vials m_VialOne.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialOne.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 375); m_VialOne.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialOne.m_Skeleton.getRootBone().setRotation(m_VialOne.m_Rotation); m_VialOne.m_State.update(Gdx.graphics.getDeltaTime()); m_VialOne.m_State.apply(m_VialOne.m_Skeleton); m_VialOne.m_Skeleton.updateWorldTransform(); m_VialTwo.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialTwo.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 305); m_VialTwo.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialTwo.m_Skeleton.getRootBone().setRotation(m_VialTwo.m_Rotation); m_VialTwo.m_State.update(Gdx.graphics.getDeltaTime()); m_VialTwo.m_State.apply(m_VialTwo.m_Skeleton); m_VialTwo.m_Skeleton.updateWorldTransform(); m_VialThree.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialThree.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 390); m_VialThree.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 205); m_VialThree.m_Skeleton.getRootBone().setRotation(m_VialThree.m_Rotation); m_VialThree.m_State.update(Gdx.graphics.getDeltaTime()); m_VialThree.m_State.apply(m_VialThree.m_Skeleton); m_VialThree.m_Skeleton.updateWorldTransform(); // draw watch last m_WatchSpine.m_Skeleton.setX(m_GameScreen.m_Camera.position.x + 300); m_WatchSpine.m_Skeleton.setY(m_GameScreen.m_Camera.position.y + 200); m_WatchSpine.m_State.update(Gdx.graphics.getDeltaTime()); m_WatchSpine.m_State.apply(m_WatchSpine.m_Skeleton); m_WatchSpine.m_Skeleton.updateWorldTransform(); m_GameScreen.GetSpriteBatch().begin(); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialOne.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialTwo.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialThree.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_WatchSpine.m_Skeleton); m_GameScreen.GetSpriteBatch().end(); }
public void Create() { // set tilemap file name m_MapFileName = "map/test.tmx"; // set up the tilemap m_TiledMap = new TmxMapLoader().load(m_MapFileName); m_TiledMapRenderer = new OrthogonalTiledMapRenderer(m_TiledMap, 1f); // set up the box2d physics m_PhysicsWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, 0), true); // attach contact listener to physics world m_PhysicsWorld.setContactListener(new GameContactListener(this)); // set up box2dlights m_RayHandler = new RayHandler(m_PhysicsWorld); m_RayHandler.setAmbientLight(0.0f); // add tilemap collision boxes to physics world for (int i = 0; i < m_TiledMap.getLayers().getCount(); i++) { if (m_TiledMap.getLayers().get(i) instanceof TiledMapTileLayer) { TiledMapTileLayer layer = (TiledMapTileLayer) m_TiledMap.getLayers().get(i); for (int j = 0; j < layer.getWidth(); j++) { for (int k = 0; k < layer.getHeight(); k++) { Cell cell = layer.getCell(j, k); if (cell != null) { TiledMapTile tile = cell.getTile(); if (tile != null) { MapProperties props = tile.getProperties(); if (props.containsKey("blocked")) { float worldX = j * 64 + 32; float worldY = k * 64 + 32; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.position.set(new Vector2(worldX * WORLD_TO_BOX, worldY * WORLD_TO_BOX)); Body newBody = m_PhysicsWorld.createBody(bodyDef); PolygonShape boxShape = new PolygonShape(); boxShape.setAsBox(32 * WORLD_TO_BOX, 32 * WORLD_TO_BOX); // Create a fixture definition to apply our shape to FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = boxShape; newBody.createFixture(fixtureDef); boxShape.dispose(); } if (props.containsKey("rotate")) { // flip some random tiles to break pattern if (k * j % 3 == 0) layer.getCell(j, k).setFlipVertically(true); if (k * j % 2 == 0) layer.getCell(j, k).setFlipHorizontally(true); } } } } } } } // set up artemis entity system m_ArtemisWorld = new com.artemis.World(); // add the passive systems m_SpineRenderSystem = new SpineRenderSystem(m_GameScreen); m_ArtemisWorld.setSystem(m_SpineRenderSystem, true); // add the systems m_ArtemisWorld.setSystem(new PlayerInputSystem(this)); m_ArtemisWorld.setSystem(new CameraSystem(m_GameScreen.m_Camera)); m_ArtemisWorld.setSystem(new PhysicsSystem()); m_ArtemisWorld.setSystem(new LifecycleSystem(this)); m_ArtemisWorld.setSystem(new SteeringSystem()); // init the world m_ArtemisWorld.initialize(); EntityHelper.LoadObjects( m_GameScreen, m_ArtemisWorld, m_TiledMap, m_PhysicsWorld, m_RayHandler); // add player to entity list m_PlayerEntity = new PlayerEntity(); m_PlayerEntity.AddToWorld(this); checkpointPos = new Vector2(0, 0); checkpointPos.x = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_X; checkpointPos.y = m_PlayerEntity.m_Entity.getComponent(PositionComponent.class).m_Y; // hud items are special cases since they needs to draw on top of border m_VialOne = new SpineComponent("map/vial", 5, 0.75f, -25); m_VialTwo = new SpineComponent("map/vial", 5, 0.65f, -5); m_VialThree = new SpineComponent("map/vial", 5, 0.75f, -50); m_WatchSpine = new SpineComponent("map/watch", 4, 0.75f, 0); if (m_GameScreen.m_Settings.m_WatchFound) { ActivateWatch(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(621 * WORLD_TO_BOX, 5961 * WORLD_TO_BOX, 0); } if (m_GameScreen.m_Settings.m_WeaponFound) { ActivateSword(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(1965 * WORLD_TO_BOX, 4842 * WORLD_TO_BOX, 0); } if (m_GameScreen.m_Settings.m_WeaponLightFound) { ActivateSwordLight(); BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); bodyComponent.m_Body.setTransform(6390 * WORLD_TO_BOX, 6462 * WORLD_TO_BOX, 0); } }