Advertisement
Guest User

HP

a guest
Jan 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.86 KB | None | 0 0
  1. package com.mygdx.game.Scenes;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.Color;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.OrthographicCamera;
  8. import com.badlogic.gdx.graphics.Pixmap;
  9. import com.badlogic.gdx.graphics.Pixmap.Format;
  10. import com.badlogic.gdx.graphics.Texture;
  11. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  12. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  13. import com.badlogic.gdx.scenes.scene2d.Stage;
  14. import com.badlogic.gdx.scenes.scene2d.ui.Label;
  15. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  16. import com.badlogic.gdx.scenes.scene2d.ui.Table;
  17. import com.badlogic.gdx.utils.viewport.FitViewport;
  18. import com.badlogic.gdx.utils.viewport.Viewport;
  19. import com.mygdx.game.MyGdxGame;
  20. import com.mygdx.game.Sprites.Dummy;
  21. import com.mygdx.game.Sprites.Player;
  22. import javafx.scene.control.ProgressBar;
  23.  
  24. /**
  25.  * Created by Tjidde
  26.  */
  27. public class Hud extends ApplicationAdapter {
  28.  
  29.     public Stage stage;
  30.     public Player player1;
  31.     public Player player2;
  32.     private Viewport viewport;
  33.     private Integer hitpoints;
  34.     private Integer hitpointsplayer1;
  35.     private Integer hitpointsplayer2;
  36.     private Integer lives1;
  37.     private Integer lives2;
  38.     private float timeCount;
  39.     private float cdCount;
  40.     private int worldTimer;
  41.     private int cdTimer;
  42.     private static Integer score1;
  43.     private static Integer score2;
  44.     private Integer cooldown1;
  45.  
  46.     // Labels
  47.     private Label liveslabel1;
  48.     private Label liveslabel2;
  49.     private Label Kill1;
  50.     private Label Kill2;
  51.     private Label numberliveslabel1;
  52.     private Label numberliveslabel2;
  53.     private Label Timerlabel;
  54.     private Label TimerNumberlabel;
  55.     private Label scoreLabel1;
  56.     private Label scoreLabel2;
  57.     private Label playerLabel1;
  58.     private Label playerLabel2;
  59.     private Label hitpointsLabel1;
  60.     private Label hitpointsLabel2;
  61.     private Label hitpointsPlayer1;
  62.     private Label hitpointsPlayer2;
  63.     private Label cooldownPlayer1;
  64.  
  65.     public Hud(SpriteBatch sb, Player player1, Player player2) {
  66.         create();
  67.  
  68.         lives1 = 3;
  69.         lives2 = 3;
  70.         worldTimer = 0;
  71.         cdTimer = 0;
  72.         score1 = 0;
  73.         score2 = 0;
  74.         timeCount = 0;
  75.         cdCount = 0;
  76.  
  77.         this.player1 = player1;
  78.         this.player2 = player2;
  79.         hitpoints = 0;
  80.         hitpointsplayer1 = 0;
  81.         hitpointsplayer2 = 0;
  82.         cooldown1 = 0;
  83.  
  84.         viewport = new FitViewport(MyGdxGame.V_WIDTH, MyGdxGame.V_HEIGHT, new OrthographicCamera());
  85.         stage = new Stage(viewport, sb);
  86.  
  87.         Table table = new Table();
  88.         table.top();
  89.         table.setFillParent(true);
  90.  
  91.         //lives
  92.         liveslabel1 = new Label(String.format("%01d", lives1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  93.         liveslabel2 = new Label(String.format("%01d", lives2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  94.         numberliveslabel1 = new Label("Lives: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  95.         numberliveslabel2 = new Label("Lives: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  96.  
  97.         //timer
  98.         Timerlabel = new Label(String.format("%03d", worldTimer), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  99.         TimerNumberlabel = new Label("Time", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  100.  
  101.         //score
  102.         playerLabel1 = new Label("Player 1:", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  103.         playerLabel2 = new Label("Player 2:", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  104.         Kill1 = new Label("Kill: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  105.         Kill2 = new Label("Kill: ", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  106.         scoreLabel1 = new Label(String.format("%01d", score1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  107.         scoreLabel2 = new Label(String.format("%01d", score2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  108.  
  109.         //hitpoints
  110.         hitpointsLabel1 = new Label(String.format("hitpoints: "), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  111.         hitpointsPlayer1 = new Label(String.format("%02d", hitpointsplayer1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  112.         hitpointsLabel2 = new Label(String.format("hitpoints: "), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  113.         hitpointsPlayer2 = new Label(String.format("%02d", hitpointsplayer2), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  114.  
  115.         //cooldown
  116.         cooldownPlayer1 = new Label(String.format("%01d", cooldown1), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
  117.  
  118.         // Adds labels to the table
  119.         table.add(playerLabel1).padLeft(-365);
  120.         table.add(playerLabel2).padRight(-435);
  121.  
  122.         table.row();
  123.         table.add(Kill1).padLeft(-420);
  124.         table.add(scoreLabel1).padLeft(-300);
  125.         table.add(Kill2).padRight(-380);
  126.         table.add(scoreLabel2).padRight(-500);
  127.  
  128.         table.row();
  129.         table.add(numberliveslabel1).padLeft(-405);
  130.         table.add(liveslabel1).padLeft(-300);
  131.         table.add(numberliveslabel2).padRight(-395);
  132.         table.add(liveslabel2).padRight(-500);
  133.  
  134.         table.row();
  135.         table.add(hitpointsLabel1).padLeft(-385);
  136.         table.add(hitpointsPlayer1).padLeft(-290);
  137.         table.add(hitpointsLabel2).padRight(-415);
  138.         table.add(hitpointsPlayer2).padRight(-510);
  139.  
  140.         table.row();
  141.         table.add(cooldownPlayer1).padLeft(-430);
  142.         table.add(TimerNumberlabel).padLeft(-50);
  143.         table.add(Timerlabel).padRight(-50);
  144.  
  145.         stage.addActor(table);
  146.  
  147.     }
  148.  
  149.     // Update method, used to count the expired time.
  150.     public void update(float dt) {
  151.  
  152.         score2 = player1.score;
  153.         scoreLabel1.setText(score1.toString());
  154.  
  155.         hitpointsplayer1 = player1.hitpoints;
  156.         hitpointsPlayer1.setText(hitpointsplayer1.toString());
  157.         score1 = player2.score;
  158.         scoreLabel2.setText(score2.toString());
  159.         hitpointsplayer2 = player2.hitpoints;
  160.         hitpointsPlayer2.setText(hitpointsplayer2.toString());
  161.         lives1 = player1.lives;
  162.         liveslabel1.setText(lives1.toString());
  163.         lives2 = player2.lives;
  164.         liveslabel2.setText(lives2.toString());
  165.  
  166.         timeCount += dt;
  167.         if (timeCount >= 1) {
  168.             worldTimer++;
  169.             Timerlabel.setText(String.format("%03d", worldTimer));
  170.             timeCount = 0;
  171.         }
  172.         if (!player1.hero.CooldownSpecial() && cdTimer == 0) {
  173.             cdTimer = 10;
  174.         }
  175.         cdCount += dt;
  176.         if (cdCount >= 1 && cdTimer != 0) {
  177.             cdTimer--;
  178.             cooldownPlayer1.setText(String.format("%02d", cdTimer));
  179.             cdCount = 0;
  180.         }
  181.     }
  182.  
  183.     SpriteBatch batch;
  184.  
  185.     Texture texture, texture2;
  186.  
  187.     @Override
  188.     public void create() {
  189.         batch = new SpriteBatch();
  190.         initTestObjects();
  191.  
  192.     }
  193.  
  194.     @Override
  195.     public void render() {
  196.         Gdx.gl.glClearColor(0, 0, 0, 0);
  197.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  198.         batch.begin();
  199.        
  200.         batch.draw(texture, 10, 10, 3000, 20);
  201.  
  202.         batch.draw(texture2, 10, 10, 2500, 20);
  203.         //batch.end();
  204.     }
  205.  
  206.  
  207.     private void initTestObjects() {
  208.  
  209.         int width = 1;
  210.         int height = 1;
  211.         Pixmap pixmap = createProceduralPixmap(width, height, 255, 1, 0);
  212.         Pixmap pixmap2 = createProceduralPixmap(width, height, 255, 255, 0);
  213.  
  214.         texture = new Texture(pixmap);
  215.         texture2 = new Texture(pixmap2);
  216.  
  217.     }
  218.  
  219.     private Pixmap createProceduralPixmap(int width, int height, int r, int g, int b) {
  220.         Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
  221.  
  222.         pixmap.setColor(r, g, b, 1);
  223.         pixmap.fill();
  224.  
  225.         return pixmap;
  226.     }
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement