constexpr float EYE_RADIUS = 14.0F;
constexpr float BLINKING_EYE_SIZE = 4.0F;
+constexpr float X_EYE_SIZE = 4.0F;
constexpr float MOUTH_RADIUS = 20.0F;
+constexpr float OPEN_MOUTH_RADIUS = 16.0F;
constexpr float MIN_BLINK_TIME = 1.0F;
constexpr float MAX_BLINK_TIME = 20.0F;
constexpr float CUT_TIMER_RATE_INC_AMT = 0.1F;
-constexpr float SPLIT_DX = 60.0F;
-constexpr float SPLIT_DY = 100.0F;
-constexpr float SPLIT_DA = 80.0F;
+constexpr float SPLIT_DX = 80.0F;
+constexpr float SPLIT_DY = 120.0F;
+constexpr float SPLIT_DA = 100.0F;
constexpr float POST_CUT_TIME = 1.7F;
Game::Game()
: re(std::random_device{}()), dist(0, FOOD_COUNT - 1), score(0),
- areaSizeRatio(1.0F), currentFood(dist(re)), blinkTimer(10.0F),
- cutTimer(0.0F), cutTimerRateInc(1.0F), postCutTimer(0.0F) {
+ highScore(0), areaSizeRatio(1.0F), currentFood(dist(re)),
+ blinkTimer(10.0F), cutTimer(0.0F), cutTimerRateInc(1.0F),
+ postCutTimer(0.0F) {
flags.set(0);
flags.set(3);
if (flags.test(0)) {
flags.set(0);
- scoreString.clear();
- if (score == 0) {
- scoreString.push_back('0');
- } else {
- std::string temp;
- for (unsigned long long i = score; i > 0; i /= 10) {
- temp.push_back((i % 10) + '0');
- }
- for (int i = temp.size(); i-- > 0;) {
- scoreString.push_back(temp[i]);
- }
- }
+ scoreString = std::string("Score: ") + std::to_string(score);
}
blinkTimer -= dt;
int coords[4];
Helpers::get_fruit_coords(coords, (FoodType)currentFood);
+ DrawRectangle(0, 0, GetScreenWidth(), offsetY, {160, 160, 160, 255});
+ DrawRectangle(0, offsetY + height, GetScreenWidth(),
+ GetScreenHeight() - (offsetY + height), {160, 160, 160, 255});
+
if (flags.test(6)) {
// bottom portion
DrawTexturePro(
Helpers::draw_eyes_full(offsetX + width / 2.0F, offsetY + height / 2.0F,
width, height, EYE_RADIUS, (FoodType)currentFood,
- flags.test(1));
+ flags.test(1), flags.test(5));
if (flags.test(2)) {
Helpers::draw_happy_mouth(offsetX + width / 2.0F,
offsetY + height / 2.0F * 1.1F, width,
MOUTH_RADIUS, (FoodType)currentFood);
+ } else if (flags.test(4) && !flags.test(5)) {
+ Helpers::draw_open_mouth(offsetX + width / 2.0F,
+ offsetY + height / 2.0F * 1.1F, width,
+ OPEN_MOUTH_RADIUS, (FoodType)currentFood);
}
DrawText(scoreString.c_str(), 2, 2, 32, BLACK);
+ DrawText(highScoreString.c_str(), 2, 34, 32, BLACK);
EndDrawing();
}
flags.reset(5);
flags.reset(6);
if (wasGameOver) {
+ if (score > highScore) {
+ highScore = score;
+ highScoreString = std::string("High score: ") + std::to_string(highScore);
+ }
score = 0;
cutTimerRateInc = 1.0F;
}
while (prevFood == currentFood) {
currentFood = dist(re);
}
- blinkTimer = 10.0F;
+ blinkTimer =
+ std::uniform_real_distribution<float>{MIN_BLINK_TIME, MAX_BLINK_TIME}(re);
cutTimer = std::uniform_real_distribution<float>(0.0F, 1.0F)(re);
postCutTimer = 0.0F;
}
std::default_random_engine re;
std::uniform_int_distribution<unsigned int> dist;
std::string scoreString;
+ std::string highScoreString;
Texture2D spriteSheet;
unsigned long long score;
+ unsigned long long highScore;
/*
* 0 - score dirty
* 1 - is blinking
DrawLineEx({x - radius, y}, {x + radius, y}, BLINKING_EYE_SIZE, BLACK);
}
-void Helpers::draw_open_mouth(float x, float y, float radius) {
- DrawCircle(x, y, radius, BLACK);
+void Helpers::draw_x_eye(float x, float y, float radius) {
+ DrawLineEx({x - radius, y - radius}, {x + radius, y + radius}, X_EYE_SIZE,
+ BLACK);
+ DrawLineEx({x - radius, y + radius}, {x + radius, y - radius}, X_EYE_SIZE,
+ BLACK);
+}
+
+void Helpers::draw_open_mouth(float x, float y, float width, float radius,
+ FoodType foodType) {
+ float offsets[2];
+ internal_get_offsets(offsets, foodType);
+
+ DrawCircle(x + offsets[0] * width, y, radius, BLACK);
}
void Helpers::draw_happy_mouth(float x, float y, float width, float radius,
}
void Helpers::draw_eyes_full(float x, float y, float width, float height,
- float radius, FoodType foodType, bool isBlinking) {
+ float radius, FoodType foodType, bool isBlinking,
+ bool isX) {
float offsets[2];
internal_get_offsets(offsets, foodType);
const float eye_width = width * EYE_WIDTH_RATIO;
- if (isBlinking) {
+ if (isX) {
+ draw_x_eye(x - eye_width / 2.0F + offsets[0] * width,
+ y + offsets[1] * height, radius);
+ draw_x_eye(x + eye_width / 2.0F + offsets[0] * width,
+ y + offsets[1] * height, radius);
+ } else if (isBlinking) {
draw_blinking_eye(x - eye_width / 2.0F + offsets[0] * width,
y + offsets[1] * height, radius);
draw_blinking_eye(x + eye_width / 2.0F + offsets[0] * width,
extern void draw_eye(float x, float y, float radius);
extern void draw_blinking_eye(float x, float y, float radius);
-extern void draw_open_mouth(float x, float y, float radius);
+extern void draw_x_eye(float x, float y, float radius);
+extern void draw_open_mouth(float x, float y, float width, float radius,
+ FoodType foodType);
extern void draw_happy_mouth(float x, float y, float width, float radius,
FoodType foodType);
extern void draw_eyes_full(float x, float y, float width, float height,
- float radius, FoodType foodType, bool isBlinking);
+ float radius, FoodType foodType, bool isBlinking,
+ bool isX);
extern float get_cut_pos(float timer, FoodType foodType);