Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

game/hud.h

Committer:
Noximilien
Date:
2019-04-15
Revision:
29:579e00b7f118
Parent:
28:35af3843de8f
Child:
30:d454d0cb72bc

File content as of revision 29:579e00b7f118:

#ifndef HUD_H
#define HUD_H

#include "game.h"

/**Hud Class
 * @brief A library for describing the player's heads up display(hud).
 * @author Dmitrijs Griskovs
 * @date 15/04/2019
 */
class Hud {

public:
/** @brief Draws an in-game score on the screen during the gameplay. */
    void drawScore(){
        char buffer[16];
        sprintf(buffer," Score: %i",game_score);
        lcd.printString(buffer,0,0);    
    }
/**@brief Displays the highest score reached in the main menu. */
    void drawHighScore(){
        if (high_score < game_score){
            high_score = game_score;
        }
    char buffer[16];
    sprintf(buffer,"High Score %i",high_score);
    lcd.printString(buffer,0,0);
    }
     
/** @brief mointors, updates and shows the player's lives
 * @details Checks the palyer's life value and lights the LEDs on/off accordingly to
 * how many lifes are left. green = 3, yellow = 2 and red = 1.
 */
    void displayLifes(){
        //printf("displayLifes:: %i\n", player_lifes);
        if (player_lifes == 3){
            playerHasThreeLives();  
        }
        else if (player_lifes == 2){
            playerHasTwoLives();
        }
        else if (player_lifes == 1){
            playerHasOneLife();
        }
        else {
            // all LEDs are flashing
            gamepad.leds_off();
        }        
    }
private:
    void playerHasThreeLives(){
        //turn all LEDs on
        gamepad.leds_on();
        
    }
    void playerHasTwoLives(){
      // only yelow and red are lit (total 4)
        gamepad.led(6,0.0);
        gamepad.led(3,0.0);
        
    }
    void playerHasOneLife(){
        // red LED is lit and flashes.
        gamepad.led(2,0.0);
        gamepad.led(5,0.0);
        gamepad.led(6,0.0);
        if (red_led_flashing == 5){
            gamepad.led(1,(float)red_led_state);
            gamepad.led(4,(float)red_led_state);
            gamepad.led(1,(float)!red_led_state);
            gamepad.led(4,(float)!red_led_state);
            red_led_flashing = 0;
            red_led_state = !red_led_state;
        }        
        red_led_flashing += 1;
    }
};

#endif