// *** Methods for drawing text ***\\ public static void drawString( SpriteBatch batch, String string, float x, float y, boolean centered, float scale, Color color) { // Check if the new scale is the same as the current one. if (font_.getScaleX() != scale || font_.getScaleY() != scale) font_.setScale(scale); // No need to check the colour, as that is done in the BitmapCache in the BitmapFont. font_.setColor(color); if (centered) { TextBounds bounds = font_.getBounds(string); float width = bounds.width; float height = bounds.height - font_.getAscent(); x -= (width / 2); y -= (height / 2); } font_.draw(batch, string, x, y); }
public void draw(SpriteBatch batch) { batch.draw( /*Texture*/ sprite, /*x*/ x - originX + dOffX, /*y*/ y - originY + dOffY, /*originX*/ originX, /*originY*/ originY, /*width*/ dWidth, /*height*/ dHeight, /*scaleX*/ 1, /*scaleY*/ 1, /*rotation*/ angle, /*uselss shit to the right*/ 0, 0, sprite.getWidth(), sprite.getHeight(), flipX, flipY); font.draw( batch, Integer.toString(effect.getNum()), (float) (x + 32 - font.getScaleX() * (Math.floor(Math.log10(effect.getNum())) + 1) * 7) - 4, y + font.getScaleY() * 12 + 1); }
public void render(Treasure cost) { fontScale = font.getScaleX(); font.setScale(Math.max(Math.round(fontScale * scale), 1)); if (!cost.equals(this.cost) || !this.equals(bounds)) { this.bounds = new Rectangle(this); this.cost = new Treasure(cost); caches = new ArrayList<costValueCache>(); if (showCost) { if (cost.getGold() > 0) { caches.add(new costValueCache(Color.WHITE, "Cost: ")); caches.add(new costValueCache(Color.YELLOW, cost.getGold() + " ")); } } for (Element element : Element.values()) { int element1 = cost.getElement(element); if (element1 > 0) { caches.add(new costValueCache(Color.WHITE, element1 + "x ")); caches.add(new costValueCache(element.getColor(), element.toString() + " ")); } } render(); } else { render(); } font.setScale(fontScale); if (App.DEBUG != null) { shapeRenderer.setColor(Color.RED); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.rect(x, y, width, height); shapeRenderer.end(); } }
protected void renderGame() { Gdx.gl.glClearDepthf(1f); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT); // Clearing screen, positioning camera, rendering map and entities // Positioning camera to the player Specular.camera.zoom = 1; Camera.setPosition(); Specular.camera.update(); // Rendering map and entities game.batch.setProjectionMatrix(Specular.camera.combined); game.batch.begin(); game.batch.setColor(1, 1, 1, 1); game.batch.draw( currentMap.getParallax(), -1024 + Camera.getCameraX() / 2, -1024 + Camera.getCameraY() / 2, 4096, 4096); game.batch.setColor(1, 1, 1, 1); Camera.setZoom(); BoardShock.setZoom(); Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); currentMap.render(game.batch, true); ScissorStack.calculateScissors( Specular.camera, game.batch.getTransformMatrix(), clipBounds, scissors); ScissorStack.pushScissors(scissors); if (tutorialOnGoing && tutorial.getCurrentWave().getEvent() == TutorialEvent.POWER_UPS_SHOWN) { if (!tutorial.enemiesHasSpawned()) { Util.writeCentered( game.batch, tutorial.getFont(), "these are power-ups", tutorial.getTextX(), tutorial.getTextY() + 200); if (tutorial.allPowerUpsActivated()) Util.writeCentered( game.batch, tutorial.getFont(), "some can be combined", tutorial.getTextX(), tutorial.getTextY()); } } for (Entity ent : entities) { if (!(ent instanceof Enemy)) ent.render(game.batch); } game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); for (UpgradeOrb orb : orbs) orb.render(game.batch); for (Particle p : particles) p.render(game.batch); game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); for (Entity ent : enemies) { ent.render(game.batch); } if (!gameMode.isGameOver()) player.render(game.batch); game.batch.flush(); ScissorStack.popScissors(); // Re-positioning camera for HUD Specular.camera.position.set(0, 0, 0); Specular.camera.zoom = 1; Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); if (isPaused) { // Pause menu game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.draw(pauseTex, -pauseTex.getWidth() / 2, 100); pauseInputProcessor.getResumeButton().render(); pauseInputProcessor.getToMenuButton().render(); } else { if (!gameMode.isGameOver()) { // Drawing HUD hud.render(game.batch, scoreMultiplierTimer); gameInputProcessor.getShootStick().render(game.batch); gameInputProcessor.getMoveStick().render(game.batch); // Tutorial if (tutorialOnGoing && !showTutorialEnd) tutorial.render(game.batch); // Drawing SCORE in the middle top of the screen Util.writeCentered( game.batch, scoreFont, player.getFormattedScore(), 0, Specular.camera.viewportHeight / 2 - 36); // Drawing MULTIPLIER on screen Util.writeCentered( game.batch, multiplierFont, "x" + Math.round(scoreMultiplier), 0, Specular.camera.viewportHeight / 2 - 98); // Tutorial end if (showTutorialEnd) { tutorialTicks++; if (tutorialTicks > 120) { scoreFontAlpha = (tutorialTicks - 120) / 180f; scoreFontAlpha = scoreFontAlpha > 1 ? 1 : scoreFontAlpha; game.batch.setColor(1, 1, 1, scoreFontAlpha); game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.setColor(Color.WHITE); scoreFont.setColor(1, 0, 0, scoreFontAlpha); Util.writeCentered(game.batch, scoreFont, "tap to continue", 0, -100); } } gameMode.render(game.batch); } else if (gameMode.isGameOver()) { // Game over screen // Manual camera shake Specular.camera.position.set(0, 0, 0); Specular.camera.position.add( rand.nextFloat() * 100 * Camera.getShakeIntensity(), rand.nextFloat() * 100 * Camera.getShakeIntensity(), 0); Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.draw(gameOverTex, -gameOverTex.getWidth() / 2, -gameOverTex.getHeight() / 2); // Game Over effects [fade in, camera shake] if (gameOverScoreFont.getScaleX() > 1f) { gameOverScoreFont.scale(-0.1f); gameOverScoreFont.setColor( 1, 0, 0, Math.max((10 - gameOverScoreFont.getScaleX()) / 10f, 0)); } else { gameOverScoreFont.setScale(1); if (!shaken) { Camera.shake(0.5f, 0.02f); shaken = true; } if (player.getScore() >= lastHighscore) { Util.drawCentered(game.batch, newHighscore, 0, 0, 0); lastHighscore = player.getScore(); } } // Drawing final score and buttons if (music != null) music.setVolume(0.25f); if (gameOverTicks == GAMEOVERSOUND_TIMER && isSoundEnabled()) { gameOverSound.play(1f, 1, 0); } Util.writeCentered(game.batch, gameOverScoreFont, player.getFormattedScore(), 0, 100); game.batch.setColor(Color.WHITE); ggInputProcessor.getRetryBtn().render(); ggInputProcessor.getMenuBtn().render(); ggInputProcessor.getHighscoreBtn().render(); if (player.getUpgradePoints() >= 1) { if (!ggInputProcessor.isTouchingUpgradeBtn()) { if (gameOverTicks % 90 < 40) { ggInputProcessor.getUpgradeBtn().setScale(1.00f); ggInputProcessor.getUpgradeBtn().setTouch(true); } else { ggInputProcessor.getUpgradeBtn().setScale(1.0f); ggInputProcessor.getUpgradeBtn().setTouch(false); } } } ggInputProcessor.getUpgradeBtn().render(); } } game.batch.end(); }
protected void update() { if (!isPaused) { if (tutorialOnGoing) tutorial.update(); // Remove random particles if there are too many while (particles.size >= PARTICLE_LIMIT) particles.removeIndex(rand.nextInt(particles.size)); // Remove random orbs if there are too many while (orbs.size >= ORB_LIMIT) orbs.removeIndex(rand.nextInt(orbs.size)); // Adding played time if (!gameMode.isGameOver()) ticks++; // Updating combos cs.update(); BoardShock.update(); if (scoreMultiplier > 1) { if (scoreMultiplierTimer < MULTIPLIER_COOLDOWN_TIME) { float decreaseRate = (float) scoreMultiplier / 3; scoreMultiplierTimer += decreaseRate; } else { if (isSoundEnabled()) multiplierDownSound.play(1f, (float) Math.sqrt(scoreMultiplier / 3), 0); scoreMultiplierTimer = 0; scoreMultiplier--; } } if (cs.getCombo() > 7) { if (isSoundEnabled()) multiplierUpSound.play(1f, (float) Math.sqrt(scoreMultiplier / 3), 0); setScoreMultiplier(scoreMultiplier + 1); if (getScoreMultiplier() % 10 == 0) { multiplierFont.scale(2); } cs.resetCombo(); } if (multiplierFont.getScaleX() > 1) { multiplierFont.scale(-0.05f); if (multiplierFont.getScaleX() <= 1) { multiplierFont.setScale(1); } } boolean playerKilled = false; // A variable to keep track of player status if (!gameMode.isGameOver()) { // Update game mode, enemy spawning and player hit detection gameMode.update(TICK_LENGTH / 1000000); if (!tutorialOnGoing) { // Update power-ups powerUpSpawnTime--; if (powerUpSpawnTime < 0) { if (enablePowerUps) { puss.spawn(); powerUpSpawnTime = 300; } } } updateHitDetections(); // So that they don't spawn while death animation is playing if (!player.isDying() && !player.isSpawning()) { if (player.isDead() && !tutorialOnGoing) { pss.spawn(true); waveNumber++; currentWave = waveManager.getWave(waveNumber); } else { player.updateHitDetection(); if (!tutorialOnGoing) { if (currentWave.update()) { waveNumber++; currentWave = waveManager.getWave(waveNumber); } } } } if (player.update() && !player.isDying()) { if (!tutorialOnGoing) { gameMode.playerKilled(); playerKilled = true; } } } else { clearLists(); gameOverTicks++; } // Removing destroyed entities for (Iterator<Entity> it = entities.iterator(); it.hasNext(); ) { Entity ent = it.next(); if (ent.update()) { if (ent instanceof Particle) pass.getPool().free((Particle) ent); else if (ent instanceof UpgradeOrb) oss.getPool().free((UpgradeOrb) ent); else if (ent instanceof Enemy) enemies.removeIndex(enemies.indexOf((Enemy) ent, true)); else if (ent instanceof PowerUp) powerups.removeIndex(powerups.indexOf((PowerUp) ent, true)); else if (ent instanceof Bullet) { bullets.removeIndex(bullets.indexOf((Bullet) ent, true)); Bullet.free((Bullet) ent); } it.remove(); } } for (Iterator<UpgradeOrb> it = orbs.iterator(); it.hasNext(); ) { if (it.next().update()) it.remove(); } for (Iterator<Particle> it = particles.iterator(); it.hasNext(); ) { if (it.next().update()) it.remove(); } // Enemy Slowdown SlowdownEnemies.setUpdatedSlowdown(false); if (playerKilled && tutorialHasEnded()) { if (!gameMode.isGameOver()) { clearLists(); resetGameTime(); pss.spawn(false); } else { saveStats(); input.setInputProcessor(ggInputProcessor); gameOverScoreFont.scale(14); if (Specular.nativeAndroid.isLoggedIn()) { Specular.nativeAndroid.postHighscore(player.getScore(), true); } } } Camera.update(this); } }
@Override public void draw() { if (_flickerTimer != 0) { _flicker = !_flicker; if (_flicker) return; } FlxCamera camera = FlxG._activeCamera; if (cameras == null) cameras = FlxG.cameras; if (!cameras.contains(camera, true)) return; if (!onScreen(camera)) return; _point.x = x - (camera.scroll.x * scrollFactor.x) - offset.x; _point.y = y - (camera.scroll.y * scrollFactor.y) - offset.y; _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f; _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f; // scaling BitmapFont font = _textField.getFont(); if (scale.x != font.getScaleX() || scale.y != font.getScaleY()) { _textField.getFont().setScale(scale.x, scale.y); calcFrame(); } // position _textField.setPosition(_point.x, _point.y); // rotation if (angle != 0) { _matrix = FlxG.batch.getTransformMatrix().cpy(); Matrix4 rotationMatrix = FlxG.batch.getTransformMatrix(); rotationMatrix.translate( _textField.getX() + (width / 2), _textField.getY() + (height / 2), 0); rotationMatrix.rotate(0, 0, 1, angle); rotationMatrix.translate( -(_textField.getX() + (width / 2)), -(_textField.getY() + (height / 2)), 0); FlxG.batch.setTransformMatrix(rotationMatrix); } // blending if (blend != null && currentBlend != blend) { int[] blendFunc = BlendMode.getOpenGLBlendMode(blend); FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]); } else if (Gdx.graphics.isGL20Available() && (FlxG.batchShader == null || ignoreBatchShader)) { // OpenGL ES 2.0 shader render renderShader(); // OpenGL ES 2.0 blend mode render renderBlend(); } // Render shadow behind the text if (_shadow != 0) { // tinting int tintColor = FlxU.multiplyColors(_shadow, camera.getColor()); _textField.setColor( ((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, ((_shadow >> 24) & 0xFF) * _alpha * 0.00392f); _textField.translate(_shadowX, _shadowY); _textField.draw(FlxG.batch); _textField.translate(-_shadowX, -_shadowY); } // tinting int tintColor = FlxU.multiplyColors(_color, camera.getColor()); _textField.setColor( ((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, _alpha); _textField.draw(FlxG.batch); // rotation if (angle != 0) FlxG.batch.setTransformMatrix(_matrix); _VISIBLECOUNT++; if (FlxG.visualDebug && !ignoreDrawDebug) drawDebug(camera); }
public float getScaleX() { return font.getScaleX(); }