select difficulty level (when play against bot) using a dedicated frame to show a graphics menu
This commit is contained in:
24
src/font.cpp
24
src/font.cpp
@@ -212,3 +212,27 @@ const byte frame_cvc[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||
};
|
||||
|
||||
const byte (*frame_gmodes[3])[12]= {frame_pvp, frame_pvc, frame_cvc};
|
||||
|
||||
const byte frame_bot_skill_easy[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||
{ 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, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
|
||||
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
|
||||
{ 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 },
|
||||
{ 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 },
|
||||
{ 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
const byte frame_bot_skill_hard[MATRIX_HEIGHT][MATRIX_WIDTH] = {
|
||||
{ 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, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
|
||||
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
|
||||
{ 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 },
|
||||
{ 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0 },
|
||||
{ 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
const byte (*frame_bot_skills[3])[12]= {frame_bot_skill_easy, frame_bot_skill_hard};
|
||||
|
||||
@@ -13,4 +13,8 @@ extern const byte frame_pvc[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||
extern const byte frame_cvc[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||
extern const byte (*frame_gmodes[3])[12];
|
||||
|
||||
extern const byte frame_bot_skill_easy[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||
extern const byte frame_bot_skill_hard[MATRIX_HEIGHT][MATRIX_WIDTH];
|
||||
extern const byte (*frame_bot_skills[3])[12];
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,10 +44,14 @@ bool Paddle::check_pad_movement(Ball &ball) {
|
||||
// redefine me
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t Paddle::get_skills() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Paddle::set_skills(uint8_t skills) {
|
||||
}
|
||||
|
||||
bool HumanPaddle::check_pad_movement() {
|
||||
bool need_refresh= false;
|
||||
if (digitalRead(_pin_btn_top) == LOW) {
|
||||
@@ -66,6 +70,8 @@ bool BotPaddle::check_pad_movement(Ball &ball) {
|
||||
int8_t ball_dir= ball.get_direction_x();
|
||||
int8_t ball_dir_ver= ball.get_direction_y();
|
||||
|
||||
uint8_t skills= this -> get_skills();
|
||||
|
||||
// ball is moving left and pad is on right, do not move
|
||||
if (ball_dir < 0 && _pos_x > MATRIX_WIDTH / 2) return false;
|
||||
// ball is moving right and pad is on left, do not move
|
||||
@@ -74,18 +80,18 @@ bool BotPaddle::check_pad_movement(Ball &ball) {
|
||||
uint8_t ball_x= ball.get_x();
|
||||
int8_t ball_distance= ball_x - _pos_x;
|
||||
if (ball_distance < 0) ball_distance *= -1;
|
||||
switch (this -> get_skills()) {
|
||||
switch (skills) {
|
||||
case 1:
|
||||
if (ball_distance > 2) return false;
|
||||
if (ball_distance > 3) return false;
|
||||
break;
|
||||
case 2:
|
||||
if (ball_distance > 3) return false;
|
||||
if (ball_distance > 4) return false;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO BotPaddle movement logics
|
||||
// on higher difficult level i could also check the ball direction
|
||||
// or at lover difficulty level i could also check the distance from the pad and move only when the ball si near
|
||||
uint8_t move_chances= random(skills * 10) % 2;
|
||||
if (!move_chances) return false;
|
||||
|
||||
enum Movement {NONE, UP, DOWN};
|
||||
Movement _movment= NONE;
|
||||
|
||||
@@ -113,3 +119,9 @@ bool BotPaddle::check_pad_movement(Ball &ball) {
|
||||
uint8_t BotPaddle::get_skills() {
|
||||
return _skills;
|
||||
}
|
||||
|
||||
void BotPaddle::set_skills(uint8_t skills) {
|
||||
if (skills < 0) _skills= 0;
|
||||
else if (skills > 1) _skills= 1;
|
||||
else _skills= skills;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class Paddle {
|
||||
virtual bool check_pad_movement();
|
||||
virtual bool check_pad_movement(Ball &ball);
|
||||
virtual uint8_t get_skills();
|
||||
virtual void set_skills(uint8_t skills);
|
||||
};
|
||||
|
||||
class HumanPaddle : public Paddle {
|
||||
@@ -46,13 +47,11 @@ class BotPaddle : public Paddle {
|
||||
uint8_t _skills; // this is the difficulty level
|
||||
|
||||
public:
|
||||
BotPaddle(uint8_t position, uint8_t pos_x, uint8_t skills)
|
||||
: Paddle(position, false), _pos_x(pos_x), _skills(skills) {
|
||||
if (_skills < 1) _skills= 1;
|
||||
if (_skills > 2) _skills= 2;
|
||||
}
|
||||
BotPaddle(uint8_t position, uint8_t pos_x)
|
||||
: Paddle(position, false), _pos_x(pos_x) {}
|
||||
bool check_pad_movement(Ball &ball);
|
||||
uint8_t get_skills();
|
||||
void set_skills(uint8_t skills);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user