Added overhead debris sign, instead of overhead bugs.
This commit is contained in:
parent
8d225bda06
commit
19b401d84f
BIN
assets/images/debris-frames.png
Normal file
BIN
assets/images/debris-frames.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 305 KiB |
37
lib/debris.dart
Normal file
37
lib/debris.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'package:firo_runner/moving_object.dart';
|
||||
import 'package:firo_runner/main.dart';
|
||||
import 'package:flame/components.dart';
|
||||
|
||||
enum DebrisState { normal }
|
||||
|
||||
class Debris extends MovingObject {
|
||||
Debris(MyGame gameRef) : super(gameRef) {
|
||||
var debris = gameRef.debrisHolder.getDebris();
|
||||
SpriteAnimation normal = SpriteAnimation.fromFrameData(
|
||||
debris,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 21,
|
||||
stepTime: 0.1,
|
||||
textureSize: Vector2(360, 1000),
|
||||
),
|
||||
);
|
||||
|
||||
sprite = SpriteAnimationGroupComponent(
|
||||
animations: {
|
||||
DebrisState.normal: normal,
|
||||
},
|
||||
current: DebrisState.normal,
|
||||
);
|
||||
|
||||
sprite.changePriorityWithoutResorting(DEBRIS_PRIORITY);
|
||||
|
||||
setSize(
|
||||
gameRef.blockSize *
|
||||
(gameRef.debrisHolder.debris.width /
|
||||
gameRef.debrisHolder.debris.height /
|
||||
21) *
|
||||
1.5,
|
||||
gameRef.blockSize * 1.5,
|
||||
);
|
||||
}
|
||||
}
|
65
lib/debris_holder.dart
Normal file
65
lib/debris_holder.dart
Normal file
@ -0,0 +1,65 @@
|
||||
import 'package:firo_runner/holder.dart';
|
||||
import 'package:firo_runner/platform.dart';
|
||||
import 'package:flame/extensions.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
|
||||
import 'package:firo_runner/debris.dart';
|
||||
import 'package:firo_runner/main.dart';
|
||||
|
||||
class DebrisHolder extends Holder {
|
||||
late Image debris;
|
||||
|
||||
@override
|
||||
Future load() async {
|
||||
debris = await Flame.images.load("debris-frames.png");
|
||||
}
|
||||
|
||||
getDebris() {
|
||||
return debris;
|
||||
}
|
||||
|
||||
bool generateDebris(MyGame gameRef, int level, bool force) {
|
||||
if (objects[level].isNotEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (random.nextInt(100) > 25) {
|
||||
return true;
|
||||
} else {
|
||||
int nearestPlatform = getNearestPlatform(level);
|
||||
|
||||
Platform? platform =
|
||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||
if (platform != null && platform.prohibitObstacles) {
|
||||
return false;
|
||||
}
|
||||
double xCoordinate = -100;
|
||||
|
||||
if (level == 0) {
|
||||
xCoordinate = gameRef.size.x;
|
||||
} else if (platform != null) {
|
||||
xCoordinate = platform.sprite.x;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Debris debris = Debris(gameRef);
|
||||
debris.setPosition(
|
||||
xCoordinate, gameRef.blockSize * level - gameRef.blockSize / 3);
|
||||
|
||||
if (gameRef.isTooNearOtherObstacles(debris.sprite.toRect())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objects[level].add(debris);
|
||||
gameRef.add(debris.sprite);
|
||||
if (platform != null) {
|
||||
platform.removeChildren.add(() {
|
||||
objects[level].remove(debris);
|
||||
debris.remove();
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||
import 'package:firo_runner/bug_holder.dart';
|
||||
import 'package:firo_runner/circuit_background.dart';
|
||||
import 'package:firo_runner/coin_holder.dart';
|
||||
import 'package:firo_runner/debris_holder.dart';
|
||||
import 'package:firo_runner/firework.dart';
|
||||
import 'package:firo_runner/game_state.dart';
|
||||
import 'package:firo_runner/moving_object.dart';
|
||||
@ -35,6 +36,7 @@ const RUNNER_PRIORITY = 100;
|
||||
const BUG_PRIORITY = 75;
|
||||
const COIN_PRIORITY = 70;
|
||||
const PLATFORM_PRIORITY = 50;
|
||||
const DEBRIS_PRIORITY = 30;
|
||||
const WIRE_PRIORITY = 25;
|
||||
const FIREWORK_PRIORITY = 15;
|
||||
const WINDOW_PRIORITY = 10;
|
||||
@ -69,6 +71,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
late WireHolder wireHolder;
|
||||
late BugHolder bugHolder;
|
||||
late Firework fireworks;
|
||||
late DebrisHolder debrisHolder;
|
||||
Random random = Random();
|
||||
bool playingMusic = false;
|
||||
|
||||
@ -101,6 +104,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
await wireHolder.load();
|
||||
bugHolder = BugHolder();
|
||||
await bugHolder.load();
|
||||
debrisHolder = DebrisHolder();
|
||||
await debrisHolder.load();
|
||||
fireworks = Firework(this);
|
||||
await fireworks.load();
|
||||
|
||||
@ -136,10 +141,15 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
}
|
||||
|
||||
int bugChosenRegion = random.nextInt(9);
|
||||
if (bugChosenRegion % 3 != 2 && bugChosenRegion != 6) {
|
||||
if (bugChosenRegion % 3 != 2 && bugChosenRegion % 3 != 0) {
|
||||
bugHolder.generateBug(this, bugChosenRegion, false);
|
||||
}
|
||||
|
||||
int debrisChosenRegion = random.nextInt(9);
|
||||
if (debrisChosenRegion % 3 == 0 && debrisChosenRegion != 6) {
|
||||
debrisHolder.generateDebris(this, debrisChosenRegion, false);
|
||||
}
|
||||
|
||||
int choseCoinLevel = random.nextInt(9);
|
||||
if (choseCoinLevel % 3 != 2 && choseCoinLevel != 6) {
|
||||
coinHolder.generateCoin(this, choseCoinLevel, false);
|
||||
@ -176,6 +186,14 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
}
|
||||
}
|
||||
|
||||
for (List<MovingObject> debrisLevel in debrisHolder.objects) {
|
||||
for (MovingObject debris in debrisLevel) {
|
||||
if (debris.intersect(obstacleBounds) != "none") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -207,6 +225,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
coinHolder.setUp();
|
||||
wireHolder.setUp();
|
||||
bugHolder.setUp();
|
||||
debrisHolder.setUp();
|
||||
|
||||
gameState.setUp(this);
|
||||
|
||||
@ -237,6 +256,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
coinHolder.removePast(this);
|
||||
wireHolder.removePast(this);
|
||||
bugHolder.removePast(this);
|
||||
debrisHolder.removePast(this);
|
||||
fillScreen();
|
||||
super.update(dt);
|
||||
circuitBackground.update(dt);
|
||||
@ -245,6 +265,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
coinHolder.update(dt);
|
||||
wireHolder.update(dt);
|
||||
bugHolder.update(dt);
|
||||
debrisHolder.update(dt);
|
||||
if (shouldReset) {
|
||||
reset();
|
||||
}
|
||||
@ -264,6 +285,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
coinHolder.resize(canvasSize, xRatio, yRatio);
|
||||
wireHolder.resize(canvasSize, xRatio, yRatio);
|
||||
bugHolder.resize(canvasSize, xRatio, yRatio);
|
||||
debrisHolder.resize(canvasSize, xRatio, yRatio);
|
||||
fireworks.resize(canvasSize, xRatio, yRatio);
|
||||
}
|
||||
}
|
||||
|
@ -402,6 +402,25 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
}
|
||||
}
|
||||
|
||||
for (List<MovingObject> debrisLevel in gameRef.debrisHolder.objects) {
|
||||
for (int i = 0; i < debrisLevel.length; i++) {
|
||||
Rect slim = Rect.fromLTRB(
|
||||
runnerRect.left + sprite.width / 3,
|
||||
runnerRect.top,
|
||||
runnerRect.right - sprite.width / 3,
|
||||
runnerRect.bottom);
|
||||
String intersectState = debrisLevel[i].intersect(slim);
|
||||
if (intersectState == "none") {
|
||||
continue;
|
||||
} else if ((runnerState == "duck" || runnerState == "float") &&
|
||||
intersectState != "above") {
|
||||
continue;
|
||||
} else {
|
||||
event("die");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!onTopOfPlatform &&
|
||||
(runnerState == "run" ||
|
||||
runnerState == "kick" ||
|
||||
|
Loading…
Reference in New Issue
Block a user