From d676116fd8509a06a16a7b93e615fe3598911ad2 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 16 Sep 2021 21:26:57 -0600 Subject: [PATCH] Added the feature where if you kick a bug, you get a Firo coin to the right that you can collect. --- lib/bug_holder.dart | 3 ++- lib/coin_holder.dart | 15 +++++++++------ lib/debris_holder.dart | 3 ++- lib/main.dart | 10 +++++----- lib/runner.dart | 2 ++ lib/wall_holder.dart | 3 ++- lib/wire_holder.dart | 3 ++- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/bug_holder.dart b/lib/bug_holder.dart index 3cb290e..d177f23 100644 --- a/lib/bug_holder.dart +++ b/lib/bug_holder.dart @@ -25,7 +25,8 @@ class BugHolder extends Holder { } } - bool generateBug(MyGame gameRef, int level, bool force) { + bool generateBug(MyGame gameRef, int level, + {bool force = false, double xPosition = 0}) { if (objects[level].isNotEmpty) { return false; } diff --git a/lib/coin_holder.dart b/lib/coin_holder.dart index 107a768..59cbce4 100644 --- a/lib/coin_holder.dart +++ b/lib/coin_holder.dart @@ -18,16 +18,17 @@ class CoinHolder extends Holder { return coin; } - bool generateCoin(MyGame gameRef, int level, bool force) { - if (total() > 5) { + bool generateCoin(MyGame gameRef, int level, + {bool force = false, double xPosition = 0}) { + if (total() > 5 && !force) { return false; } - if (objects[level].isNotEmpty) { + if (objects[level].isNotEmpty && !force) { return false; } - if (random.nextInt(100) > 25) { + if (random.nextInt(100) > 25 && !force) { return true; } else { int nearestPlatform = getNearestPlatform(level); @@ -36,7 +37,9 @@ class CoinHolder extends Holder { gameRef.platformHolder.getPlatformOffScreen(nearestPlatform); double xCoordinate = -100; - if (level == 0) { + if (force) { + xCoordinate = xPosition; + } else if (level == 0) { xCoordinate = gameRef.size.x; } else if (platform != null) { xCoordinate = platform.sprite.x; @@ -47,7 +50,7 @@ class CoinHolder extends Holder { Coin coin = Coin(gameRef); coin.setPosition(xCoordinate, gameRef.blockSize * level); - if (gameRef.isTooNearOtherObstacles(coin.sprite.toRect())) { + if (gameRef.isTooNearOtherObstacles(coin.sprite.toRect()) && !force) { return false; } diff --git a/lib/debris_holder.dart b/lib/debris_holder.dart index bc1233d..8d14c73 100644 --- a/lib/debris_holder.dart +++ b/lib/debris_holder.dart @@ -18,7 +18,8 @@ class DebrisHolder extends Holder { return debris; } - bool generateDebris(MyGame gameRef, int level, bool force) { + bool generateDebris(MyGame gameRef, int level, + {bool force = false, double xPosition = 0}) { if (objects[level].isNotEmpty) { return false; } diff --git a/lib/main.dart b/lib/main.dart index b77b31b..7014e2b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -142,27 +142,27 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents { if (wireChosenRegion % 3 != 2 && wireChosenRegion != 6 && wireChosenRegion != 7) { - wireHolder.generateWire(this, wireChosenRegion, false); + wireHolder.generateWire(this, wireChosenRegion); } int bugChosenRegion = random.nextInt(9); if (bugChosenRegion % 3 != 2 && bugChosenRegion % 3 != 0) { - bugHolder.generateBug(this, bugChosenRegion, false); + bugHolder.generateBug(this, bugChosenRegion); } int debrisChosenRegion = random.nextInt(9); if (debrisChosenRegion % 3 == 0 && debrisChosenRegion != 6) { - debrisHolder.generateDebris(this, debrisChosenRegion, false); + debrisHolder.generateDebris(this, debrisChosenRegion); } int choseCoinLevel = random.nextInt(9); if (choseCoinLevel % 3 != 2 && choseCoinLevel != 6) { - coinHolder.generateCoin(this, choseCoinLevel, false); + coinHolder.generateCoin(this, choseCoinLevel); } int wallChosenRegion = random.nextInt(9); if (wallChosenRegion % 3 == 1 && wallChosenRegion != 7) { - wallHolder.generateWall(this, wallChosenRegion, false); + wallHolder.generateWall(this, wallChosenRegion); } } diff --git a/lib/runner.dart b/lib/runner.dart index df6fa2b..543857d 100644 --- a/lib/runner.dart +++ b/lib/runner.dart @@ -395,6 +395,8 @@ class Runner extends Component with HasGameRef { } } else if (intersectState == "left" && runnerState == "kick") { bugLevel[i].sprite.current = BugState.breaking; + gameRef.coinHolder.generateCoin(gameRef, level, + force: true, xPosition: bugLevel[i].sprite.x + gameRef.blockSize); } else { event("glitch"); return; diff --git a/lib/wall_holder.dart b/lib/wall_holder.dart index c9ad35d..b3f0664 100644 --- a/lib/wall_holder.dart +++ b/lib/wall_holder.dart @@ -18,7 +18,8 @@ class WallHolder extends Holder { return wall; } - bool generateWall(MyGame gameRef, int level, bool force) { + bool generateWall(MyGame gameRef, int level, + {bool force = false, double xPosition = 0}) { if (objects[level].isNotEmpty) { return false; } diff --git a/lib/wire_holder.dart b/lib/wire_holder.dart index b123d19..8f7f800 100644 --- a/lib/wire_holder.dart +++ b/lib/wire_holder.dart @@ -18,7 +18,8 @@ class WireHolder extends Holder { return wire; } - bool generateWire(MyGame gameRef, int level, bool force) { + bool generateWire(MyGame gameRef, int level, + {bool force = false, double xPosition = 0}) { if (objects[level].isNotEmpty) { return false; }