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
Diff: Ball/Ball.cpp
- Revision:
- 2:21973e665a32
- Child:
- 3:f86c1cf90d0d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ball/Ball.cpp Sat Apr 25 21:56:30 2020 +0000 @@ -0,0 +1,79 @@ +#include "Ball.h" + +const int ball[3][11][15] = { + {{0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, + {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, + {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, + {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, + {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, + {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, + {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, + {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, + {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}}, + + {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, + {0,0,0,0,1,0,0,1,0,0,1,0,0,0,0}, + {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, + {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, + {0,0,1,1,1,1,1,1,1,1,1,1,1,0,0}, + {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, + {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, + {0,0,0,0,1,0,1,1,1,0,1,0,0,0,0}, + {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}, + + {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}, + {0,0,0,0,0,1,0,1,0,1,0,0,0,0,0}, + {0,0,0,0,1,1,1,1,1,1,1,0,0,0,0}, + {0,0,0,0,0,1,0,1,0,1,0,0,0,0,0}, + {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}, +}; + +Ball::Ball() { + + } + +Ball::~Ball() { + + } + +void Ball::init(N5110 &lcd) { + _ball_x = BALL_INIT_X; + _ball_y = BALL_INIT_Y; + lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball); + } +void Ball::set_location(int x, int y,N5110 &lcd) { + lcd.drawSprite(x,y,11,15,(int *)ball); + } +void Ball::play_shot_animation(int user_input_x, int user_input_y,N5110 &lcd) { + _user_input_x = user_input_x; + _user_input_y = user_input_y; + int j = 0; + + while(_user_input_x != _ball_x || _user_input_y != _ball_y) { + for(int i = 0; i < 12; i++ ) { + if(_user_input_x < _ball_x ) { _ball_x --;} + else if(_user_input_x > _ball_x ) { _ball_x ++;} + + if(_user_input_y < _ball_y ) { _ball_y --;} + else if(_user_input_y > _ball_y ) { _ball_y ++;} + lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball[j]); + + + if(i == 4) {j = 0;} + if(i == 8) {j = 1;} + if(i == 12) {j = 2;} + break; + } + wait_ms(50); + } + } \ No newline at end of file