Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game.Scenes;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Pixmap;
- import com.badlogic.gdx.graphics.Pixmap.Format;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.utils.viewport.FitViewport;
- import com.badlogic.gdx.utils.viewport.Viewport;
- import com.mygdx.game.MyGdxGame;
- import com.mygdx.game.Sprites.Dummy;
- import com.mygdx.game.Sprites.Player;
- import javafx.scene.control.ProgressBar;
- /**
- * Created by Tjidde
- */
- public class Hud extends ApplicationAdapter {
- public Stage stage;
- public Player player1;
- public Player player2;
- private Viewport viewport;
- private Integer hitpoints;
- private Integer hitpointsplayer1;
- private Integer hitpointsplayer2;
- private Integer lives1;
- private Integer lives2;
- private float timeCount;
- private float cdCount;
- private int worldTimer;
- private int cdTimer;
- private static Integer score1;
- private static Integer score2;
- private Integer cooldown1;
- // Labels
- private Label liveslabel1;
- private Label liveslabel2;
- private Label Kill1;
- private Label Kill2;
- private Label numberliveslabel1;
- private Label numberliveslabel2;
- private Label Timerlabel;
- private Label TimerNumberlabel;
- private Label scoreLabel1;
- private Label scoreLabel2;
- private Label playerLabel1;
- private Label playerLabel2;
- private Label hitpointsLabel1;
- private Label hitpointsLabel2;
- private Label hitpointsPlayer1;
- private Label hitpointsPlayer2;
- private Label cooldownPlayer1;
- public Hud(SpriteBatch sb, Player player1, Player player2) {
- create();
- lives1 = 3;
- lives2 = 3;
- worldTimer = 0;
- cdTimer = 0;
- score1 = 0;
- score2 = 0;
- timeCount = 0;
- cdCount = 0;
- this.player1 = player1;
- this.player2 = player2;
- hitpoints = 0;
- hitpointsplayer1 = 0;
- hitpointsplayer2 = 0;
- cooldown1 = 0;
- viewport = new FitViewport(MyGdxGame.V_WIDTH, MyGdxGame.V_HEIGHT, new OrthographicCamera());
- stage = new Stage(viewport, sb);
- Table table = new Table();
- table.top();
- table.setFillParent(true);
- //lives
- liveslabel1 = new Label(String.format("%01d", lives1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- liveslabel2 = new Label(String.format("%01d", lives2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- numberliveslabel1 = new Label("Lives: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- numberliveslabel2 = new Label("Lives: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- //timer
- Timerlabel = new Label(String.format("%03d", worldTimer), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- TimerNumberlabel = new Label("Time", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- //score
- playerLabel1 = new Label("Player 1:", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- playerLabel2 = new Label("Player 2:", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- Kill1 = new Label("Kill: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- Kill2 = new Label("Kill: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- scoreLabel1 = new Label(String.format("%01d", score1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- scoreLabel2 = new Label(String.format("%01d", score2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- //hitpoints
- hitpointsLabel1 = new Label(String.format("hitpoints: "), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- hitpointsPlayer1 = new Label(String.format("%02d", hitpointsplayer1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- hitpointsLabel2 = new Label(String.format("hitpoints: "), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- hitpointsPlayer2 = new Label(String.format("%02d", hitpointsplayer2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- //cooldown
- cooldownPlayer1 = new Label(String.format("%01d", cooldown1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
- // Adds labels to the table
- table.add(playerLabel1).padLeft(-365);
- table.add(playerLabel2).padRight(-435);
- table.row();
- table.add(Kill1).padLeft(-420);
- table.add(scoreLabel1).padLeft(-300);
- table.add(Kill2).padRight(-380);
- table.add(scoreLabel2).padRight(-500);
- table.row();
- table.add(numberliveslabel1).padLeft(-405);
- table.add(liveslabel1).padLeft(-300);
- table.add(numberliveslabel2).padRight(-395);
- table.add(liveslabel2).padRight(-500);
- table.row();
- table.add(hitpointsLabel1).padLeft(-385);
- table.add(hitpointsPlayer1).padLeft(-290);
- table.add(hitpointsLabel2).padRight(-415);
- table.add(hitpointsPlayer2).padRight(-510);
- table.row();
- table.add(cooldownPlayer1).padLeft(-430);
- table.add(TimerNumberlabel).padLeft(-50);
- table.add(Timerlabel).padRight(-50);
- stage.addActor(table);
- }
- // Update method, used to count the expired time.
- public void update(float dt) {
- score2 = player1.score;
- scoreLabel1.setText(score1.toString());
- hitpointsplayer1 = player1.hitpoints;
- hitpointsPlayer1.setText(hitpointsplayer1.toString());
- score1 = player2.score;
- scoreLabel2.setText(score2.toString());
- hitpointsplayer2 = player2.hitpoints;
- hitpointsPlayer2.setText(hitpointsplayer2.toString());
- lives1 = player1.lives;
- liveslabel1.setText(lives1.toString());
- lives2 = player2.lives;
- liveslabel2.setText(lives2.toString());
- timeCount += dt;
- if (timeCount >= 1) {
- worldTimer++;
- Timerlabel.setText(String.format("%03d", worldTimer));
- timeCount = 0;
- }
- if (!player1.hero.CooldownSpecial() && cdTimer == 0) {
- cdTimer = 10;
- }
- cdCount += dt;
- if (cdCount >= 1 && cdTimer != 0) {
- cdTimer--;
- cooldownPlayer1.setText(String.format("%02d", cdTimer));
- cdCount = 0;
- }
- }
- SpriteBatch batch;
- Texture texture, texture2;
- @Override
- public void create() {
- batch = new SpriteBatch();
- initTestObjects();
- }
- @Override
- public void render() {
- Gdx.gl.glClearColor(0, 0, 0, 0);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- batch.draw(texture, 10, 10, 3000, 20);
- batch.draw(texture2, 10, 10, 2500, 20);
- //batch.end();
- }
- private void initTestObjects() {
- int width = 1;
- int height = 1;
- Pixmap pixmap = createProceduralPixmap(width, height, 255, 1, 0);
- Pixmap pixmap2 = createProceduralPixmap(width, height, 255, 255, 0);
- texture = new Texture(pixmap);
- texture2 = new Texture(pixmap2);
- }
- private Pixmap createProceduralPixmap(int width, int height, int r, int g, int b) {
- Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
- pixmap.setColor(r, g, b, 1);
- pixmap.fill();
- return pixmap;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement