WIP game is done but needs polish
This commit is contained in:
parent
1f5d533dac
commit
95a78b5b2d
5 changed files with 53 additions and 25 deletions
|
@ -37,8 +37,10 @@ constexpr float MAX_FOOD_WH = 500.0F;
|
|||
|
||||
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;
|
||||
|
@ -48,9 +50,9 @@ constexpr float CUT_RATE = 0.7F;
|
|||
|
||||
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;
|
||||
|
||||
|
|
36
src/game.cc
36
src/game.cc
|
@ -10,8 +10,9 @@
|
|||
|
||||
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);
|
||||
|
||||
|
@ -28,18 +29,7 @@ void Game::update_impl() {
|
|||
|
||||
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;
|
||||
|
@ -165,6 +155,10 @@ void Game::draw_impl() {
|
|||
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(
|
||||
|
@ -197,15 +191,20 @@ void Game::draw_impl() {
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -218,6 +217,10 @@ void Game::reset(bool wasGameOver) {
|
|||
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;
|
||||
}
|
||||
|
@ -226,7 +229,8 @@ void Game::reset(bool wasGameOver) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ private:
|
|||
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
|
||||
|
|
|
@ -47,8 +47,19 @@ void Helpers::draw_blinking_eye(float x, float y, float radius) {
|
|||
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,
|
||||
|
@ -61,13 +72,19 @@ 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,
|
||||
|
|
|
@ -7,12 +7,15 @@ namespace Helpers {
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue