public AotHudGameOver(Skin sk) { _skin = sk; Label gameover = new Label("GAME OVER", _skin.get("JUNEBUG_32", LabelStyle.class)); _retry = new Label(">> RETRY <<", _skin.get("JUNEBUG_16", LabelStyle.class)); _lvlselect = new Label(">> LEVEL SELECTION <<", _skin.get("JUNEBUG_16", LabelStyle.class)); _retry.setPosition(0, 0); _lvlselect.setPosition(_retry.getWidth() + 100, 0); this.setWidth(_retry.getWidth() + _lvlselect.getWidth() + 100); gameover.setPosition((this.getWidth() - gameover.getWidth()) / 2, _retry.getHeight() + 100); this.setHeight(_retry.getHeight() + gameover.getHeight() + 100); addActor(gameover); addActor(_retry); addActor(_lvlselect); this.setPosition( (AbstractScreen.GAME_VIEWPORT_WIDTH - this.getWidth()) / 2, (AbstractScreen.MENU_VIEWPORT_HEIGHT - this.getHeight()) / 2 - 100); _lvlselect.addListener(this); _retry.addListener(this); }
public LabelText(String s, float x, float y) { labelStyle = new Label.LabelStyle(); labelStyle.font = Fonts.GOST_28; levNumLabel = new Label(s, labelStyle); levNumLabel.setPosition(x / 2 - levNumLabel.getWidth() / 2, y - levNumLabel.getHeight() - 10); setOrigin(x / 2, y - levNumLabel.getHeight() / 2 - 10); addActor(levNumLabel); }
public void showNotif(String text) { notifTxt.remove(); notifTxt.setText(text); notifTxt.setPosition(512 - notifTxt.getWidth() / 2, 300 - notifTxt.getHeight() / 2); notifTxt.setAlignment(Align.center); GdxGame.ui_stage1.addActor(notifTxt); notifTxt.clearActions(); notifTxt.addAction(sequence(alpha(1f), delay(1f), fadeOut(1f), removeActor())); }
@Override public void show() { Gdx.app.log(LOG, "Showing screen: " + getName()); // FPS Label fpsLabel.setFontScale(0.5f); fpsLabel.setPosition( uiStage.getWidth() - fpsLabel.getPrefWidth(), uiStage.getHeight() - fpsLabel.getHeight()); if (reaktio.getPreferencesManager().isFpsCounterEnabled()) uiStage.addActor(fpsLabel); }
public void addScore() { LabelStyle style = new LabelStyle(); style.font = new BitmapFont( Gdx.files.internal("data/flappyfont.fnt"), Gdx.files.internal("data/flappyfont.png"), false); labelScore = new Label("0", style); labelScore.setPosition( Flappybird.VIEWPORT.x / 2 - labelScore.getWidth() / 2, Flappybird.VIEWPORT.y - labelScore.getHeight()); stage.addActor(labelScore); }
@Override public void render() { Gdx.gl.glClearColor( background.rgb.getRed() / 255f, background.rgb.getGreen() / 255f, background.rgb.getBlue() / 255f, background.rgb.getAlpha() / 255f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); boolean hasUserInput = false; if (input.getText() != null && input.getText().length() != 0) hasUserInput = true; final String text = hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog"; float scale = scaleSlider.getValue(); cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.setProjectionMatrix(cam.combined); batch.getProjectionMatrix().scale(scale, scale, 0.0f); // batch.getTransformMatrix().scale(scale, scale, 0.0f); if (fonts != null) { batch.begin(); int x = 5; int y = 0; for (FontElement e : fonts) { y += e.font.getLineHeight() + 5; String str = hasUserInput ? text : e.name + " " + e.size + ": " + text; e.font.draw(batch, str, x, y); } batch.end(); } input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5); labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5); labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5); scaleSlider.setY(input.getY() - input.getHeight() - 5); scaleAmt.setY(scaleSlider.getY()); linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10); stage.act(); stage.draw(); }
@Override public void create(Object... args) { super.create(args); Label versionLabel = FontManager.Default.makeLabel( String.format( "v%s (%s, %s)", TowerConsts.VERSION, TowerConsts.GIT_SHA.substring(0, 8), TowerGameService.getDeviceOSMarketName())); versionLabel.setColor(Color.LIGHT_GRAY); versionLabel.setX(getStage().getWidth() - versionLabel.getWidth() - 5); versionLabel.setY(getStage().getHeight() - versionLabel.getHeight() - 5); addActor(versionLabel); }
private void layout() { lblMsg.setHeight(50); lblMsg.setWidth(w); lblMsg.setAlignment(Align.center, Align.center); lblMsg.setWrap(true); lblMsg.setText(Msg); lblMsg.setPosition(0, h - lblMsg.getHeight()); if (WorkPathFound > 0) { btnRunTranslations.setVisible(true); if (ImageWorkPathFound) btnRunTexturePacker.setVisible(true); else btnRunTexturePacker.setVisible(false); btnRunLibGdx.setWidth(300); btnRunLibGdx.setHeight(35); btnRunLibGdx.setY(lblMsg.getY() - margin - btnRunLibGdx.getHeight()); btnRunLibGdx.setX(margin); btnRunTranslations.setWidth(300); btnRunTranslations.setHeight(35); btnRunTranslations.setY(lblMsg.getY() - margin - btnRunLibGdx.getHeight()); btnRunTranslations.setX(btnRunLibGdx.getX() + btnRunLibGdx.getWidth() + margin); btnRunTexturePacker.setWidth(300); btnRunTexturePacker.setHeight(35); btnRunTexturePacker.setY(lblMsg.getY() - margin - btnRunLibGdx.getHeight()); btnRunTexturePacker.setX(btnRunTranslations.getX() + btnRunLibGdx.getWidth() + margin); } else { btnRunTranslations.setVisible(false); btnRunTexturePacker.setVisible(false); btnRunLibGdx.setWidth(300); btnRunLibGdx.setHeight(35); btnRunLibGdx.setY(lblMsg.getY() - margin - btnRunLibGdx.getHeight()); btnRunLibGdx.setX(w / 2 - btnRunLibGdx.getWidth() / 2); } lblOut.setHeight(btnRunLibGdx.getY() - margin - margin); lblOut.setWidth(w - margin - margin); lblOut.setWrap(true); lblOut.setPosition(margin, margin); }
/** * Create a countdown in the screen lasting for the amount of seconds given. When the countdown * reaches 0, the code provided in the runnable will be executed as a callback. * * @param seconds how many seconds should the countdown be displayed. */ private void countdown(final int seconds, final Runnable after) { // Since this is a recursive function, avoid the case where you pass // a number of seconds that might trigger an infinite loop. if (seconds <= 0) { return; } // Create the label that will contain this number String number = Integer.toString(seconds); final Label label = new Label(number, game.getSkin(), "monospace"); label.setFontScale(5f); label.setSize(150, 150); label.setAlignment(Align.center); label.setPosition( (getStage().getWidth() - label.getWidth()) / 2, (getStage().getHeight() - label.getHeight()) / 2); // Add the label to the stage and play a sound to notify the user. getStage().addActor(label); game.player.playSound(SoundCode.SELECT); label.addAction( Actions.sequence( Actions.parallel(Actions.moveBy(0, 80, 1f)), // After the animation, decide. If the countdown hasn't finished // yet, run another countdown with 1 second less. Actions.run( new Runnable() { @Override public void run() { label.remove(); if (seconds > 1) { countdown(seconds - 1, after); } else { after.run(); } } }))); }
private void showPartialScore(int score, Bounds bounds, boolean special) { // Calculate the center of the region. BallActor bottomLeftBall = board.getBall(bounds.minX, bounds.minY); BallActor upperRightBall = board.getBall(bounds.maxX, bounds.maxY); float minX = bottomLeftBall.getX(); float maxX = upperRightBall.getX() + upperRightBall.getWidth(); float minY = bottomLeftBall.getY(); float maxY = upperRightBall.getY() + upperRightBall.getHeight(); float centerX = (minX + maxX) / 2; float centerY = (minY + maxY) / 2; Label label = new Label("+" + score, game.getSkin(), "monospace"); label.setFontScale(5f); label.setSize(140, 70); label.setAlignment(Align.center); label.setPosition(centerX - label.getWidth() / 2, centerY - label.getHeight() / 2); label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor())); getStage().addActor(label); if (special) { label.setColor(Color.CYAN); } }
public Stage_Game(Viewport viewport) { super(viewport); unprojected = new Vector3(0, 0, 0); Gdx.input.setCatchBackKey(true); pauseButton = new ImageButton(skin, "pause"); pauseButton.getStyle().imageChecked.setMinWidth(150); pauseButton.getStyle().imageChecked.setMinHeight(150); pauseButton.setBounds(880, 1720, 150, 150); pauseButton.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); pause = !pause; pauseButton.setChecked(pause); exitButton.setVisible(pause); MainClass.clickSound.play(MainClass.sound); } }); exitButton = new ImageButton(skin, "exit"); exitButton.setBounds(880, 1550, 150, 150); exitButton.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { MainClass.setCurrentStage(new Stage_Menu(getViewport())); MainClass.clickSound.play(MainClass.sound); super.clicked(event, x, y); } }); exitButton.setVisible(false); gameOver = false; pause = false; bodyY = new Array<Float>(); camera = new OrthographicCamera(5.628f, 10.0f); camera.position.set(2.814f, 4, 0); camY = 4; camera.update(); muffinSource = new Actor() { @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); muffinSourceSprite.setBounds(425, 1680, 230, 186); muffinSourceSprite.setScale(getScaleX()); muffinSourceSprite.draw(batch); } }; muffinSource.setBounds(425, 1680, 230, 186); muffinSource.addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (muffinSource.getScaleX() >= 1 && !pause && !gameOver) { newMuffinSound.play(MainClass.sound); unprojected = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0)); muffinBodyDef.position.set(new Vector2(unprojected.x - 0.5f, unprojected.y - 0.5f)); tmpbd = world.createBody(muffinBodyDef); loader.attachFixture(tmpbd, "MuffinModel", muffinFixtureDef, 1.1f, 1.1f, 1.1f); tmpbd.setFixedRotation(true); drag = true; muffinSource.setScale(0.1f); ScaleToAction getNormal = new ScaleToAction(); getNormal.setScale(1); getNormal.setDuration(0.4f); mpHandler.addParticle(unprojected.x, unprojected.y, tmpbd); muffinSource.addAction(getNormal); } return super.touchDown(event, x, y, pointer, button); } }); score = 0; scoreLabel = new Label("Score: 0", skin, "score"); scoreLabel.setPosition(15, 1920 - scoreLabel.getHeight()); /** TEXTURES * */ fireEffect = new ParticleEffect(); fireEffect = AssetLoader.manager.get(AssetLoader.fireParticlePath); mpHandler = new MuffinParticleHandler(fireEffect); textures = AssetLoader.manager.get(AssetLoader.uiAtlasPath, TextureAtlas.class); normalmuffinface = textures.createSprite("muffin_face_normal"); scaredmuffinface = textures.createSprite("muffin_face_scared"); awakemuffinface = textures.createSprite("muffin_face_awake"); traySprite = textures.createSprite("tray"); traySprite.setPosition(0.3f, -1.8f); traySprite.setSize(4.4f, 2.19f); backgrounds = new Sprite[5]; for (i = 0; i < 5; i++) { backgrounds[i] = new Sprite( AssetLoader.manager.get("menu/back" + String.valueOf(i + 1) + ".png", Texture.class)); backgrounds[i].setBounds( camera.position.x - (camera.viewportWidth / 2), camera.position.y - (camera.viewportHeight / 2) + (i * 1920 / 192), (float) 1080 / 192, (float) 1920 / 192); } batch = new SpriteBatch(); batch.setProjectionMatrix(camera.combined); muffinSprite = textures.createSprite("muffin"); muffinSourceSprite = textures.createSprite("muffin"); muffinSourceSprite.setBounds(450, 1714, 180, 146); muffinSourceSprite.setOrigin(90, 73); /** PHYSICS * */ bodies = new Array<Body>(); // WORLD world = new World(new Vector2(0, -10f), true); renderer = new Box2DDebugRenderer(); // PLATE BodyDef plateDef = new BodyDef(); plateDef.type = BodyDef.BodyType.StaticBody; plateDef.position.set(2.814f, 0.25f); plate = world.createBody(plateDef); FixtureDef plateFixtureDef = new FixtureDef(); PolygonShape plateShape = new PolygonShape(); plateShape.setAsBox(1.8f, 0.1f); plateFixtureDef.shape = plateShape; plateFixtureDef.friction = 0.9f; // plateFixtureDef.density = 1; plate.createFixture(plateFixtureDef); plateShape.dispose(); // MUFFIN loader = new BodyEditorLoader(Gdx.files.internal("physics/muffin.json")); muffinBodyDef = new BodyDef(); muffinBodyDef.type = BodyDef.BodyType.DynamicBody; muffinBodyDef.bullet = true; muffinFixtureDef = new FixtureDef(); muffinFixtureDef.density = 0.7f; muffinFixtureDef.friction = 0.5f; muffinFixtureDef.restitution = 0.1f; muffinOrigin = loader.getOrigin("MuffinModel", 1.1f).cpy(); gameOverDialog = new Dialog_GameOver("", skin, "default"); /** SOUNDS * */ newHighScoreSound = AssetLoader.manager.get(AssetLoader.clappingPath, Sound.class); gameOverSound = AssetLoader.manager.get(AssetLoader.gameOverPath, Sound.class); newMuffinSound = AssetLoader.manager.get(AssetLoader.newMuffinPath, Sound.class); addActor(pauseButton); addActor(exitButton); addActor(muffinSource); addActor(scoreLabel); }
@Override public void show() { imgNinja = new Texture(Gdx.files.internal("Ninja-Shadow.png")); imgNinja.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("lastninja.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.genMipMaps = true; parameter.minFilter = Texture.TextureFilter.Linear.MipMapLinearNearest; parameter.magFilter = Texture.TextureFilter.Linear; parameter.size = 26; final BitmapFont font = generator.generateFont(parameter); startLabel = new Label("Start Game", new Label.LabelStyle(font, Color.BLACK)); startLabel.setPosition(500, 300); startLabel.setTouchable(Touchable.enabled); startLabel.setBounds(500, 300, startLabel.getWidth(), startLabel.getHeight()); startLabel.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new PlayScreen(game)); dispose(); } }); instructionLabel = new Label("Instructions", new Label.LabelStyle(font, Color.BLACK)); instructionLabel.setPosition(500, 250); instructionLabel.setTouchable(Touchable.enabled); instructionLabel.setBounds(500, 250, instructionLabel.getWidth(), instructionLabel.getHeight()); instructionLabel.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new InstructionScreen(game)); dispose(); } }); aboutLabel = new Label("About", new Label.LabelStyle(font, Color.BLACK)); aboutLabel.setPosition(500, 200); aboutLabel.setTouchable(Touchable.enabled); aboutLabel.setBounds(500, 200, aboutLabel.getWidth(), aboutLabel.getHeight()); aboutLabel.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new AboutScreen(game)); dispose(); } }); quitLabel = new Label("Quit", new Label.LabelStyle(font, Color.BLACK)); quitLabel.setPosition(500, 150); quitLabel.setTouchable(Touchable.enabled); quitLabel.setBounds(500, 150, quitLabel.getWidth(), quitLabel.getHeight()); quitLabel.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } }); stage.addActor(startLabel); stage.addActor(instructionLabel); stage.addActor(aboutLabel); stage.addActor(quitLabel); }
@Override public void onSelectionSucceeded(final List<BallActor> selection) { // Extract the data from the selection. List<Ball> balls = new ArrayList<>(); for (BallActor selectedBall : selection) balls.add(selectedBall.getBall()); final Bounds bounds = Bounds.fromBallList(balls); // Change the colors of the selected region. board.addAction( Actions.sequence( board.hideRegion(bounds), Actions.run( new Runnable() { @Override public void run() { for (BallActor selectedBall : selection) { selectedBall.setColor(Color.WHITE); } generate(bounds); // Reset the cheat game.getState().setCheatSeen(false); game.getState().setWiggledBounds(null); } }))); // Give some score to the user. ScoreCalculator calculator = new ScoreCalculator(game.getState().getBoard(), bounds); int givenScore = calculator.calculate(); game.getState().addScore(givenScore); score.giveScore(givenScore); // Put information about this combination in the stats. int rows = bounds.maxY - bounds.minY + 1; int cols = bounds.maxX - bounds.minX + 1; String size = Math.max(rows, cols) + "x" + Math.min(rows, cols); game.statistics.getSizesData().incrementValue(size); BallColor color = board.getBall(bounds.minX, bounds.minY).getBall().getColor(); game.statistics.getColorData().incrementValue(color.toString().toLowerCase()); game.statistics.getTotalData().incrementValue("balls", rows * cols); game.statistics.getTotalData().incrementValue("combinations"); // Now, display the score to the user. If the combination is a // PERFECT combination, just display PERFECT. int boardSize = game.getState().getBoard().getSize() - 1; if (bounds.equals(new Bounds(0, 0, boardSize, boardSize))) { // Give score Label label = new Label("PERFECT", game.getSkin(), "monospace"); label.setX((getStage().getViewport().getWorldWidth() - label.getWidth()) / 2); label.setY((getStage().getViewport().getWorldHeight() - label.getHeight()) / 2); label.setFontScale(3); label.setAlignment(Align.center); label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor())); getStage().addActor(label); game.player.playSound(SoundCode.PERFECT); // Give time float givenTime = Constants.SECONDS - timer.getSeconds(); timer.giveTime(givenTime, 4f); } else { // Was special? boolean special = givenScore != rows * cols; // Give score showPartialScore(givenScore, bounds, special); game.player.playSound(SoundCode.SUCCESS); // Give time float givenTime = 4f; timer.giveTime(givenTime, 0.25f); } }
@Override public void create() { // Gdx.gl.glClearColor( // background.rgb.getRed() / 255f, // background.rgb.getGreen() / 255f, // background.rgb.getBlue() / 255f, // background.rgb.getAlpha() / 255f); // Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // Gdx.graphics.setContinuousRendering(false); // Gdx.graphics.requestRendering(); cam = new OrthographicCamera(); batch = new SpriteBatch(); stage = new Stage(); skin = new Skin(Gdx.files.internal("data/uiskin.json")); input = new TextField("", skin); // can't use Table here since it will conflict with the Swing Table toolkit // this is why static is shit -.- labelInput = new Label("Sample Text:", skin); labelScale = new Label("Scale:", skin); scaleAmt = new Label("1.0", skin); labelInput.setHeight(input.getHeight()); labelInput.setPosition(10, Gdx.graphics.getHeight() - labelInput.getHeight() - 5); input.setPosition( labelInput.getX() + labelInput.getWidth() + 10, Gdx.graphics.getHeight() - input.getHeight() - 5); scaleSlider = new Slider(0, 3, 0.05f, false, skin); scaleSlider.setSnapToValues(new float[] {0.0f, 0.5f, 1.0f}, 0.05f); scaleSlider.addListener( new ChangeListener() { @Override public void changed(ChangeEvent arg0, Actor arg1) { scaleAmt.setText(String.format("%.2f", scaleSlider.getValue())); } }); scaleSlider.setValue(1.0f); scaleAmt.setText(String.format("%.2f", scaleSlider.getValue())); linearFiltering = new ToggleBox("Linear Filtering", skin); linearFiltering.addListener( new ClickListener() { public void clicked(InputEvent ev, float x, float y) { updateFiltering(); } }); scaleAmt.setHeight(scaleSlider.getHeight()); labelScale.setHeight(scaleSlider.getHeight()); labelScale.setPosition( input.getX() - 10 - labelScale.getWidth(), labelInput.getY() - labelInput.getHeight() - 5); scaleSlider.setPosition(input.getX(), input.getY() - input.getHeight() - 5); scaleAmt.setPosition(scaleSlider.getX() + scaleSlider.getWidth() + 5, scaleSlider.getY()); linearFiltering.setPosition(input.getX(), scaleSlider.getY() - scaleSlider.getHeight() - 10); Gdx.input.setInputProcessor(stage); stage.addActor(labelInput); stage.addActor(input); stage.addActor(labelScale); stage.addActor(scaleSlider); stage.addActor(scaleAmt); stage.addActor(linearFiltering); myButton = new TextButton("Blah", skin); }