Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Ball/Ball.cpp@28:d0b0a64a832d, 2019-05-07 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue May 07 17:50:58 2019 +0000
- Revision:
- 28:d0b0a64a832d
- Parent:
- 26:6427f09cf8d3
- Child:
- 30:43aace0fdbdf
Documented the bat and ball class;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shahidsajid | 3:bd3465a70a5a | 1 | #include "Ball.h" |
shahidsajid | 3:bd3465a70a5a | 2 | Ball::Ball() |
shahidsajid | 3:bd3465a70a5a | 3 | { |
shahidsajid | 3:bd3465a70a5a | 4 | |
shahidsajid | 3:bd3465a70a5a | 5 | } |
shahidsajid | 3:bd3465a70a5a | 6 | |
shahidsajid | 3:bd3465a70a5a | 7 | Ball::~Ball() |
shahidsajid | 3:bd3465a70a5a | 8 | { |
shahidsajid | 3:bd3465a70a5a | 9 | |
shahidsajid | 3:bd3465a70a5a | 10 | } |
shahidsajid | 3:bd3465a70a5a | 11 | |
shahidsajid | 3:bd3465a70a5a | 12 | void Ball::init(int size,int speed) |
shahidsajid | 3:bd3465a70a5a | 13 | { |
shahidsajid | 3:bd3465a70a5a | 14 | _size = size; |
shahidsajid | 7:a1a6bff238c1 | 15 | _x1=42; |
shahidsajid | 7:a1a6bff238c1 | 16 | _y1=3; |
shahidsajid | 3:bd3465a70a5a | 17 | _x = 42; |
shahidsajid | 3:bd3465a70a5a | 18 | _y = 15; |
shahidsajid | 18:a260ce8db9e7 | 19 | _ball_count=0; |
shahidsajid | 26:6427f09cf8d3 | 20 | _set_tone=0; |
shahidsajid | 6:3e50f2cf4366 | 21 | bat.init(3,4); |
shahidsajid | 26:6427f09cf8d3 | 22 | _bowled=0; |
shahidsajid | 18:a260ce8db9e7 | 23 | _ball_count=0; |
shahidsajid | 3:bd3465a70a5a | 24 | |
shahidsajid | 3:bd3465a70a5a | 25 | } |
shahidsajid | 18:a260ce8db9e7 | 26 | void Ball::increment_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 27 | _ball_count++; |
shahidsajid | 18:a260ce8db9e7 | 28 | } |
shahidsajid | 18:a260ce8db9e7 | 29 | int Ball::get_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 30 | return _ball_count; |
shahidsajid | 18:a260ce8db9e7 | 31 | } |
shahidsajid | 15:81a3aaf52647 | 32 | int Ball::bowler_start(Gamepad &pad){ |
shahidsajid | 7:a1a6bff238c1 | 33 | if(_y1!=15){ |
shahidsajid | 12:954da4f4e565 | 34 | _y1+=1; |
shahidsajid | 7:a1a6bff238c1 | 35 | return 0; |
shahidsajid | 7:a1a6bff238c1 | 36 | } |
shahidsajid | 7:a1a6bff238c1 | 37 | else { |
shahidsajid | 26:6427f09cf8d3 | 38 | if (_set_tone==0){ |
shahidsajid | 15:81a3aaf52647 | 39 | //pad.tone(750.0,0.3); |
shahidsajid | 26:6427f09cf8d3 | 40 | _set_tone=1; |
shahidsajid | 15:81a3aaf52647 | 41 | } |
shahidsajid | 7:a1a6bff238c1 | 42 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 43 | } |
shahidsajid | 7:a1a6bff238c1 | 44 | } |
shahidsajid | 15:81a3aaf52647 | 45 | int Ball::ball_start(Gamepad &pad){ |
shahidsajid | 18:a260ce8db9e7 | 46 | |
shahidsajid | 15:81a3aaf52647 | 47 | int bowler_start_check=bowler_start(pad); |
shahidsajid | 10:6c6e09023942 | 48 | if (bowler_start_check==1){ |
shahidsajid | 9:a81db6a703b7 | 49 | if (_y!=36){ |
shahidsajid | 10:6c6e09023942 | 50 | _y+=1; |
shahidsajid | 10:6c6e09023942 | 51 | return 0; |
shahidsajid | 9:a81db6a703b7 | 52 | } |
shahidsajid | 10:6c6e09023942 | 53 | else{ |
shahidsajid | 26:6427f09cf8d3 | 54 | _bowled=1; |
shahidsajid | 10:6c6e09023942 | 55 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 56 | } |
shahidsajid | 12:954da4f4e565 | 57 | } |
shahidsajid | 7:a1a6bff238c1 | 58 | } |
shahidsajid | 11:f481ec642cc5 | 59 | |
shahidsajid | 7:a1a6bff238c1 | 60 | void Ball::draw(N5110 &lcd) |
shahidsajid | 7:a1a6bff238c1 | 61 | { |
shahidsajid | 18:a260ce8db9e7 | 62 | char buffer[5]; |
shahidsajid | 18:a260ce8db9e7 | 63 | int c=get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 64 | int length=sprintf(buffer,"B%i",c); |
shahidsajid | 18:a260ce8db9e7 | 65 | lcd.printString(buffer,0,0); |
shahidsajid | 13:924891519a95 | 66 | lcd.drawCircle(_x1,_y1,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 67 | lcd.drawCircle(_x,_y,2,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 68 | //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 69 | } |
shahidsajid | 12:954da4f4e565 | 70 | |
shahidsajid | 14:122eaa3b7a50 | 71 | int Ball::update_ball(int expected_x,int expected_y){ |
shahidsajid | 12:954da4f4e565 | 72 | if (_y!=expected_y){ |
shahidsajid | 20:9d21599fe350 | 73 | if (_y>=expected_y){ |
shahidsajid | 12:954da4f4e565 | 74 | _y--; |
shahidsajid | 9:a81db6a703b7 | 75 | } |
shahidsajid | 12:954da4f4e565 | 76 | else{ |
shahidsajid | 12:954da4f4e565 | 77 | _y++; |
shahidsajid | 14:122eaa3b7a50 | 78 | } |
shahidsajid | 6:3e50f2cf4366 | 79 | } |
shahidsajid | 14:122eaa3b7a50 | 80 | if (_x!=expected_x){ |
shahidsajid | 20:9d21599fe350 | 81 | if (_x>expected_x) |
shahidsajid | 12:954da4f4e565 | 82 | _x--; |
shahidsajid | 12:954da4f4e565 | 83 | else{ |
shahidsajid | 12:954da4f4e565 | 84 | _x++; |
shahidsajid | 12:954da4f4e565 | 85 | } |
shahidsajid | 15:81a3aaf52647 | 86 | } |
shahidsajid | 15:81a3aaf52647 | 87 | printf(" %i %i %i %i \n",_x,expected_x,_y,expected_y); |
shahidsajid | 14:122eaa3b7a50 | 88 | if (_x==expected_x && _y==expected_y){ |
shahidsajid | 14:122eaa3b7a50 | 89 | return 1; |
shahidsajid | 12:954da4f4e565 | 90 | } |
shahidsajid | 14:122eaa3b7a50 | 91 | else{ |
shahidsajid | 14:122eaa3b7a50 | 92 | return 0; |
shahidsajid | 14:122eaa3b7a50 | 93 | } |
shahidsajid | 14:122eaa3b7a50 | 94 | } |
shahidsajid | 14:122eaa3b7a50 | 95 | |
shahidsajid | 18:a260ce8db9e7 | 96 | void Ball::reset_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 97 | _ball_count=0; |
shahidsajid | 18:a260ce8db9e7 | 98 | } |
shahidsajid | 9:a81db6a703b7 | 99 | void Ball::reset(){ |
shahidsajid | 26:6427f09cf8d3 | 100 | _bowled=0; |
shahidsajid | 14:122eaa3b7a50 | 101 | _x1=42; |
shahidsajid | 14:122eaa3b7a50 | 102 | _y1=3; |
shahidsajid | 14:122eaa3b7a50 | 103 | _x = 42; |
shahidsajid | 14:122eaa3b7a50 | 104 | _y = 15; |
shahidsajid | 26:6427f09cf8d3 | 105 | _set_tone=0; |
shahidsajid | 18:a260ce8db9e7 | 106 | //_ball_count=0; |
shahidsajid | 9:a81db6a703b7 | 107 | } |
shahidsajid | 9:a81db6a703b7 | 108 | |
shahidsajid | 12:954da4f4e565 | 109 |