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@13:924891519a95, 2019-04-23 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue Apr 23 14:35:39 2019 +0000
- Revision:
- 13:924891519a95
- Parent:
- 12:954da4f4e565
- Child:
- 14:122eaa3b7a50
Created a method check_fielder() to check for collisions
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 | 6:3e50f2cf4366 | 20 | bat.init(3,4); |
shahidsajid | 9:a81db6a703b7 | 21 | bowled=0; |
shahidsajid | 3:bd3465a70a5a | 22 | |
shahidsajid | 3:bd3465a70a5a | 23 | } |
shahidsajid | 12:954da4f4e565 | 24 | Vector2D Ball::get_pos() |
shahidsajid | 12:954da4f4e565 | 25 | { |
shahidsajid | 12:954da4f4e565 | 26 | Vector2D p = {_x,_y}; |
shahidsajid | 12:954da4f4e565 | 27 | return p; |
shahidsajid | 12:954da4f4e565 | 28 | } |
shahidsajid | 11:f481ec642cc5 | 29 | |
shahidsajid | 12:954da4f4e565 | 30 | void Ball::set_pos(Vector2D p) |
shahidsajid | 12:954da4f4e565 | 31 | { |
shahidsajid | 12:954da4f4e565 | 32 | _x = p.x; |
shahidsajid | 12:954da4f4e565 | 33 | _y = p.y; |
shahidsajid | 12:954da4f4e565 | 34 | } |
shahidsajid | 7:a1a6bff238c1 | 35 | int Ball::bowler_start(){ |
shahidsajid | 7:a1a6bff238c1 | 36 | if(_y1!=15){ |
shahidsajid | 12:954da4f4e565 | 37 | _y1+=1; |
shahidsajid | 7:a1a6bff238c1 | 38 | return 0; |
shahidsajid | 7:a1a6bff238c1 | 39 | } |
shahidsajid | 7:a1a6bff238c1 | 40 | else { |
shahidsajid | 7:a1a6bff238c1 | 41 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 42 | } |
shahidsajid | 7:a1a6bff238c1 | 43 | } |
shahidsajid | 11:f481ec642cc5 | 44 | int Ball::ball_start(){ |
shahidsajid | 10:6c6e09023942 | 45 | int bowler_start_check=bowler_start(); |
shahidsajid | 10:6c6e09023942 | 46 | if (bowler_start_check==1){ |
shahidsajid | 9:a81db6a703b7 | 47 | if (_y!=36){ |
shahidsajid | 10:6c6e09023942 | 48 | _y+=1; |
shahidsajid | 10:6c6e09023942 | 49 | return 0; |
shahidsajid | 9:a81db6a703b7 | 50 | } |
shahidsajid | 10:6c6e09023942 | 51 | else{ |
shahidsajid | 7:a1a6bff238c1 | 52 | bowled=1; |
shahidsajid | 10:6c6e09023942 | 53 | return 1; |
shahidsajid | 7:a1a6bff238c1 | 54 | } |
shahidsajid | 12:954da4f4e565 | 55 | } |
shahidsajid | 7:a1a6bff238c1 | 56 | } |
shahidsajid | 11:f481ec642cc5 | 57 | |
shahidsajid | 7:a1a6bff238c1 | 58 | void Ball::draw(N5110 &lcd) |
shahidsajid | 7:a1a6bff238c1 | 59 | { |
shahidsajid | 13:924891519a95 | 60 | lcd.drawCircle(_x1,_y1,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 61 | lcd.drawCircle(_x,_y,2,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 62 | //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); |
shahidsajid | 7:a1a6bff238c1 | 63 | } |
shahidsajid | 12:954da4f4e565 | 64 | |
shahidsajid | 12:954da4f4e565 | 65 | void Ball::update_ball_y(int expected_y){ |
shahidsajid | 12:954da4f4e565 | 66 | if (_y!=expected_y){ |
shahidsajid | 12:954da4f4e565 | 67 | printf("IN HERE \n"); |
shahidsajid | 12:954da4f4e565 | 68 | if (_y>expected_y){ |
shahidsajid | 12:954da4f4e565 | 69 | printf("MADE IT \n"); |
shahidsajid | 12:954da4f4e565 | 70 | _y--; |
shahidsajid | 9:a81db6a703b7 | 71 | } |
shahidsajid | 12:954da4f4e565 | 72 | else{ |
shahidsajid | 12:954da4f4e565 | 73 | _y++; |
shahidsajid | 6:3e50f2cf4366 | 74 | } |
shahidsajid | 6:3e50f2cf4366 | 75 | } |
shahidsajid | 3:bd3465a70a5a | 76 | } |
shahidsajid | 12:954da4f4e565 | 77 | void Ball::update_ball_x(int expected_x){ |
shahidsajid | 12:954da4f4e565 | 78 | if (_x!=expected_x){ |
shahidsajid | 12:954da4f4e565 | 79 | if (_x>expected_x){ |
shahidsajid | 12:954da4f4e565 | 80 | _x--; |
shahidsajid | 12:954da4f4e565 | 81 | } |
shahidsajid | 12:954da4f4e565 | 82 | else{ |
shahidsajid | 12:954da4f4e565 | 83 | _x++; |
shahidsajid | 12:954da4f4e565 | 84 | } |
shahidsajid | 12:954da4f4e565 | 85 | } |
shahidsajid | 12:954da4f4e565 | 86 | } |
shahidsajid | 12:954da4f4e565 | 87 | |
shahidsajid | 12:954da4f4e565 | 88 | |
shahidsajid | 12:954da4f4e565 | 89 | |
shahidsajid | 12:954da4f4e565 | 90 | |
shahidsajid | 12:954da4f4e565 | 91 | |
shahidsajid | 9:a81db6a703b7 | 92 | void Ball::reset(){ |
shahidsajid | 9:a81db6a703b7 | 93 | bowled=0; |
shahidsajid | 9:a81db6a703b7 | 94 | ballHit=0; |
shahidsajid | 9:a81db6a703b7 | 95 | } |
shahidsajid | 9:a81db6a703b7 | 96 | |
shahidsajid | 12:954da4f4e565 | 97 |