ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Bat/Bat.cpp

Committer:
shahidsajid
Date:
2019-05-08
Revision:
31:eefa1d23a843
Parent:
30:43aace0fdbdf
Child:
33:9d34ef219fff

File content as of revision 31:eefa1d23a843:

#include "Bat.h"

//Constructor for the Bat Object
Bat::Bat()
{

}
//Deconstructor for the Bat Object
Bat::~Bat()
{

}
//Initialises the UX Object
void Bat::init(int width,int height)
{   
    //assigns the x and y co-ordinates for the bat to be printed to the LCD
    _bat_width = width;
    _bat_height = height;
    
    //initialises the Bat class flags to 0
    _hit_ball=0;
    _loft_ball=0;
}

//Resets the bat flags to 0
void Bat::reset(){
    _hit_ball=0;
    _loft_ball=0;
}

//Draws the bat on the LCD
void Bat::draw(N5110 &lcd){
    lcd.drawLine(38,36,41,36,1);
    lcd.drawRect(41,35,_bat_width,_bat_height,FILL_BLACK);
}

//Checks if the ball has been hit during the game play
//if true the hit ball variable is set to 1 and returned to the caller
/* The bat passes UX as the argument because CHECK_EVENT function of the gamepad did 
   did not respond when using the Gamepad object declared in the main function*/
int Bat::get_hit_ball(UX &ux){ 
    _hit_ball=ux.get_a_pressed();
    //printf("_hitBall %i \n",_hitBall); //used for debugging to get the flag value
    return _hit_ball; 
}

//Checks if the ball has been hit during the game play
//if true the loft ball variable is 1 and returned to the caller
int Bat::get_loft_ball(UX &ux){
     _loft_ball=ux.get_l_pressed();
     //printf("_loftBall %i \n",_loftBall); //used for debugging to
    return _loft_ball;
}