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