Changed the runner controls to be more smooth, and in line with original vision. Adjusted the obstacles to make it more fair for the user. Removed death by hitting platform.
This commit is contained in:
parent
c6868f23fd
commit
a4269c43c5
@ -48,16 +48,13 @@ class BugHolder {
|
||||
if (random.nextInt(100) > 25) {
|
||||
return true;
|
||||
} else {
|
||||
int nearestPlatform = level <= 0
|
||||
? 0
|
||||
: level <= 3
|
||||
? 2
|
||||
: level <= 6
|
||||
? 5
|
||||
: 8;
|
||||
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||
|
||||
Platform? platform =
|
||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||
if (platform != null && platform.prohibitObstacles) {
|
||||
return false;
|
||||
}
|
||||
double xCoordinate = -100;
|
||||
|
||||
if (level == 0) {
|
||||
|
@ -45,13 +45,7 @@ class CoinHolder {
|
||||
if (random.nextInt(100) > 25) {
|
||||
return true;
|
||||
} else {
|
||||
int nearestPlatform = level <= 0
|
||||
? 0
|
||||
: level <= 3
|
||||
? 2
|
||||
: level <= 6
|
||||
? 5
|
||||
: 8;
|
||||
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||
|
||||
Platform? platform =
|
||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||
|
@ -210,7 +210,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
circuitBackground.render(canvas);
|
||||
fireworks.renderText(canvas);
|
||||
super.render(canvas);
|
||||
final fpsCount = fps(1);
|
||||
final fpsCount = fps(10000);
|
||||
fireworksPaint.render(
|
||||
canvas,
|
||||
fpsCount.toString(),
|
||||
@ -300,6 +300,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||
if (!playingMusic && kIsWeb) {
|
||||
playMusic();
|
||||
}
|
||||
print(event.data.logicalKey.keyId);
|
||||
print(event.data.keyLabel);
|
||||
if (event is RawKeyUpEvent) {
|
||||
keyboardKey = null;
|
||||
switch (event.data.keyLabel) {
|
||||
|
@ -13,6 +13,7 @@ enum PlatformState {
|
||||
|
||||
class Platform extends MovingObject {
|
||||
int row = 0;
|
||||
bool prohibitObstacles = false;
|
||||
List<Function> removeChildren = [];
|
||||
|
||||
Platform(MyGame gameRef) : super(gameRef) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:firo_runner/bug.dart';
|
||||
import 'package:firo_runner/main.dart';
|
||||
import 'package:firo_runner/wire.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:firo_runner/platform.dart';
|
||||
import 'package:flame/extensions.dart';
|
||||
@ -44,6 +46,50 @@ class PlatformHolder {
|
||||
}
|
||||
}
|
||||
|
||||
void removeUnfairObstacles(
|
||||
MyGame gameRef, Platform currentPlatform, int from, int to) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
if (i == 0) {
|
||||
for (Bug bug in gameRef.bugHolder.bugs[0]) {
|
||||
if (bug.sprite.x >= currentPlatform.sprite.x &&
|
||||
bug.sprite.x <
|
||||
currentPlatform.sprite.x + 4 * currentPlatform.sprite.width) {
|
||||
gameRef.bugHolder.bugs[0].remove(bug);
|
||||
bug.remove();
|
||||
}
|
||||
}
|
||||
for (Wire wire in gameRef.wireHolder.wires[0]) {
|
||||
if (wire.sprite.x >= currentPlatform.sprite.x &&
|
||||
wire.sprite.x <
|
||||
currentPlatform.sprite.x + 4 * currentPlatform.sprite.width) {
|
||||
gameRef.wireHolder.wires[0].remove(wire);
|
||||
wire.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int nearestPlatform = getNearestPlatform(i);
|
||||
for (Platform platform in platforms[nearestPlatform]) {
|
||||
if (platform.sprite.x >= currentPlatform.sprite.x &&
|
||||
platform.sprite.x <
|
||||
currentPlatform.sprite.x + 4 * currentPlatform.sprite.width) {
|
||||
platform.remove();
|
||||
platform.prohibitObstacles = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getNearestPlatform(int level) {
|
||||
return level <= 0
|
||||
? 0
|
||||
: level <= 3
|
||||
? 2
|
||||
: level <= 6
|
||||
? 5
|
||||
: 8;
|
||||
}
|
||||
|
||||
void generatePlatforms(MyGame gameRef) {
|
||||
while (!generatePlatform(gameRef, 2)) {
|
||||
timeSinceLastTopHole++;
|
||||
@ -58,8 +104,12 @@ class PlatformHolder {
|
||||
.nextInt(timeSinceLastBottomHole > 0 ? timeSinceLastBottomHole : 1);
|
||||
|
||||
if (topChance > 50) {
|
||||
removeUnfairObstacles(
|
||||
gameRef, platforms[2][platforms[2].length - 4], 0, 4);
|
||||
// Create an opening in the top.
|
||||
remove(platforms[2], platforms[2].length - 2);
|
||||
remove(platforms[2], platforms[2].length - 2);
|
||||
|
||||
timeSinceLastTopHole = 0;
|
||||
}
|
||||
if (bottomChance > 30) {
|
||||
@ -70,10 +120,15 @@ class PlatformHolder {
|
||||
}
|
||||
int lastToRemove = platforms[5].length - 3;
|
||||
int firstToRemove = platforms[5].length - 10;
|
||||
|
||||
removeUnfairObstacles(gameRef, platforms[5][lastToRemove - 1], 3, 7);
|
||||
remove(platforms[5], lastToRemove);
|
||||
remove(platforms[5], lastToRemove);
|
||||
|
||||
removeUnfairObstacles(gameRef, platforms[5][firstToRemove - 1], 3, 7);
|
||||
remove(platforms[5], firstToRemove);
|
||||
remove(platforms[5], firstToRemove);
|
||||
|
||||
timeSinceLastBottomHole = 0;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
// sprite.position,
|
||||
Vector2(sprite.x, (level - 1) * gameRef.blockSize),
|
||||
],
|
||||
speed: 150,
|
||||
duration: 0.25,
|
||||
curve: Curves.bounceIn,
|
||||
onComplete: () {
|
||||
updateLevel();
|
||||
@ -91,6 +91,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
));
|
||||
break;
|
||||
case "double_jump":
|
||||
if (belowPlatform()) {
|
||||
break;
|
||||
}
|
||||
sprite.clearEffects();
|
||||
if (level - 1 < 0) {
|
||||
break;
|
||||
}
|
||||
@ -104,22 +108,31 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
curve: Curves.ease,
|
||||
onComplete: () {
|
||||
updateLevel();
|
||||
this.event("float");
|
||||
if (onTopOfPlatform()) {
|
||||
this.event("run");
|
||||
} else {
|
||||
this.event("float");
|
||||
}
|
||||
},
|
||||
));
|
||||
break;
|
||||
case "fall":
|
||||
sprite.clearEffects();
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.fall;
|
||||
sprite.addEffect(MoveEffect(
|
||||
path: [
|
||||
Vector2(sprite.x, (level + 1) * gameRef.blockSize),
|
||||
],
|
||||
speed: 100,
|
||||
duration: 0.2,
|
||||
curve: Curves.ease,
|
||||
onComplete: () {
|
||||
updateLevel();
|
||||
this.event("float");
|
||||
if (onTopOfPlatform()) {
|
||||
this.event("run");
|
||||
} else {
|
||||
this.event("fall");
|
||||
}
|
||||
},
|
||||
));
|
||||
break;
|
||||
@ -136,23 +149,36 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
sprite.current = RunnerState.float;
|
||||
sprite.addEffect(MoveEffect(
|
||||
path: [sprite.position],
|
||||
speed: 500,
|
||||
duration: 1.5,
|
||||
curve: Curves.ease,
|
||||
onComplete: () {
|
||||
updateLevel();
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.float;
|
||||
if (onTopOfPlatform()) {
|
||||
this.event("run");
|
||||
} else {
|
||||
this.event("fall");
|
||||
}
|
||||
},
|
||||
));
|
||||
break;
|
||||
case "duck":
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.duck;
|
||||
sprite.addEffect(MoveEffect(
|
||||
path: [sprite.position],
|
||||
duration: 1.5,
|
||||
curve: Curves.linear,
|
||||
onComplete: () {
|
||||
this.event("run");
|
||||
},
|
||||
));
|
||||
break;
|
||||
case "die":
|
||||
if (dead) {
|
||||
return;
|
||||
}
|
||||
sprite.clearEffects();
|
||||
updateLevel();
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.die;
|
||||
gameRef.die();
|
||||
@ -161,6 +187,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
if (dead) {
|
||||
return;
|
||||
}
|
||||
sprite.clearEffects();
|
||||
updateLevel();
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.electrocute;
|
||||
gameRef.die();
|
||||
@ -169,6 +197,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
if (dead) {
|
||||
return;
|
||||
}
|
||||
sprite.clearEffects();
|
||||
updateLevel();
|
||||
runnerState = event;
|
||||
sprite.current = RunnerState.glitch;
|
||||
gameRef.die();
|
||||
@ -189,6 +219,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
} else if (runnerState == "float" && previousState == "jump") {
|
||||
event("double_jump");
|
||||
} else if (runnerState == "duck") {
|
||||
sprite.clearEffects();
|
||||
event("run");
|
||||
}
|
||||
break;
|
||||
@ -196,8 +227,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
if (runnerState == "run") {
|
||||
event("duck");
|
||||
} else if (runnerState == "float" && onTopOfPlatform()) {
|
||||
sprite.clearEffects();
|
||||
event("run");
|
||||
} else if (runnerState == "float") {
|
||||
sprite.clearEffects();
|
||||
event("fall");
|
||||
}
|
||||
break;
|
||||
@ -207,10 +240,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
}
|
||||
break;
|
||||
case "center":
|
||||
if (runnerState == "fall") {
|
||||
updateLevel();
|
||||
event("float");
|
||||
}
|
||||
// if (runnerState == "fall") {
|
||||
// updateLevel();
|
||||
// event("float");
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -252,6 +285,24 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
return onTopOfPlatform;
|
||||
}
|
||||
|
||||
bool belowPlatform() {
|
||||
Rect runnerRect = sprite.toRect();
|
||||
bool belowPlatform = false;
|
||||
for (List<Platform> platformLevel in gameRef.platformHolder.platforms) {
|
||||
for (Platform p in platformLevel) {
|
||||
String side = p.intersect(runnerRect);
|
||||
if (side == "none") {
|
||||
Rect belowRunner = Rect.fromLTRB(runnerRect.left, runnerRect.top - 1,
|
||||
runnerRect.right, runnerRect.bottom);
|
||||
if (p.intersect(belowRunner) == "bottom") {
|
||||
belowPlatform = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return belowPlatform;
|
||||
}
|
||||
|
||||
void intersecting() {
|
||||
if (gameRef.gameState.isPaused) {
|
||||
return;
|
||||
@ -268,7 +319,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
onTopOfPlatform = true;
|
||||
}
|
||||
} else if (side == "bottom") {
|
||||
event("die");
|
||||
// event("die");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -41,16 +41,13 @@ class WireHolder {
|
||||
if (random.nextInt(100) > 100) {
|
||||
return true;
|
||||
} else {
|
||||
int nearestPlatform = level <= 0
|
||||
? 0
|
||||
: level <= 3
|
||||
? 2
|
||||
: level <= 6
|
||||
? 5
|
||||
: 8;
|
||||
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||
|
||||
Platform? platform =
|
||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||
if (platform != null && platform.prohibitObstacles) {
|
||||
return false;
|
||||
}
|
||||
double xCoordinate = -100;
|
||||
|
||||
if (level == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user