ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Ball/Ball.cpp

Committer:
shahidsajid
Date:
2019-04-24
Revision:
15:81a3aaf52647
Parent:
14:122eaa3b7a50
Child:
17:b2b651acffae
Child:
18:a260ce8db9e7

File content as of revision 15:81a3aaf52647:


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

}

Ball::~Ball()
{

}

void Ball::init(int size,int speed)
{
    _size = size;
    _x1=42;
    _y1=3;
    _x = 42;
    _y = 15;
    set_tone=0;
    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(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)
{
    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(){
    bowled=0;
    ballHit=0;
    _x1=42;
    _y1=3;
    _x = 42;
    _y = 15;
    set_tone=0;
}