]> git.seodisparate.com - LD53/commitdiff
Add "Wrong House"
authorStephen Seo <seo.disparate@gmail.com>
Sun, 30 Apr 2023 08:24:39 +0000 (17:24 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sun, 30 Apr 2023 08:24:39 +0000 (17:24 +0900)
src/world.rs

index a767f5adef2ca9cc220eda0d03acc4fbb95a2da1..dd4957d5d6a02daf5afdfe028c810d96f30822f8 100644 (file)
@@ -16,14 +16,16 @@ enum Building {
     House,
     SpeedUp,
     SlowDown,
+    WrongHouse,
 }
 
 impl Building {
     pub fn random(rand: &mut StdRand) -> Self {
-        match rand.next_u16() % 20 {
+        match rand.next_u16() % 30 {
             0..=9 => Building::House,
             10..=14 => Building::SpeedUp,
             15..=19 => Building::SlowDown,
+            20..=29 => Building::WrongHouse,
             _ => unreachable!(),
         }
     }
@@ -143,6 +145,12 @@ impl World {
                 self.building.take();
                 self.status_text = Some(("It's OK!\nKeep delivering!", 80));
                 self.is_in_range = false;
+            } else if building_type == Building::WrongHouse && *pos_ref < -(HOUSE0_WIDTH as f32) {
+                if self.is_in_range {
+                    self.status_text = Some(("OK!\nKeep going!", 80));
+                }
+                self.building.take();
+                self.is_in_range = false;
             }
         }
 
@@ -173,6 +181,14 @@ impl World {
                         self.building.take();
                         self.music.slow_down();
                     }
+                    Building::WrongHouse => {
+                        self.rate_multiplier /= SLOWDOWN_DIV;
+                        if self.rate_multiplier < 1f32 {
+                            self.rate_multiplier = 1f32;
+                        }
+                        self.status_text = Some(("Oh no!\nSlow down!", 80));
+                        self.music.slow_down();
+                    }
                 }
                 self.music.start();
             }
@@ -220,6 +236,14 @@ impl World {
 
         if let Some((x, building_type, state)) = &self.building {
             match building_type {
+                Building::WrongHouse => crate::blit(
+                    &HOUSE0,
+                    round_f32_to_i32(*x),
+                    30,
+                    HOUSE0_WIDTH,
+                    HOUSE0_HEIGHT,
+                    HOUSE0_FLAGS,
+                ),
                 Building::House => match state {
                     0 => crate::blit(
                         &HOUSE1,
@@ -268,7 +292,11 @@ impl World {
             unsafe {
                 *crate::DRAW_COLORS = 0x1;
             }
-            crate::text("Tap or Press X!", 5, 5);
+            if let Some((_, Building::WrongHouse, _)) = self.building {
+                crate::text("Don't Press!", 5, 5);
+            } else {
+                crate::text("Tap or Press X!", 5, 5);
+            }
         }
 
         unsafe {