Package Ocarina2D.Objects

Source Code of Ocarina2D.Objects.HUD

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package Ocarina2D.Objects;

import Ocarina2D.Objects.Player.PlayerDekuNut;
import Ocarina2D.TextEngine.Text;
import java.awt.Graphics2D;
import Ocarina2D.GlobalVariables;
import Ocarina2D.ZeldaKeys;
import puppyeyes.engine.Actor;
import puppyeyes.engine.Settings.Input;
import puppyeyes.engine.Sprite;

/**
*
* @author majora
*/
public class HUD extends Actor {
    private Sprite heartholder;
        private Sprite heartEmpty;
        private Sprite heartQuarter;
        private Sprite heartHalf;
        private Sprite heartThreeQ;
        private Sprite heartFull;
    private Sprite magicHolder;
        private Sprite magic;
    private Sprite itemholder;
        private Text actionText = new Text("Roll",true);

    // Keys
    private boolean holdUp;
    private boolean holdDown;
    private boolean holdLeft;
    private boolean holdRight;
    private boolean holdA;
    private boolean holdB;
   

    public HUD() {
        super("HUD");
        heartholder = new Sprite("Resources/Sprites/HUD/heartholder.png");  addFrame(heartholder);
            heartEmpty = new Sprite("Resources/Sprites/HUD/heart0.png");  addFrame(heartEmpty);
            heartQuarter = new Sprite("Resources/Sprites/HUD/heart1.png");  addFrame(heartQuarter);
            heartHalf = new Sprite("Resources/Sprites/HUD/heart2.png");  addFrame(heartHalf);
            heartThreeQ = new Sprite("Resources/Sprites/HUD/heart3.png");  addFrame(heartThreeQ);
        heartFull = new Sprite("Resources/Sprites/HUD/heart4.png");  addFrame(heartFull);

        magicHolder = new Sprite("Resources/Sprites/HUD/magicholder.png"); addFrame(magicHolder);
        magic = new Sprite("Resources/Sprites/HUD/magicbit.png"); addFrame(magic);


        itemholder = new Sprite("Resources/Sprites/HUD/itemholder.png");    addFrame(itemholder);
        actionText = new Text(GlobalVariables.action,true);


        draw.setVisible(true);
        position.x = 200;
        position.y = 5;
        draw.setLayer(GlobalVariables.hudLayer);
    }

    /**
     * Gets the key states required for this object.
     */
    private void getKeys() {
        holdUp = Input.keyDown(ZeldaKeys.up);
        holdDown = Input.keyDown(ZeldaKeys.down);
        holdLeft = Input.keyDown(ZeldaKeys.left);
        holdRight = Input.keyDown(ZeldaKeys.right);

        holdA = Input.keyDown(ZeldaKeys.a);
        holdB = Input.keyDown(ZeldaKeys.b);
    }

    @Override
    public void step() {
       getKeys();
      
       if (actionText!=null) {
         actionText.position.x = position.x;
           actionText.position.y = position.y;
            actionText.setText(GlobalVariables.action);
       }

       // Items
       dekuNut();
    }

    /**
     * Draws the hearts / life of the player at the given position.
     * @param graphics the graphics to draw to.
     * @param x the x position.
     * @param y the y position.
     */
    public void drawHearts(Graphics2D graphics, int x, int y) {
        // Draw the HUD heart holder
        //heartholder.drawSprite(graphics, x, y);

        // Draw the hearts
        if (GlobalVariables.player!=null) {
            int i=0;
            int fullHearts = (int)Math.round(GlobalVariables.player.getHealth());
            if (fullHearts > GlobalVariables.player.getHealth()) { fullHearts--; }
            while (i<fullHearts ) {
                int pos = i * (heartFull.getWidth());
                heartFull.drawSprite(graphics, x +pos, y);
                i++;
            }

            // Draw part heart
            double spareHeart =GlobalVariables.player.getHealth() - fullHearts;
            if (spareHeart == 0.25) {
                int pos = i * (heartFull.getWidth());
                heartQuarter.drawSprite(graphics, x +pos, y);
                i++;
            } else if (spareHeart == 0.5) {
                int pos = i * (heartFull.getWidth());
                heartHalf.drawSprite(graphics, x +pos, y);
                i++;
            } else if (spareHeart == 0.75) {
                int pos = i * (heartFull.getWidth());
                heartThreeQ.drawSprite(graphics, x +pos, y);
                i++;
            }

            // Draws empty hearts
            while (i< GlobalVariables.player.maxHealth) {
                  int pos = i * (heartFull.getWidth());
                  heartEmpty.drawSprite(graphics, x +pos, y);
                  i++;
            }
        }
    }

        /**
     * Draws the magic of the player at the given position.
     * @param graphics the graphics to draw to.
     * @param x the x position.
     * @param y the y position.
     */
    public void drawMagic(Graphics2D graphics, int x, int y) {
        if (GlobalVariables.player.hasMagic==true) {
            // Draw the HUD magic holder
            magicHolder.drawSprite(graphics, x, y);

            //Draw the magic bar
            if (GlobalVariables.player!=null) {
                for (int i=0; i<GlobalVariables.player.magic; i++) {
                    magic.drawSprite(graphics, x+i+6, y+2);
                }

            }
        }
    }


    @Override
    public void draw(Graphics2D graphics, int x, int y) {
        if (GlobalVariables.cutScene == false) {
            // Draw the hearts
            drawHearts(graphics, 15, 15);

            // Draw the magic
            drawMagic(graphics, 13, 30);

            // Draw the items
            itemholder.drawSprite(graphics, 250, 10);
            actionText.draw(graphics, 273, 26);

        }
    }



    // Code for all of the items


   
    public void dekuNut() {
        //if (holdB==true) {
            //new PlayerDekuNut(GlobalVariables.player.facing);
        //}
    }
}
TOP

Related Classes of Ocarina2D.Objects.HUD

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.