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@30:43aace0fdbdf, 2019-05-08 (annotated)
- Committer:
- shahidsajid
- Date:
- Wed May 08 01:20:06 2019 +0000
- Revision:
- 30:43aace0fdbdf
- Parent:
- 28:d0b0a64a832d
- Child:
- 31:eefa1d23a843
Updated in-line comments for 3 classes;
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 | 26:6427f09cf8d3 | 21 | _bowled=0; |
shahidsajid | 18:a260ce8db9e7 | 22 | _ball_count=0; |
shahidsajid | 3:bd3465a70a5a | 23 | |
shahidsajid | 3:bd3465a70a5a | 24 | } |
shahidsajid | 18:a260ce8db9e7 | 25 | void Ball::increment_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 26 | _ball_count++; |
shahidsajid | 18:a260ce8db9e7 | 27 | } |
shahidsajid | 18:a260ce8db9e7 | 28 | int Ball::get_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 29 | return _ball_count; |
shahidsajid | 18:a260ce8db9e7 | 30 | } |
shahidsajid | 15:81a3aaf52647 | 31 | int Ball::bowler_start(Gamepad &pad){ |
shahidsajid | 7:a1a6bff238c1 | 32 | if(_y1!=15){ |
shahidsajid | 12:954da4f4e565 | 33 | _y1+=1; |
shahidsajid | 7:a1a6bff238c1 | 34 | return 0; |
shahidsajid | 7:a1a6bff238c1 | 35 | } |
shahidsajid | 7:a1a6bff238c1 | 36 | else { |
shahidsajid | 26:6427f09cf8d3 | 37 | if (_set_tone==0){ |
shahidsajid | 15:81a3aaf52647 | 38 | //pad.tone(750.0,0.3); |
shahidsajid | 26:6427f09cf8d3 | 39 | _set_tone=1; |
shahidsajid | 15:81a3aaf52647 | 40 | } |
shahidsajid | 7:a1a6bff238c1 | 41 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 42 | } |
shahidsajid | 7:a1a6bff238c1 | 43 | } |
shahidsajid | 15:81a3aaf52647 | 44 | int Ball::ball_start(Gamepad &pad){ |
shahidsajid | 18:a260ce8db9e7 | 45 | |
shahidsajid | 15:81a3aaf52647 | 46 | int bowler_start_check=bowler_start(pad); |
shahidsajid | 10:6c6e09023942 | 47 | if (bowler_start_check==1){ |
shahidsajid | 9:a81db6a703b7 | 48 | if (_y!=36){ |
shahidsajid | 10:6c6e09023942 | 49 | _y+=1; |
shahidsajid | 10:6c6e09023942 | 50 | return 0; |
shahidsajid | 9:a81db6a703b7 | 51 | } |
shahidsajid | 10:6c6e09023942 | 52 | else{ |
shahidsajid | 26:6427f09cf8d3 | 53 | _bowled=1; |
shahidsajid | 10:6c6e09023942 | 54 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 55 | } |
shahidsajid | 12:954da4f4e565 | 56 | } |
shahidsajid | 7:a1a6bff238c1 | 57 | } |
shahidsajid | 11:f481ec642cc5 | 58 | |
shahidsajid | 7:a1a6bff238c1 | 59 | void Ball::draw(N5110 &lcd) |
shahidsajid | 7:a1a6bff238c1 | 60 | { |
shahidsajid | 18:a260ce8db9e7 | 61 | char buffer[5]; |
shahidsajid | 18:a260ce8db9e7 | 62 | int c=get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 63 | int length=sprintf(buffer,"B%i",c); |
shahidsajid | 18:a260ce8db9e7 | 64 | lcd.printString(buffer,0,0); |
shahidsajid | 13:924891519a95 | 65 | lcd.drawCircle(_x1,_y1,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 66 | lcd.drawCircle(_x,_y,2,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 67 | //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 68 | } |
shahidsajid | 12:954da4f4e565 | 69 | |
shahidsajid | 14:122eaa3b7a50 | 70 | int Ball::update_ball(int expected_x,int expected_y){ |
shahidsajid | 12:954da4f4e565 | 71 | if (_y!=expected_y){ |
shahidsajid | 20:9d21599fe350 | 72 | if (_y>=expected_y){ |
shahidsajid | 12:954da4f4e565 | 73 | _y--; |
shahidsajid | 9:a81db6a703b7 | 74 | } |
shahidsajid | 12:954da4f4e565 | 75 | else{ |
shahidsajid | 12:954da4f4e565 | 76 | _y++; |
shahidsajid | 14:122eaa3b7a50 | 77 | } |
shahidsajid | 6:3e50f2cf4366 | 78 | } |
shahidsajid | 14:122eaa3b7a50 | 79 | if (_x!=expected_x){ |
shahidsajid | 20:9d21599fe350 | 80 | if (_x>expected_x) |
shahidsajid | 12:954da4f4e565 | 81 | _x--; |
shahidsajid | 12:954da4f4e565 | 82 | else{ |
shahidsajid | 12:954da4f4e565 | 83 | _x++; |
shahidsajid | 12:954da4f4e565 | 84 | } |
shahidsajid | 15:81a3aaf52647 | 85 | } |
shahidsajid | 15:81a3aaf52647 | 86 | printf(" %i %i %i %i \n",_x,expected_x,_y,expected_y); |
shahidsajid | 14:122eaa3b7a50 | 87 | if (_x==expected_x && _y==expected_y){ |
shahidsajid | 14:122eaa3b7a50 | 88 | return 1; |
shahidsajid | 12:954da4f4e565 | 89 | } |
shahidsajid | 14:122eaa3b7a50 | 90 | else{ |
shahidsajid | 14:122eaa3b7a50 | 91 | return 0; |
shahidsajid | 14:122eaa3b7a50 | 92 | } |
shahidsajid | 14:122eaa3b7a50 | 93 | } |
shahidsajid | 14:122eaa3b7a50 | 94 | |
shahidsajid | 18:a260ce8db9e7 | 95 | void Ball::reset_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 96 | _ball_count=0; |
shahidsajid | 18:a260ce8db9e7 | 97 | } |
shahidsajid | 9:a81db6a703b7 | 98 | void Ball::reset(){ |
shahidsajid | 26:6427f09cf8d3 | 99 | _bowled=0; |
shahidsajid | 14:122eaa3b7a50 | 100 | _x1=42; |
shahidsajid | 14:122eaa3b7a50 | 101 | _y1=3; |
shahidsajid | 14:122eaa3b7a50 | 102 | _x = 42; |
shahidsajid | 14:122eaa3b7a50 | 103 | _y = 15; |
shahidsajid | 26:6427f09cf8d3 | 104 | _set_tone=0; |
shahidsajid | 18:a260ce8db9e7 | 105 | //_ball_count=0; |
shahidsajid | 30:43aace0fdbdf | 106 | } |