Added new death animation when runner hits the bugs, Also made it so that obstactles are spaced further apart

This commit is contained in:
Marco Salazar 2021-09-06 16:28:56 -06:00
parent 7fa49eb824
commit f4274e7207
3 changed files with 28 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

View File

@ -17,6 +17,7 @@ enum RunnerState {
fall, fall,
die, die,
electro, electro,
glitch,
} }
class Runner extends Component with HasGameRef<MyGame> { class Runner extends Component with HasGameRef<MyGame> {
@ -81,7 +82,7 @@ class Runner extends Component with HasGameRef<MyGame> {
// sprite.position, // sprite.position,
Vector2(sprite.x, (level - 1) * gameRef.blockSize), Vector2(sprite.x, (level - 1) * gameRef.blockSize),
], ],
speed: 50, speed: 150,
curve: Curves.bounceIn, curve: Curves.bounceIn,
onComplete: () { onComplete: () {
updateLevel(); updateLevel();
@ -99,7 +100,7 @@ class Runner extends Component with HasGameRef<MyGame> {
path: [ path: [
Vector2(sprite.x, (level - 2) * gameRef.blockSize), Vector2(sprite.x, (level - 2) * gameRef.blockSize),
], ],
speed: 100, speed: 150,
curve: Curves.ease, curve: Curves.ease,
onComplete: () { onComplete: () {
updateLevel(); updateLevel();
@ -164,6 +165,14 @@ class Runner extends Component with HasGameRef<MyGame> {
sprite.current = RunnerState.electro; sprite.current = RunnerState.electro;
gameRef.die(); gameRef.die();
break; break;
case "glitch":
if (dead) {
return;
}
runnerState = event;
sprite.current = RunnerState.glitch;
gameRef.die();
break;
default: default:
break; break;
} }
@ -298,7 +307,7 @@ class Runner extends Component with HasGameRef<MyGame> {
(runnerState == "duck" || runnerState == "float")) { (runnerState == "duck" || runnerState == "float")) {
continue; continue;
} else if (aboveIntersect != "none") { } else if (aboveIntersect != "none") {
event("die"); event("glitch");
return; return;
} }
} else if (intersectState == "left" && runnerState == "kick") { } else if (intersectState == "left" && runnerState == "kick") {
@ -306,7 +315,7 @@ class Runner extends Component with HasGameRef<MyGame> {
// bugLevel[i].remove(); // bugLevel[i].remove();
// bugLevel.removeAt(i); // bugLevel.removeAt(i);
} else { } else {
event("die"); event("glitch");
return; return;
} }
} }
@ -397,6 +406,16 @@ class Runner extends Component with HasGameRef<MyGame> {
), ),
); );
SpriteAnimation dyingGlitch = await loadSpriteAnimation(
'death-glitched-frames.png',
SpriteAnimationData.sequenced(
amount: 8,
stepTime: 0.1,
textureSize: Vector2(512, 512),
loop: false,
),
);
sprite = SpriteAnimationGroupComponent( sprite = SpriteAnimationGroupComponent(
animations: { animations: {
RunnerState.run: running, RunnerState.run: running,
@ -407,6 +426,7 @@ class Runner extends Component with HasGameRef<MyGame> {
RunnerState.fall: falling, RunnerState.fall: falling,
RunnerState.die: dying, RunnerState.die: dying,
RunnerState.electro: dyingElectrocuted, RunnerState.electro: dyingElectrocuted,
RunnerState.glitch: dyingGlitch,
}, },
current: RunnerState.run, current: RunnerState.run,
); );

View File

@ -116,10 +116,10 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
bool isTooNearOtherObstacles(Rect rect) { bool isTooNearOtherObstacles(Rect rect) {
Rect obstacleBounds = Rect.fromLTRB( Rect obstacleBounds = Rect.fromLTRB(
2 * rect.left - rect.right - 1, 3 * rect.left - 2 * rect.right - 1,
2 * rect.top - rect.bottom - 1, 3 * rect.top - 2 * rect.bottom - 1,
2 * rect.right - rect.left + 1, 3 * rect.right - 2 * rect.left + 1,
2 * rect.bottom - rect.top + 1); 3 * rect.bottom - 2 * rect.top + 1);
for (List<Wire> wireLevel in wireHolder.wires) { for (List<Wire> wireLevel in wireHolder.wires) {
for (Wire wire in wireLevel) { for (Wire wire in wireLevel) {
if (wire.intersect(obstacleBounds) != "none") { if (wire.intersect(obstacleBounds) != "none") {