Added the feature where if you kick a bug, you get a Firo coin to the right that you can collect.

This commit is contained in:
Marco Salazar 2021-09-16 21:26:57 -06:00
parent df5814820b
commit d676116fd8
7 changed files with 24 additions and 15 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -395,6 +395,8 @@ class Runner extends Component with HasGameRef<MyGame> {
}
} 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;

View File

@ -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;
}

View File

@ -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;
}