]> git.seodisparate.com - LD52/commitdiff
WIP game is done but needs polish
authorStephen Seo <seo.disparate@gmail.com>
Sat, 7 Jan 2023 07:35:29 +0000 (16:35 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 7 Jan 2023 07:35:29 +0000 (16:35 +0900)
src/constants.h
src/game.cc
src/game.h
src/helpers.cc
src/helpers.h

index 39ec957c99574f2ab113c77ea9a05a527c83a651..60cee0922f8dc55ca5ef7bf463bcfae3b5417f46 100644 (file)
@@ -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;
 
index df07ab1aed4e22749783858558ffc9abf9413d37..93bea65f78972700ae19f7c3c8d0039ab0a18439 100644 (file)
@@ -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;
 }
index 539426a3e28eee29edbb1ae5768cb063e7bd0540..324e7195c8875f677b113c71d6f6cb29da63e12f 100644 (file)
@@ -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
index e8513805e31db8b1295e9b5d0d413350ccccf66e..428d39af35e53f65a620b95e04f7f2e20bffaabd 100644 (file)
@@ -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,
index 02082942b9031ec69cbf8b552a0d3bae44acd807..968eea894baeb068fa5a1b433ffb35459e953683 100644 (file)
@@ -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);