ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Ball/Ball.cpp

Committer:
shahidsajid
Date:
2019-04-23
Revision:
12:954da4f4e565
Parent:
11:f481ec642cc5
Child:
13:924891519a95

File content as of revision 12:954da4f4e565:


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

}

Ball::~Ball()
{

}

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

}
Vector2D Ball::get_pos()
{
    Vector2D p = {_x,_y};
    return p;
}

void Ball::set_pos(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}
int Ball::bowler_start(){
    if(_y1!=15){
        _y1+=1;
        return 0;
    }
    else {
        return 1;
    }
}
int Ball::ball_start(){
   int bowler_start_check=bowler_start();
   if (bowler_start_check==1){
         if (_y!=36){ 
            _y+=1;
            return 0;        
        }
        else{
            bowled=1;
            return 1;
        } 
    }  
}

void Ball::draw(N5110 &lcd)
{
    lcd.drawCircle(_x1,_y1,2,FILL_BLACK);
    lcd.drawCircle(_x,_y,2,FILL_TRANSPARENT);
    //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
}

void Ball::update_ball_y(int expected_y){
    if (_y!=expected_y){
     printf("IN HERE \n");
     if (_y>expected_y){
         printf("MADE IT \n");
         _y--;
     }
     else{
         _y++;
    }
}
}
void Ball::update_ball_x(int expected_x){
     if (_x!=expected_x){
     if (_x>expected_x){
         _x--;
     }
     else{
         _x++;
    }
}
}

     



void Ball::reset(){
    bowled=0;
    ballHit=0;
}