ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Ball/Ball.cpp

Committer:
shahidsajid
Date:
2019-05-01
Revision:
26:6427f09cf8d3
Parent:
20:9d21599fe350
Child:
28:d0b0a64a832d

File content as of revision 26:6427f09cf8d3:


#include "Ball.h"
Ball::Ball()
{

}

Ball::~Ball()
{

}

void Ball::init(int size,int speed)
{
    _size = size;
    _x1=42;
    _y1=3;
    _x = 42;
    _y = 15;
    _ball_count=0;
    _set_tone=0;
    bat.init(3,4);
    _bowled=0;
    _ball_count=0;

}
void Ball::increment_ball_count(){
    _ball_count++;
}
int Ball::get_ball_count(){
    return _ball_count;
}
int Ball::bowler_start(Gamepad &pad){
    if(_y1!=15){
        _y1+=1;
        return 0;
    }
    else {
        if (_set_tone==0){
            //pad.tone(750.0,0.3);
            _set_tone=1;
        }
        return 1;
    }
}
int Ball::ball_start(Gamepad &pad){
   
   int bowler_start_check=bowler_start(pad);
   if (bowler_start_check==1){
         if (_y!=36){ 
            _y+=1;
            return 0;        
        }
        else{
            _bowled=1;
            return 1;
        } 
    }  
}

void Ball::draw(N5110 &lcd)
{
    char buffer[5];
    int c=get_ball_count();
    int length=sprintf(buffer,"B%i",c);
    lcd.printString(buffer,0,0);
    lcd.drawCircle(_x1,_y1,2,FILL_TRANSPARENT);
    lcd.drawCircle(_x,_y,2,FILL_BLACK);
    //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
}

int Ball::update_ball(int expected_x,int expected_y){
    if (_y!=expected_y){
     if (_y>=expected_y){
         _y--;
     }
     else{
         _y++;
     }
    }
    if (_x!=expected_x){
     if (_x>expected_x)
         _x--;
     else{
         _x++;
    }
   }
printf(" %i %i %i %i \n",_x,expected_x,_y,expected_y);
if (_x==expected_x && _y==expected_y){
    return 1;
}
else{
    return 0; 
}
}

void Ball::reset_ball_count(){
    _ball_count=0;
}


void Ball::reset(){
    _bowled=0;
   
    _x1=42;
    _y1=3;
    _x = 42;
    _y = 15;
    _set_tone=0;
    //_ball_count=0;
}