forked from marco/firo_runner
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) {
|
if (random.nextInt(100) > 25) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
int nearestPlatform = level <= 0
|
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||||
? 0
|
|
||||||
: level <= 3
|
|
||||||
? 2
|
|
||||||
: level <= 6
|
|
||||||
? 5
|
|
||||||
: 8;
|
|
||||||
|
|
||||||
Platform? platform =
|
Platform? platform =
|
||||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||||
|
if (platform != null && platform.prohibitObstacles) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
double xCoordinate = -100;
|
double xCoordinate = -100;
|
||||||
|
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
|
@ -45,13 +45,7 @@ class CoinHolder {
|
|||||||
if (random.nextInt(100) > 25) {
|
if (random.nextInt(100) > 25) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
int nearestPlatform = level <= 0
|
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||||
? 0
|
|
||||||
: level <= 3
|
|
||||||
? 2
|
|
||||||
: level <= 6
|
|
||||||
? 5
|
|
||||||
: 8;
|
|
||||||
|
|
||||||
Platform? platform =
|
Platform? platform =
|
||||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||||
|
@ -210,7 +210,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
circuitBackground.render(canvas);
|
circuitBackground.render(canvas);
|
||||||
fireworks.renderText(canvas);
|
fireworks.renderText(canvas);
|
||||||
super.render(canvas);
|
super.render(canvas);
|
||||||
final fpsCount = fps(1);
|
final fpsCount = fps(10000);
|
||||||
fireworksPaint.render(
|
fireworksPaint.render(
|
||||||
canvas,
|
canvas,
|
||||||
fpsCount.toString(),
|
fpsCount.toString(),
|
||||||
@ -300,6 +300,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
if (!playingMusic && kIsWeb) {
|
if (!playingMusic && kIsWeb) {
|
||||||
playMusic();
|
playMusic();
|
||||||
}
|
}
|
||||||
|
print(event.data.logicalKey.keyId);
|
||||||
|
print(event.data.keyLabel);
|
||||||
if (event is RawKeyUpEvent) {
|
if (event is RawKeyUpEvent) {
|
||||||
keyboardKey = null;
|
keyboardKey = null;
|
||||||
switch (event.data.keyLabel) {
|
switch (event.data.keyLabel) {
|
||||||
|
@ -13,6 +13,7 @@ enum PlatformState {
|
|||||||
|
|
||||||
class Platform extends MovingObject {
|
class Platform extends MovingObject {
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
bool prohibitObstacles = false;
|
||||||
List<Function> removeChildren = [];
|
List<Function> removeChildren = [];
|
||||||
|
|
||||||
Platform(MyGame gameRef) : super(gameRef) {
|
Platform(MyGame gameRef) : super(gameRef) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:firo_runner/bug.dart';
|
||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
|
import 'package:firo_runner/wire.dart';
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:firo_runner/platform.dart';
|
import 'package:firo_runner/platform.dart';
|
||||||
import 'package:flame/extensions.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) {
|
void generatePlatforms(MyGame gameRef) {
|
||||||
while (!generatePlatform(gameRef, 2)) {
|
while (!generatePlatform(gameRef, 2)) {
|
||||||
timeSinceLastTopHole++;
|
timeSinceLastTopHole++;
|
||||||
@ -58,8 +104,12 @@ class PlatformHolder {
|
|||||||
.nextInt(timeSinceLastBottomHole > 0 ? timeSinceLastBottomHole : 1);
|
.nextInt(timeSinceLastBottomHole > 0 ? timeSinceLastBottomHole : 1);
|
||||||
|
|
||||||
if (topChance > 50) {
|
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);
|
||||||
remove(platforms[2], platforms[2].length - 2);
|
remove(platforms[2], platforms[2].length - 2);
|
||||||
|
|
||||||
timeSinceLastTopHole = 0;
|
timeSinceLastTopHole = 0;
|
||||||
}
|
}
|
||||||
if (bottomChance > 30) {
|
if (bottomChance > 30) {
|
||||||
@ -70,10 +120,15 @@ class PlatformHolder {
|
|||||||
}
|
}
|
||||||
int lastToRemove = platforms[5].length - 3;
|
int lastToRemove = platforms[5].length - 3;
|
||||||
int firstToRemove = platforms[5].length - 10;
|
int firstToRemove = platforms[5].length - 10;
|
||||||
|
|
||||||
|
removeUnfairObstacles(gameRef, platforms[5][lastToRemove - 1], 3, 7);
|
||||||
remove(platforms[5], lastToRemove);
|
remove(platforms[5], lastToRemove);
|
||||||
remove(platforms[5], lastToRemove);
|
remove(platforms[5], lastToRemove);
|
||||||
|
|
||||||
|
removeUnfairObstacles(gameRef, platforms[5][firstToRemove - 1], 3, 7);
|
||||||
remove(platforms[5], firstToRemove);
|
remove(platforms[5], firstToRemove);
|
||||||
remove(platforms[5], firstToRemove);
|
remove(platforms[5], firstToRemove);
|
||||||
|
|
||||||
timeSinceLastBottomHole = 0;
|
timeSinceLastBottomHole = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,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: 150,
|
duration: 0.25,
|
||||||
curve: Curves.bounceIn,
|
curve: Curves.bounceIn,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
@ -91,6 +91,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "double_jump":
|
case "double_jump":
|
||||||
|
if (belowPlatform()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sprite.clearEffects();
|
||||||
if (level - 1 < 0) {
|
if (level - 1 < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -104,22 +108,31 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
this.event("float");
|
if (onTopOfPlatform()) {
|
||||||
|
this.event("run");
|
||||||
|
} else {
|
||||||
|
this.event("float");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "fall":
|
case "fall":
|
||||||
|
sprite.clearEffects();
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.fall;
|
sprite.current = RunnerState.fall;
|
||||||
sprite.addEffect(MoveEffect(
|
sprite.addEffect(MoveEffect(
|
||||||
path: [
|
path: [
|
||||||
Vector2(sprite.x, (level + 1) * gameRef.blockSize),
|
Vector2(sprite.x, (level + 1) * gameRef.blockSize),
|
||||||
],
|
],
|
||||||
speed: 100,
|
duration: 0.2,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
this.event("float");
|
if (onTopOfPlatform()) {
|
||||||
|
this.event("run");
|
||||||
|
} else {
|
||||||
|
this.event("fall");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
@ -136,23 +149,36 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
sprite.current = RunnerState.float;
|
sprite.current = RunnerState.float;
|
||||||
sprite.addEffect(MoveEffect(
|
sprite.addEffect(MoveEffect(
|
||||||
path: [sprite.position],
|
path: [sprite.position],
|
||||||
speed: 500,
|
duration: 1.5,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
runnerState = event;
|
if (onTopOfPlatform()) {
|
||||||
sprite.current = RunnerState.float;
|
this.event("run");
|
||||||
|
} else {
|
||||||
|
this.event("fall");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "duck":
|
case "duck":
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.duck;
|
sprite.current = RunnerState.duck;
|
||||||
|
sprite.addEffect(MoveEffect(
|
||||||
|
path: [sprite.position],
|
||||||
|
duration: 1.5,
|
||||||
|
curve: Curves.linear,
|
||||||
|
onComplete: () {
|
||||||
|
this.event("run");
|
||||||
|
},
|
||||||
|
));
|
||||||
break;
|
break;
|
||||||
case "die":
|
case "die":
|
||||||
if (dead) {
|
if (dead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sprite.clearEffects();
|
||||||
|
updateLevel();
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.die;
|
sprite.current = RunnerState.die;
|
||||||
gameRef.die();
|
gameRef.die();
|
||||||
@ -161,6 +187,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
if (dead) {
|
if (dead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sprite.clearEffects();
|
||||||
|
updateLevel();
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.electrocute;
|
sprite.current = RunnerState.electrocute;
|
||||||
gameRef.die();
|
gameRef.die();
|
||||||
@ -169,6 +197,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
if (dead) {
|
if (dead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sprite.clearEffects();
|
||||||
|
updateLevel();
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.glitch;
|
sprite.current = RunnerState.glitch;
|
||||||
gameRef.die();
|
gameRef.die();
|
||||||
@ -189,6 +219,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
} else if (runnerState == "float" && previousState == "jump") {
|
} else if (runnerState == "float" && previousState == "jump") {
|
||||||
event("double_jump");
|
event("double_jump");
|
||||||
} else if (runnerState == "duck") {
|
} else if (runnerState == "duck") {
|
||||||
|
sprite.clearEffects();
|
||||||
event("run");
|
event("run");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -196,8 +227,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
if (runnerState == "run") {
|
if (runnerState == "run") {
|
||||||
event("duck");
|
event("duck");
|
||||||
} else if (runnerState == "float" && onTopOfPlatform()) {
|
} else if (runnerState == "float" && onTopOfPlatform()) {
|
||||||
|
sprite.clearEffects();
|
||||||
event("run");
|
event("run");
|
||||||
} else if (runnerState == "float") {
|
} else if (runnerState == "float") {
|
||||||
|
sprite.clearEffects();
|
||||||
event("fall");
|
event("fall");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -207,10 +240,10 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "center":
|
case "center":
|
||||||
if (runnerState == "fall") {
|
// if (runnerState == "fall") {
|
||||||
updateLevel();
|
// updateLevel();
|
||||||
event("float");
|
// event("float");
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,6 +285,24 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
return onTopOfPlatform;
|
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() {
|
void intersecting() {
|
||||||
if (gameRef.gameState.isPaused) {
|
if (gameRef.gameState.isPaused) {
|
||||||
return;
|
return;
|
||||||
@ -268,7 +319,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
onTopOfPlatform = true;
|
onTopOfPlatform = true;
|
||||||
}
|
}
|
||||||
} else if (side == "bottom") {
|
} else if (side == "bottom") {
|
||||||
event("die");
|
// event("die");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,16 +41,13 @@ class WireHolder {
|
|||||||
if (random.nextInt(100) > 100) {
|
if (random.nextInt(100) > 100) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
int nearestPlatform = level <= 0
|
int nearestPlatform = gameRef.platformHolder.getNearestPlatform(level);
|
||||||
? 0
|
|
||||||
: level <= 3
|
|
||||||
? 2
|
|
||||||
: level <= 6
|
|
||||||
? 5
|
|
||||||
: 8;
|
|
||||||
|
|
||||||
Platform? platform =
|
Platform? platform =
|
||||||
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||||
|
if (platform != null && platform.prohibitObstacles) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
double xCoordinate = -100;
|
double xCoordinate = -100;
|
||||||
|
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user