ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bat.cpp Source File

Bat.cpp

00001 #include "Bat.h"
00002 
00003 //Constructor for the Bat Object
00004 Bat::Bat()
00005 {
00006 
00007 }
00008 //Deconstructor for the Bat Object
00009 Bat::~Bat()
00010 {
00011 
00012 }
00013 //Initialises the UX Object
00014 void Bat::init(int width,int height)
00015 {   
00016     //assigns the x and y co-ordinates for the bat to be printed to the LCD
00017     _bat_width = width;
00018     _bat_height = height;
00019     
00020     //initialises the Bat class flags to 0
00021     _hit_ball=0;
00022     _loft_ball=0;
00023 }
00024 
00025 //Resets the bat flags to 0
00026 void Bat::reset(){
00027     _hit_ball=0;
00028     _loft_ball=0;
00029 }
00030 
00031 //Draws the bat on the LCD
00032 void Bat::draw(N5110 &lcd){
00033     lcd.drawLine(38,36,41,36,1);
00034     lcd.drawRect(41,35,_bat_width,_bat_height,FILL_BLACK);
00035 }
00036 
00037 //Checks if the ball has been hit during the game play
00038 //if true the hit ball variable is set to 1 and returned to the caller
00039 /* The bat passes UX as the argument because CHECK_EVENT function of the gamepad did 
00040    did not respond when using the Gamepad object declared in the main function*/
00041 int Bat::get_hit_ball(UX &ux){ 
00042     _hit_ball=ux.get_a_pressed();
00043     //printf("_hitBall %i \n",_hitBall); //used for debugging to get the flag value
00044     return _hit_ball; 
00045 }
00046 
00047 //Checks if the ball has been hit during the game play
00048 //if true the loft ball variable is 1 and returned to the caller
00049 int Bat::get_loft_ball(UX &ux){
00050      _loft_ball=ux.get_l_pressed();
00051      //printf("_loftBall %i \n",_loftBall); //used for debugging 
00052     return _loft_ball;
00053 }
00054 
00055