List of usage examples for com.badlogic.gdx.math CatmullRomSpline valueAt
@Override public T valueAt(T out, float t)
From source file:releasethekraken.GameWorld.java
/** * Gets the target position that a sea creature should move towards, based on * where the sea creature currently is. At the end of the path, it will be * the last point on the path./*from ww w . j a v a2 s . co m*/ * @param entity The sea creature * @return The position the sea creature should move towards */ public Vector2 getPathTargetPos(EntitySeaCreature entity) { if (entity.getCurrentPath() == null) //Immediately return if there is no path to follow return entity.getPos(); //TODO: The target position doesn't seem to be that great CatmullRomSpline smoothPath = entity.getCurrentPath().getSmoothPath(); Vector2 targetPos = new Vector2(); float pathProgress = smoothPath.locate(entity.getPos()); if (pathProgress >= 0.9F) //Randomly choose a next path. TODO: Allow for choosing { //Gdx.app.log(entity.toString(), "At the end of the path! ****************************************************************"); SeaCreaturePath nextPath = entity.getCurrentPath().getNextPaths().random(); if (nextPath != null) { entity.setCurrentPath(nextPath); return getPathTargetPos(entity); } } smoothPath.valueAt(targetPos, pathProgress); return targetPos; }
From source file:releasethekraken.ui.renderer.GameRenderer.java
/** * Constructs a new GameRenderer/*from ww w .j a va 2 s. co m*/ * @param rtk The ReleaseTheKraken instance. This is final so that the * anonymous inner classes can access it. * @param world The world to be rendered */ public GameRenderer(final ReleaseTheKraken rtk, GameWorld world) { super(); this.world = world; //Populate the list of connected paths this.world.getFirstPath().getAllConnectedPaths(this.seaCreaturePaths); //Create the camera to view the world this.camera = new OrthographicCamera(); float cameraWidth = 80.0F; float cameraHeight = (Gdx.graphics.getHeight() * 1F / Gdx.graphics.getWidth()) * cameraWidth; this.camera.setToOrtho(false, cameraWidth, cameraHeight); Gdx.app.log("GameRenderer", "Calculated camera dimensions: " + cameraWidth + " x " + cameraHeight); this.worldSpriteBatch = new SpriteBatch(); this.worldShapeRenderer = new ShapeRenderer(); //Set the world renderers to render to the camera's projection matrix this.worldSpriteBatch.setProjectionMatrix(this.camera.combined); this.worldShapeRenderer.setProjectionMatrix(this.camera.combined); //Create the Box2D debug renderer this.box2DDebugRenderer = new Box2DDebugRenderer(); this.box2DDebugRenderer.setDrawVelocities(true); //Create the tile map renderer this.tiledMapRenderer = new OrthogonalTiledMapRenderer(world.getTiledMap(), 1 / (world.getTiledMapUnitScale())); //this.tiledMapRenderer.getBatch().setShader(GameAssets.tilemapShader); //Set the shader //Don't use the shader for now this.debugOverlay = new DebugOverlay(this); this.uiObjects.add(this.debugOverlay); UiButton pauseButton = new UiButton(this, Gdx.graphics.getWidth() - 0.075F * Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 0.05F * Gdx.graphics.getHeight(), 0.075F, 0.05F, "Pause", Color.GRAY.cpy().sub(0.1F, 0.1F, 0.1F, 0)) { @Override public void onClick(int mouseButton) { super.onClick(mouseButton); //Take a screenshot of the game Pixmap pixmap = Screenshots.getScreenshot(true); //Push a new pause screen onto the screen stack rtk.pushScreen(new PauseScreen(rtk, pixmap)); } }; pauseButton.setToolTip(new TextToolTip(this, "Pause the game")); this.uiObjects.add(pauseButton); UiButton debugMenuButton = new UiButton(this, Gdx.graphics.getWidth() - 0.2323F * Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 0.05F * Gdx.graphics.getHeight(), 0.157F, 0.05F, "Debug Screen", Color.GRAY.cpy().sub(0.1F, 0.1F, 0.1F, 0)) { @Override public void onClick(int mouseButton) { super.onClick(mouseButton); if (this.renderer instanceof GameRenderer) { ((GameRenderer) this.renderer).debugScreenVisible = !((GameRenderer) this.renderer).debugScreenVisible; //Toggle visibility Gdx.app.log("Debug Menu Button", "Debug screen " + (((GameRenderer) this.renderer).debugScreenVisible ? "ON" : "OFF")); } } }; debugMenuButton.setToolTip(new TextToolTip(this, "Show/Hide Debug Screen")); this.uiObjects.add(debugMenuButton); this.uiObjects.add(new Sidebar(this)); //Add the sidebar this.uiObjects.sort(); //Sort the UI objects so that they render in the order of their render depths //Generate path pixmap and texture Pixmap.setBlending(Pixmap.Blending.None); //Disable Pixmap blending, because it causes weird lines this.pathPixmap = new Pixmap((int) (this.world.getWidth() * this.world.getTiledMapUnitScale()), (int) (this.world.getHeight() * this.world.getTiledMapUnitScale()), Pixmap.Format.RGBA8888); //Make sure the pixmap is clear this.pathPixmap.setColor(new Color(0, 0, 0, 0)); //Completely clear this.pathPixmap.fill(); this.pathPixmap.setColor(Color.valueOf("61B5FF66")); //Partial transparency with color //Draw the path for every path for (SeaCreaturePath path : this.seaCreaturePaths) { CatmullRomSpline smoothPath = path.getSmoothPath(); Vector2 pathPoint = new Vector2(); //Move across the path from 0 to 1, drawing circles along the way for (float f = -0.1F; f < 1.1F; f += 0.001F) { smoothPath.valueAt(pathPoint, f); //Stores the value of the path at the point in the vector this.pathPixmap.fillCircle((int) (pathPoint.x * this.world.getTiledMapUnitScale()), (int) (this.world.getHeight() * this.world.getTiledMapUnitScale() - (pathPoint.y * this.world.getTiledMapUnitScale())), (int) this.world.getTiledMapUnitScale()); } } //Create texture to hold pixmap data this.pathTexture = new Texture(this.pathPixmap); this.pathTexture.draw(this.pathPixmap, 0, 0); //Draw the pixmap to the texture this.pathTexture.bind(1); //Bind the texture to texture unit 1 Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0); //Set the active texture back to the normal one }