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@23:a16c97a59a41, 2019-05-01 (annotated)
- Committer:
- shahidsajid
- Date:
- Wed May 01 07:40:35 2019 +0000
- Revision:
- 23:a16c97a59a41
- Parent:
- 20:9d21599fe350
Fixed out screen bug
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 | 15:81a3aaf52647 | 21 | set_tone=0; |
shahidsajid | 6:3e50f2cf4366 | 22 | bat.init(3,4); |
shahidsajid | 9:a81db6a703b7 | 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 | 23:a16c97a59a41 | 33 | /* |
shahidsajid | 12:954da4f4e565 | 34 | Vector2D Ball::get_pos() |
shahidsajid | 12:954da4f4e565 | 35 | { |
shahidsajid | 12:954da4f4e565 | 36 | Vector2D p = {_x,_y}; |
shahidsajid | 12:954da4f4e565 | 37 | return p; |
shahidsajid | 12:954da4f4e565 | 38 | } |
shahidsajid | 11:f481ec642cc5 | 39 | |
shahidsajid | 12:954da4f4e565 | 40 | void Ball::set_pos(Vector2D p) |
shahidsajid | 12:954da4f4e565 | 41 | { |
shahidsajid | 12:954da4f4e565 | 42 | _x = p.x; |
shahidsajid | 12:954da4f4e565 | 43 | _y = p.y; |
shahidsajid | 12:954da4f4e565 | 44 | } |
shahidsajid | 23:a16c97a59a41 | 45 | */ |
shahidsajid | 15:81a3aaf52647 | 46 | int Ball::bowler_start(Gamepad &pad){ |
shahidsajid | 7:a1a6bff238c1 | 47 | if(_y1!=15){ |
shahidsajid | 12:954da4f4e565 | 48 | _y1+=1; |
shahidsajid | 7:a1a6bff238c1 | 49 | return 0; |
shahidsajid | 7:a1a6bff238c1 | 50 | } |
shahidsajid | 7:a1a6bff238c1 | 51 | else { |
shahidsajid | 15:81a3aaf52647 | 52 | if (set_tone==0){ |
shahidsajid | 15:81a3aaf52647 | 53 | //pad.tone(750.0,0.3); |
shahidsajid | 15:81a3aaf52647 | 54 | set_tone=1; |
shahidsajid | 15:81a3aaf52647 | 55 | } |
shahidsajid | 7:a1a6bff238c1 | 56 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 57 | } |
shahidsajid | 7:a1a6bff238c1 | 58 | } |
shahidsajid | 15:81a3aaf52647 | 59 | int Ball::ball_start(Gamepad &pad){ |
shahidsajid | 18:a260ce8db9e7 | 60 | |
shahidsajid | 15:81a3aaf52647 | 61 | int bowler_start_check=bowler_start(pad); |
shahidsajid | 10:6c6e09023942 | 62 | if (bowler_start_check==1){ |
shahidsajid | 9:a81db6a703b7 | 63 | if (_y!=36){ |
shahidsajid | 10:6c6e09023942 | 64 | _y+=1; |
shahidsajid | 10:6c6e09023942 | 65 | return 0; |
shahidsajid | 9:a81db6a703b7 | 66 | } |
shahidsajid | 10:6c6e09023942 | 67 | else{ |
shahidsajid | 7:a1a6bff238c1 | 68 | bowled=1; |
shahidsajid | 10:6c6e09023942 | 69 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 70 | } |
shahidsajid | 12:954da4f4e565 | 71 | } |
shahidsajid | 7:a1a6bff238c1 | 72 | } |
shahidsajid | 11:f481ec642cc5 | 73 | |
shahidsajid | 7:a1a6bff238c1 | 74 | void Ball::draw(N5110 &lcd) |
shahidsajid | 7:a1a6bff238c1 | 75 | { |
shahidsajid | 18:a260ce8db9e7 | 76 | char buffer[5]; |
shahidsajid | 18:a260ce8db9e7 | 77 | int c=get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 78 | int length=sprintf(buffer,"B%i",c); |
shahidsajid | 18:a260ce8db9e7 | 79 | lcd.printString(buffer,0,0); |
shahidsajid | 13:924891519a95 | 80 | lcd.drawCircle(_x1,_y1,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 81 | lcd.drawCircle(_x,_y,2,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 82 | //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 83 | } |
shahidsajid | 12:954da4f4e565 | 84 | |
shahidsajid | 14:122eaa3b7a50 | 85 | int Ball::update_ball(int expected_x,int expected_y){ |
shahidsajid | 12:954da4f4e565 | 86 | if (_y!=expected_y){ |
shahidsajid | 20:9d21599fe350 | 87 | if (_y>=expected_y){ |
shahidsajid | 12:954da4f4e565 | 88 | _y--; |
shahidsajid | 9:a81db6a703b7 | 89 | } |
shahidsajid | 12:954da4f4e565 | 90 | else{ |
shahidsajid | 12:954da4f4e565 | 91 | _y++; |
shahidsajid | 14:122eaa3b7a50 | 92 | } |
shahidsajid | 6:3e50f2cf4366 | 93 | } |
shahidsajid | 14:122eaa3b7a50 | 94 | if (_x!=expected_x){ |
shahidsajid | 20:9d21599fe350 | 95 | if (_x>expected_x) |
shahidsajid | 12:954da4f4e565 | 96 | _x--; |
shahidsajid | 12:954da4f4e565 | 97 | else{ |
shahidsajid | 12:954da4f4e565 | 98 | _x++; |
shahidsajid | 12:954da4f4e565 | 99 | } |
shahidsajid | 15:81a3aaf52647 | 100 | } |
shahidsajid | 15:81a3aaf52647 | 101 | printf(" %i %i %i %i \n",_x,expected_x,_y,expected_y); |
shahidsajid | 14:122eaa3b7a50 | 102 | if (_x==expected_x && _y==expected_y){ |
shahidsajid | 14:122eaa3b7a50 | 103 | return 1; |
shahidsajid | 12:954da4f4e565 | 104 | } |
shahidsajid | 14:122eaa3b7a50 | 105 | else{ |
shahidsajid | 14:122eaa3b7a50 | 106 | return 0; |
shahidsajid | 14:122eaa3b7a50 | 107 | } |
shahidsajid | 14:122eaa3b7a50 | 108 | } |
shahidsajid | 14:122eaa3b7a50 | 109 | |
shahidsajid | 18:a260ce8db9e7 | 110 | void Ball::reset_ball_count(){ |
shahidsajid | 18:a260ce8db9e7 | 111 | _ball_count=0; |
shahidsajid | 18:a260ce8db9e7 | 112 | } |
shahidsajid | 12:954da4f4e565 | 113 | |
shahidsajid | 12:954da4f4e565 | 114 | |
shahidsajid | 9:a81db6a703b7 | 115 | void Ball::reset(){ |
shahidsajid | 9:a81db6a703b7 | 116 | bowled=0; |
shahidsajid | 9:a81db6a703b7 | 117 | ballHit=0; |
shahidsajid | 14:122eaa3b7a50 | 118 | _x1=42; |
shahidsajid | 14:122eaa3b7a50 | 119 | _y1=3; |
shahidsajid | 14:122eaa3b7a50 | 120 | _x = 42; |
shahidsajid | 14:122eaa3b7a50 | 121 | _y = 15; |
shahidsajid | 15:81a3aaf52647 | 122 | set_tone=0; |
shahidsajid | 18:a260ce8db9e7 | 123 | //_ball_count=0; |
shahidsajid | 9:a81db6a703b7 | 124 | } |
shahidsajid | 9:a81db6a703b7 | 125 | |
shahidsajid | 12:954da4f4e565 | 126 |