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@15:81a3aaf52647, 2019-04-24 (annotated)
- Committer:
- shahidsajid
- Date:
- Wed Apr 24 21:17:22 2019 +0000
- Revision:
- 15:81a3aaf52647
- Parent:
- 14:122eaa3b7a50
- Child:
- 17:b2b651acffae
- Child:
- 18:a260ce8db9e7
Created a few starting menus; Created a tone for when bowler starts and batsman is out
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 | 15:81a3aaf52647 | 20 | set_tone=0; |
shahidsajid | 6:3e50f2cf4366 | 21 | bat.init(3,4); |
shahidsajid | 9:a81db6a703b7 | 22 | bowled=0; |
shahidsajid | 3:bd3465a70a5a | 23 | |
shahidsajid | 3:bd3465a70a5a | 24 | } |
shahidsajid | 12:954da4f4e565 | 25 | Vector2D Ball::get_pos() |
shahidsajid | 12:954da4f4e565 | 26 | { |
shahidsajid | 12:954da4f4e565 | 27 | Vector2D p = {_x,_y}; |
shahidsajid | 12:954da4f4e565 | 28 | return p; |
shahidsajid | 12:954da4f4e565 | 29 | } |
shahidsajid | 11:f481ec642cc5 | 30 | |
shahidsajid | 12:954da4f4e565 | 31 | void Ball::set_pos(Vector2D p) |
shahidsajid | 12:954da4f4e565 | 32 | { |
shahidsajid | 12:954da4f4e565 | 33 | _x = p.x; |
shahidsajid | 12:954da4f4e565 | 34 | _y = p.y; |
shahidsajid | 12:954da4f4e565 | 35 | } |
shahidsajid | 15:81a3aaf52647 | 36 | int Ball::bowler_start(Gamepad &pad){ |
shahidsajid | 7:a1a6bff238c1 | 37 | if(_y1!=15){ |
shahidsajid | 12:954da4f4e565 | 38 | _y1+=1; |
shahidsajid | 7:a1a6bff238c1 | 39 | return 0; |
shahidsajid | 7:a1a6bff238c1 | 40 | } |
shahidsajid | 7:a1a6bff238c1 | 41 | else { |
shahidsajid | 15:81a3aaf52647 | 42 | if (set_tone==0){ |
shahidsajid | 15:81a3aaf52647 | 43 | //pad.tone(750.0,0.3); |
shahidsajid | 15:81a3aaf52647 | 44 | set_tone=1; |
shahidsajid | 15:81a3aaf52647 | 45 | } |
shahidsajid | 7:a1a6bff238c1 | 46 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 47 | } |
shahidsajid | 7:a1a6bff238c1 | 48 | } |
shahidsajid | 15:81a3aaf52647 | 49 | int Ball::ball_start(Gamepad &pad){ |
shahidsajid | 15:81a3aaf52647 | 50 | int bowler_start_check=bowler_start(pad); |
shahidsajid | 10:6c6e09023942 | 51 | if (bowler_start_check==1){ |
shahidsajid | 9:a81db6a703b7 | 52 | if (_y!=36){ |
shahidsajid | 10:6c6e09023942 | 53 | _y+=1; |
shahidsajid | 10:6c6e09023942 | 54 | return 0; |
shahidsajid | 9:a81db6a703b7 | 55 | } |
shahidsajid | 10:6c6e09023942 | 56 | else{ |
shahidsajid | 7:a1a6bff238c1 | 57 | bowled=1; |
shahidsajid | 10:6c6e09023942 | 58 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 59 | } |
shahidsajid | 12:954da4f4e565 | 60 | } |
shahidsajid | 7:a1a6bff238c1 | 61 | } |
shahidsajid | 11:f481ec642cc5 | 62 | |
shahidsajid | 7:a1a6bff238c1 | 63 | void Ball::draw(N5110 &lcd) |
shahidsajid | 7:a1a6bff238c1 | 64 | { |
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 | 12:954da4f4e565 | 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 | 12:954da4f4e565 | 80 | if (_x>expected_x){ |
shahidsajid | 12:954da4f4e565 | 81 | _x--; |
shahidsajid | 12:954da4f4e565 | 82 | } |
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 | 12:954da4f4e565 | 96 | |
shahidsajid | 12:954da4f4e565 | 97 | |
shahidsajid | 12:954da4f4e565 | 98 | |
shahidsajid | 12:954da4f4e565 | 99 | |
shahidsajid | 12:954da4f4e565 | 100 | |
shahidsajid | 9:a81db6a703b7 | 101 | void Ball::reset(){ |
shahidsajid | 9:a81db6a703b7 | 102 | bowled=0; |
shahidsajid | 9:a81db6a703b7 | 103 | ballHit=0; |
shahidsajid | 14:122eaa3b7a50 | 104 | _x1=42; |
shahidsajid | 14:122eaa3b7a50 | 105 | _y1=3; |
shahidsajid | 14:122eaa3b7a50 | 106 | _x = 42; |
shahidsajid | 14:122eaa3b7a50 | 107 | _y = 15; |
shahidsajid | 15:81a3aaf52647 | 108 | set_tone=0; |
shahidsajid | 9:a81db6a703b7 | 109 | } |
shahidsajid | 9:a81db6a703b7 | 110 | |
shahidsajid | 12:954da4f4e565 | 111 |