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@3:f86c1cf90d0d, 2020-04-27 (annotated)
- Committer:
- KaifK
- Date:
- Mon Apr 27 21:58:35 2020 +0000
- Revision:
- 3:f86c1cf90d0d
- Parent:
- 2:21973e665a32
- Child:
- 4:08a0ff6668df
Splash screen files first draft complete, added info screen and game title animation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KaifK | 2:21973e665a32 | 1 | #include "Ball.h" |
KaifK | 2:21973e665a32 | 2 | |
KaifK | 2:21973e665a32 | 3 | const int ball[3][11][15] = { |
KaifK | 2:21973e665a32 | 4 | {{0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 5 | {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, |
KaifK | 2:21973e665a32 | 6 | {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, |
KaifK | 2:21973e665a32 | 7 | {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, |
KaifK | 2:21973e665a32 | 8 | {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, |
KaifK | 2:21973e665a32 | 9 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
KaifK | 2:21973e665a32 | 10 | {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, |
KaifK | 2:21973e665a32 | 11 | {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, |
KaifK | 2:21973e665a32 | 12 | {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, |
KaifK | 2:21973e665a32 | 13 | {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, |
KaifK | 2:21973e665a32 | 14 | {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}}, |
KaifK | 2:21973e665a32 | 15 | |
KaifK | 2:21973e665a32 | 16 | {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 17 | {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 18 | {0,0,0,0,1,0,0,1,0,0,1,0,0,0,0}, |
KaifK | 2:21973e665a32 | 19 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, |
KaifK | 2:21973e665a32 | 20 | {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, |
KaifK | 2:21973e665a32 | 21 | {0,0,1,1,1,1,1,1,1,1,1,1,1,0,0}, |
KaifK | 2:21973e665a32 | 22 | {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, |
KaifK | 2:21973e665a32 | 23 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, |
KaifK | 2:21973e665a32 | 24 | {0,0,0,0,1,0,1,1,1,0,1,0,0,0,0}, |
KaifK | 2:21973e665a32 | 25 | {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 26 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}, |
KaifK | 2:21973e665a32 | 27 | |
KaifK | 2:21973e665a32 | 28 | {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 29 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 30 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 31 | {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 32 | {0,0,0,0,0,1,0,1,0,1,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 33 | {0,0,0,0,1,1,1,1,1,1,1,0,0,0,0}, |
KaifK | 2:21973e665a32 | 34 | {0,0,0,0,0,1,0,1,0,1,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 35 | {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 36 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 37 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
KaifK | 2:21973e665a32 | 38 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}, |
KaifK | 2:21973e665a32 | 39 | }; |
KaifK | 2:21973e665a32 | 40 | |
KaifK | 2:21973e665a32 | 41 | Ball::Ball() { |
KaifK | 2:21973e665a32 | 42 | |
KaifK | 2:21973e665a32 | 43 | } |
KaifK | 2:21973e665a32 | 44 | |
KaifK | 2:21973e665a32 | 45 | Ball::~Ball() { |
KaifK | 2:21973e665a32 | 46 | |
KaifK | 2:21973e665a32 | 47 | } |
KaifK | 2:21973e665a32 | 48 | |
KaifK | 2:21973e665a32 | 49 | void Ball::init(N5110 &lcd) { |
KaifK | 2:21973e665a32 | 50 | _ball_x = BALL_INIT_X; |
KaifK | 2:21973e665a32 | 51 | _ball_y = BALL_INIT_Y; |
KaifK | 2:21973e665a32 | 52 | lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball); |
KaifK | 2:21973e665a32 | 53 | } |
KaifK | 3:f86c1cf90d0d | 54 | void Ball::setLocation(int x, int y,N5110 &lcd) { |
KaifK | 2:21973e665a32 | 55 | lcd.drawSprite(x,y,11,15,(int *)ball); |
KaifK | 2:21973e665a32 | 56 | } |
KaifK | 3:f86c1cf90d0d | 57 | void Ball::playShot(int user_input_x, int user_input_y,N5110 &lcd) { |
KaifK | 2:21973e665a32 | 58 | _user_input_x = user_input_x; |
KaifK | 2:21973e665a32 | 59 | _user_input_y = user_input_y; |
KaifK | 3:f86c1cf90d0d | 60 | int i = 0; |
KaifK | 3:f86c1cf90d0d | 61 | int kar = 0; |
KaifK | 3:f86c1cf90d0d | 62 | while(_user_input_x < _ball_x || _user_input_y < _ball_y) { |
KaifK | 3:f86c1cf90d0d | 63 | |
KaifK | 3:f86c1cf90d0d | 64 | if(_user_input_x < _ball_x ) { _ball_x -=2.5;} |
KaifK | 3:f86c1cf90d0d | 65 | else if(_user_input_x > _ball_x ) { _ball_x +=2.5;} |
KaifK | 2:21973e665a32 | 66 | |
KaifK | 3:f86c1cf90d0d | 67 | if(_user_input_y < _ball_y ) { _ball_y -=2.5;} |
KaifK | 3:f86c1cf90d0d | 68 | else if(_user_input_y > _ball_y ) { _ball_y +=2.5;} |
KaifK | 3:f86c1cf90d0d | 69 | lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball[kar]); |
KaifK | 3:f86c1cf90d0d | 70 | |
KaifK | 3:f86c1cf90d0d | 71 | if(i == 4) {kar = 0;} |
KaifK | 3:f86c1cf90d0d | 72 | if(i == 6) {kar = 1;} |
KaifK | 3:f86c1cf90d0d | 73 | if(i == 8) {kar = 2;} |
KaifK | 3:f86c1cf90d0d | 74 | printf("%d \n",i); |
KaifK | 3:f86c1cf90d0d | 75 | i++; |
KaifK | 3:f86c1cf90d0d | 76 | wait_ms(100); |
KaifK | 2:21973e665a32 | 77 | |
KaifK | 3:f86c1cf90d0d | 78 | lcd.refresh(); |
KaifK | 2:21973e665a32 | 79 | } |
KaifK | 2:21973e665a32 | 80 | } |