Added wires, and fixed rendering so that flips of images will be registered.
Before Width: | Height: | Size: 143 KiB |
Before Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 295 KiB |
BIN
assets/images/hover-frames.png
Normal file
After Width: | Height: | Size: 290 KiB |
Before Width: | Height: | Size: 131 KiB |
Before Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 165 KiB |
Before Width: | Height: | Size: 118 KiB |
@ -1,9 +1,6 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:firo_runner/MovingObject.dart';
|
import 'package:firo_runner/MovingObject.dart';
|
||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
enum CoinState { normal }
|
enum CoinState { normal }
|
||||||
|
|
||||||
@ -26,6 +23,8 @@ class Coin extends MovingObject {
|
|||||||
current: CoinState.normal,
|
current: CoinState.normal,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sprite.changePriorityWithoutResorting(COIN_PRIORITY);
|
||||||
|
|
||||||
var platform = gameRef.platformHolder.getPlatform(0);
|
var platform = gameRef.platformHolder.getPlatform(0);
|
||||||
|
|
||||||
setSize(
|
setSize(
|
||||||
@ -38,8 +37,7 @@ class Coin extends MovingObject {
|
|||||||
return sprite.position.x + sprite.width;
|
return sprite.position.x + sprite.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
void remove() {
|
||||||
void render(Canvas c) {
|
sprite.remove();
|
||||||
getSprite().render(c, position: sprite.position, size: sprite.size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'Coin.dart';
|
import 'Coin.dart';
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
|
|
||||||
class Coinholder {
|
class CoinHolder {
|
||||||
var coin;
|
var coin;
|
||||||
Random random = Random();
|
Random random = Random();
|
||||||
|
|
||||||
@ -28,19 +27,17 @@ class Coinholder {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double xCordinate = gameRef.platformHolder.getFlushX();
|
double xCordinate = gameRef.platformHolder.getFlushX();
|
||||||
// if (coins[level].isNotEmpty) {
|
|
||||||
// xCordinate = coins[level].last.getRightEnd();
|
|
||||||
// }
|
|
||||||
xCordinate = xCordinate +
|
xCordinate = xCordinate +
|
||||||
gameRef.blockSize * random.nextInt(5) +
|
gameRef.blockSize * random.nextInt(5) +
|
||||||
gameRef.blockSize * 20;
|
gameRef.blockSize * 20;
|
||||||
|
|
||||||
if (xCordinate < gameRef.size.x && random.nextInt(1000000) > 99999) {
|
if (xCordinate < gameRef.size.x || random.nextInt(100) > 10) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Coin coin = Coin(gameRef);
|
Coin coin = Coin(gameRef);
|
||||||
coin.setPosition(xCordinate, gameRef.blockSize * level);
|
coin.setPosition(xCordinate, gameRef.blockSize * level);
|
||||||
coins[level].add(coin);
|
coins[level].add(coin);
|
||||||
|
gameRef.add(coin.sprite);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,14 +50,6 @@ class Coinholder {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(Canvas canvas) {
|
|
||||||
for (List<Coin> coinLevel in coins) {
|
|
||||||
for (Coin p in coinLevel) {
|
|
||||||
p.render(canvas);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
for (List<Coin> coinLevel in coins) {
|
for (List<Coin> coinLevel in coins) {
|
||||||
for (Coin p in coinLevel) {
|
for (Coin p in coinLevel) {
|
||||||
@ -73,6 +62,7 @@ class Coinholder {
|
|||||||
for (List<Coin> coinLevel in coins) {
|
for (List<Coin> coinLevel in coins) {
|
||||||
for (int i = 0; i < coinLevel.length;) {
|
for (int i = 0; i < coinLevel.length;) {
|
||||||
if (coinLevel[i].sprite.x + coinLevel[i].sprite.width < 0) {
|
if (coinLevel[i].sprite.x + coinLevel[i].sprite.width < 0) {
|
||||||
|
coinLevel[i].sprite.remove();
|
||||||
coinLevel.removeAt(i);
|
coinLevel.removeAt(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
|
|
||||||
class MovingObject extends Component {
|
class MovingObject {
|
||||||
late SpriteAnimationGroupComponent sprite;
|
late SpriteAnimationGroupComponent sprite;
|
||||||
MyGame gameRef;
|
MyGame gameRef;
|
||||||
|
|
||||||
@ -21,15 +21,7 @@ class MovingObject extends Component {
|
|||||||
return sprite.animation!.getSprite();
|
return sprite.animation!.getSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void render(Canvas c) {
|
|
||||||
super.render(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
super.update(dt);
|
|
||||||
sprite.update(dt);
|
|
||||||
double velocity = gameRef.gameState.getVelocity();
|
double velocity = gameRef.gameState.getVelocity();
|
||||||
sprite.position = sprite.position - Vector2(velocity * dt, 0);
|
sprite.position = sprite.position - Vector2(velocity * dt, 0);
|
||||||
}
|
}
|
||||||
@ -37,17 +29,16 @@ class MovingObject extends Component {
|
|||||||
String intersect(Rect other) {
|
String intersect(Rect other) {
|
||||||
final collision = sprite.toRect().intersect(other);
|
final collision = sprite.toRect().intersect(other);
|
||||||
if (!collision.isEmpty) {
|
if (!collision.isEmpty) {
|
||||||
// print(collision);
|
double yDistance = other.top - sprite.toRect().top;
|
||||||
double ydistance = other.top - sprite.toRect().top;
|
double xDistance = other.left - sprite.toRect().left;
|
||||||
double xdistance = other.left - sprite.toRect().left;
|
if (yDistance.abs() > xDistance.abs()) {
|
||||||
if (ydistance.abs() > xdistance.abs()) {
|
if (yDistance > 0) {
|
||||||
if (ydistance > 0) {
|
|
||||||
return "bottom";
|
return "bottom";
|
||||||
} else {
|
} else {
|
||||||
return "top";
|
return "top";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (xdistance > 0) {
|
if (xDistance > 0) {
|
||||||
return "right";
|
return "right";
|
||||||
} else {
|
} else {
|
||||||
return "left";
|
return "left";
|
||||||
|
@ -3,11 +3,12 @@ import 'dart:math';
|
|||||||
import 'package:firo_runner/MovingObject.dart';
|
import 'package:firo_runner/MovingObject.dart';
|
||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
enum PlatformState { normal }
|
enum PlatformState { normal }
|
||||||
|
|
||||||
class Platform extends MovingObject {
|
class Platform extends MovingObject {
|
||||||
|
var removeChildren = null;
|
||||||
|
|
||||||
Platform(MyGame gameRef) : super(gameRef) {
|
Platform(MyGame gameRef) : super(gameRef) {
|
||||||
var random = Random();
|
var random = Random();
|
||||||
int version = random.nextInt(3) + 1;
|
int version = random.nextInt(3) + 1;
|
||||||
@ -28,6 +29,8 @@ class Platform extends MovingObject {
|
|||||||
current: PlatformState.normal,
|
current: PlatformState.normal,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY);
|
||||||
|
|
||||||
setSize(
|
setSize(
|
||||||
gameRef.blockSize * (platform!.width / platform!.height / 7),
|
gameRef.blockSize * (platform!.width / platform!.height / 7),
|
||||||
gameRef.blockSize,
|
gameRef.blockSize,
|
||||||
@ -38,8 +41,9 @@ class Platform extends MovingObject {
|
|||||||
return sprite.position.x + sprite.width;
|
return sprite.position.x + sprite.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
void remove() {
|
||||||
void render(Canvas c) {
|
if (removeChildren != null) {
|
||||||
getSprite().render(c, position: sprite.position, size: sprite.size);
|
removeChildren();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'Platform.dart';
|
import 'Platform.dart';
|
||||||
|
|
||||||
class PlatformHolder {
|
class PlatformHolder {
|
||||||
@ -33,29 +32,22 @@ class PlatformHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool generatePlatform(MyGame gameRef, int level, bool force) {
|
bool generatePlatform(MyGame gameRef, int level, bool force) {
|
||||||
double xCordinate = 0;
|
double xCoordinate = 0;
|
||||||
if (platforms[level].isNotEmpty) {
|
if (platforms[level].isNotEmpty) {
|
||||||
xCordinate = platforms[level].last.getRightEnd();
|
xCoordinate = platforms[level].last.getRightEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xCordinate > gameRef.size.x + 1000) {
|
if (xCoordinate > gameRef.size.x + 1000) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Platform platform = Platform(gameRef);
|
Platform platform = Platform(gameRef);
|
||||||
platform.setPosition(xCordinate, gameRef.blockSize * level);
|
platform.setPosition(xCoordinate, gameRef.blockSize * level);
|
||||||
|
gameRef.add(platform.sprite);
|
||||||
platforms[level].add(platform);
|
platforms[level].add(platform);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(Canvas canvas) {
|
|
||||||
for (List<Platform> platformLevel in platforms) {
|
|
||||||
for (Platform p in platformLevel) {
|
|
||||||
p.render(canvas);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
for (List<Platform> platformLevel in platforms) {
|
for (List<Platform> platformLevel in platforms) {
|
||||||
for (Platform p in platformLevel) {
|
for (Platform p in platformLevel) {
|
||||||
@ -70,6 +62,7 @@ class PlatformHolder {
|
|||||||
while (platformLevel.isNotEmpty &&
|
while (platformLevel.isNotEmpty &&
|
||||||
platformLevel[0].sprite.position.x + platformLevel[0].sprite.width <
|
platformLevel[0].sprite.position.x + platformLevel[0].sprite.width <
|
||||||
0) {
|
0) {
|
||||||
|
platformLevel[0].sprite.remove();
|
||||||
platformLevel.removeAt(0);
|
platformLevel.removeAt(0);
|
||||||
removed++;
|
removed++;
|
||||||
}
|
}
|
||||||
@ -81,7 +74,12 @@ class PlatformHolder {
|
|||||||
double secondToLastPosition =
|
double secondToLastPosition =
|
||||||
platformLevel.elementAt(secondToLast).sprite.x;
|
platformLevel.elementAt(secondToLast).sprite.x;
|
||||||
if (secondToLastPosition > gameRef.size.x) {
|
if (secondToLastPosition > gameRef.size.x) {
|
||||||
|
platformLevel[secondToLast].remove();
|
||||||
|
platformLevel[secondToLast].sprite.remove();
|
||||||
platformLevel.removeAt(secondToLast);
|
platformLevel.removeAt(secondToLast);
|
||||||
|
|
||||||
|
platformLevel[secondToLast + 1].remove();
|
||||||
|
platformLevel[secondToLast + 1].sprite.remove();
|
||||||
platformLevel.removeAt(secondToLast + 1);
|
platformLevel.removeAt(secondToLast + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,4 +96,15 @@ class PlatformHolder {
|
|||||||
});
|
});
|
||||||
return platform.sprite.x;
|
return platform.sprite.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Platform? getPlatformOffScreen(int level) {
|
||||||
|
for (int i = 0; i < platforms[level].length; i++) {
|
||||||
|
Platform p = platforms[level][i];
|
||||||
|
if (p.sprite.x > p.gameRef.size.x) {
|
||||||
|
int chosenIndex = random.nextInt(platforms[level].length - i) + i;
|
||||||
|
return platforms[level][chosenIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:firo_runner/Coin.dart';
|
import 'package:firo_runner/Coin.dart';
|
||||||
|
import 'package:firo_runner/Wire.dart';
|
||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/effects.dart';
|
import 'package:flame/effects.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -72,17 +73,16 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
runnerState = event;
|
runnerState = event;
|
||||||
sprite.current = RunnerState.jump;
|
sprite.current = RunnerState.float;
|
||||||
sprite.addEffect(MoveEffect(
|
sprite.addEffect(MoveEffect(
|
||||||
path: [
|
path: [
|
||||||
sprite.position,
|
|
||||||
Vector2(sprite.x, (level - 2) * gameRef.blockSize),
|
Vector2(sprite.x, (level - 2) * gameRef.blockSize),
|
||||||
],
|
],
|
||||||
speed: 50,
|
speed: 100,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
runnerState = "run";
|
this.event("float");
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
@ -96,13 +96,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
speed: 100,
|
speed: 100,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
if (runnerState == "fall") {
|
updateLevel();
|
||||||
updateLevel();
|
this.event("float");
|
||||||
sprite.position = Vector2(sprite.x, level * gameRef.blockSize);
|
|
||||||
this.event("run");
|
|
||||||
} else {
|
|
||||||
this.event("float");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
@ -119,7 +114,7 @@ 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: 50,
|
speed: 500,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
@ -227,8 +222,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
onTopOfPlatform = true;
|
onTopOfPlatform = true;
|
||||||
}
|
}
|
||||||
} else if (side == "bottom") {
|
} else if (side == "bottom") {
|
||||||
// The runner has hit his head on the ceiling and should die.
|
|
||||||
event("die");
|
event("die");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,6 +232,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
for (int i = 0; i < coinLevel.length;) {
|
for (int i = 0; i < coinLevel.length;) {
|
||||||
if (coinLevel[i].intersect(runnerRect) != "none") {
|
if (coinLevel[i].intersect(runnerRect) != "none") {
|
||||||
gameRef.gameState.numCoins++;
|
gameRef.gameState.numCoins++;
|
||||||
|
coinLevel[i].remove();
|
||||||
coinLevel.removeAt(i);
|
coinLevel.removeAt(i);
|
||||||
print(gameRef.gameState.numCoins);
|
print(gameRef.gameState.numCoins);
|
||||||
continue;
|
continue;
|
||||||
@ -245,6 +241,14 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (List<Wire> wireLevel in gameRef.wireHolder.wires) {
|
||||||
|
for (int i = 0; i < wireLevel.length; i++) {
|
||||||
|
if (wireLevel[i].intersect(runnerRect) != "none") {
|
||||||
|
event("electro");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!onTopOfPlatform &&
|
if (!onTopOfPlatform &&
|
||||||
(runnerState == "run" ||
|
(runnerState == "run" ||
|
||||||
runnerState == "kick" ||
|
runnerState == "kick" ||
|
||||||
@ -293,24 +297,24 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
SpriteAnimation floating = await loadSpriteAnimation(
|
SpriteAnimation floating = await loadSpriteAnimation(
|
||||||
'run-frames.png',
|
'hover-frames.png',
|
||||||
SpriteAnimationData.sequenced(
|
SpriteAnimationData.sequenced(
|
||||||
amount: 1,
|
amount: 3,
|
||||||
stepTime: 0.1,
|
stepTime: 0.1,
|
||||||
textureSize: Vector2(512, 512),
|
textureSize: Vector2(512, 512),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
SpriteAnimation falling = await loadSpriteAnimation(
|
SpriteAnimation falling = await loadSpriteAnimation(
|
||||||
'run-frames.png',
|
'hover-frames.png',
|
||||||
SpriteAnimationData.sequenced(
|
SpriteAnimationData.sequenced(
|
||||||
amount: 1,
|
amount: 3,
|
||||||
stepTime: 0.1,
|
stepTime: 0.1,
|
||||||
textureSize: Vector2(512, 512),
|
textureSize: Vector2(512, 512),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
SpriteAnimation dieing = await loadSpriteAnimation(
|
SpriteAnimation dying = await loadSpriteAnimation(
|
||||||
'death-normal-frames.png',
|
'death-normal-frames.png',
|
||||||
SpriteAnimationData.sequenced(
|
SpriteAnimationData.sequenced(
|
||||||
amount: 20,
|
amount: 20,
|
||||||
@ -320,8 +324,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
SpriteAnimation dieingElectorcuted = await loadSpriteAnimation(
|
SpriteAnimation dyingElectrocuted = await loadSpriteAnimation(
|
||||||
'electrecuted-frames.png',
|
'electrocuted-frames.png',
|
||||||
SpriteAnimationData.sequenced(
|
SpriteAnimationData.sequenced(
|
||||||
amount: 2,
|
amount: 2,
|
||||||
stepTime: 0.1,
|
stepTime: 0.1,
|
||||||
@ -337,10 +341,12 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
RunnerState.kick: kicking,
|
RunnerState.kick: kicking,
|
||||||
RunnerState.float: floating,
|
RunnerState.float: floating,
|
||||||
RunnerState.fall: falling,
|
RunnerState.fall: falling,
|
||||||
RunnerState.die: dieing,
|
RunnerState.die: dying,
|
||||||
RunnerState.electro: dieingElectorcuted,
|
RunnerState.electro: dyingElectrocuted,
|
||||||
},
|
},
|
||||||
current: RunnerState.run,
|
current: RunnerState.run,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
changePriorityWithoutResorting(RUNNER_PRIORITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
lib/Wire.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:firo_runner/MovingObject.dart';
|
||||||
|
import 'package:firo_runner/main.dart';
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
|
||||||
|
enum WireState { normal }
|
||||||
|
|
||||||
|
class Wire extends MovingObject {
|
||||||
|
Wire(MyGame gameRef) : super(gameRef) {
|
||||||
|
var wire = gameRef.wireHolder.getWire();
|
||||||
|
SpriteAnimation normal = SpriteAnimation.fromFrameData(
|
||||||
|
wire,
|
||||||
|
SpriteAnimationData.sequenced(
|
||||||
|
amount: 6,
|
||||||
|
stepTime: 0.1,
|
||||||
|
textureSize: Vector2(512, 512),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
sprite = SpriteAnimationGroupComponent(
|
||||||
|
animations: {
|
||||||
|
WireState.normal: normal,
|
||||||
|
},
|
||||||
|
current: WireState.normal,
|
||||||
|
);
|
||||||
|
|
||||||
|
sprite.changePriorityWithoutResorting(WIRE_PRIORITY);
|
||||||
|
|
||||||
|
setSize(
|
||||||
|
gameRef.blockSize,
|
||||||
|
gameRef.blockSize,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double getRightEnd() {
|
||||||
|
return sprite.position.x + sprite.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove() {
|
||||||
|
sprite.remove();
|
||||||
|
}
|
||||||
|
}
|
103
lib/WireHolder.dart
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:firo_runner/Platform.dart';
|
||||||
|
import 'package:flame/flame.dart';
|
||||||
|
|
||||||
|
import 'Wire.dart';
|
||||||
|
import 'main.dart';
|
||||||
|
|
||||||
|
class WireHolder {
|
||||||
|
var wire;
|
||||||
|
Random random = Random();
|
||||||
|
|
||||||
|
late List<List<Wire>> wires = [];
|
||||||
|
|
||||||
|
Future loadWires() async {
|
||||||
|
wire = await Flame.images.load("wire-frames.png");
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
wires.add([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getWire() {
|
||||||
|
return wire;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool generateWire(MyGame gameRef, int level, bool force) {
|
||||||
|
if (wires[level].isNotEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (random.nextInt(100) > 100) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
int nearestPlatform = level <= 0
|
||||||
|
? 0
|
||||||
|
: level <= 3
|
||||||
|
? 2
|
||||||
|
: level <= 6
|
||||||
|
? 5
|
||||||
|
: 8;
|
||||||
|
|
||||||
|
Platform? platform =
|
||||||
|
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
||||||
|
double xCoordinate = -100;
|
||||||
|
|
||||||
|
if (level == 0) {
|
||||||
|
xCoordinate = gameRef.size.x;
|
||||||
|
} else if (platform != null) {
|
||||||
|
xCoordinate = platform.sprite.x;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Wire wire = Wire(gameRef);
|
||||||
|
if (level % 3 == 0) {
|
||||||
|
wire.sprite.renderFlipY = true;
|
||||||
|
wire.setPosition(
|
||||||
|
xCoordinate, gameRef.blockSize * level - gameRef.blockSize / 6);
|
||||||
|
} else {
|
||||||
|
wire.setPosition(
|
||||||
|
xCoordinate, gameRef.blockSize * level + gameRef.blockSize / 10);
|
||||||
|
}
|
||||||
|
wires[level].add(wire);
|
||||||
|
gameRef.add(wire.sprite);
|
||||||
|
if (platform != null) {
|
||||||
|
platform.removeChildren = () {
|
||||||
|
wires[level].remove(wire);
|
||||||
|
wire.remove();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalWires() {
|
||||||
|
int total = 0;
|
||||||
|
for (List<Wire> levelWires in wires) {
|
||||||
|
total += levelWires.length;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(double dt) {
|
||||||
|
for (List<Wire> wireLevel in wires) {
|
||||||
|
for (Wire p in wireLevel) {
|
||||||
|
p.update(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removePast(MyGame gameRef) {
|
||||||
|
for (List<Wire> wireLevel in wires) {
|
||||||
|
for (int i = 0; i < wireLevel.length;) {
|
||||||
|
if (wireLevel[i].sprite.x + wireLevel[i].sprite.width < 0) {
|
||||||
|
wireLevel[i].sprite.remove();
|
||||||
|
wireLevel.removeAt(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,26 +2,27 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:firo_runner/CoinHolder.dart';
|
import 'package:firo_runner/CoinHolder.dart';
|
||||||
import 'package:firo_runner/GameState.dart';
|
import 'package:firo_runner/GameState.dart';
|
||||||
import 'package:firo_runner/MovingObject.dart';
|
|
||||||
import 'package:firo_runner/Platform.dart';
|
|
||||||
import 'package:firo_runner/PlatformHolder.dart';
|
import 'package:firo_runner/PlatformHolder.dart';
|
||||||
|
import 'package:firo_runner/Wire.dart';
|
||||||
|
import 'package:firo_runner/WireHolder.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flame/extensions.dart';
|
import 'package:flame/extensions.dart';
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/gestures.dart';
|
import 'package:flame/gestures.dart';
|
||||||
import 'package:flame/keyboard.dart';
|
import 'package:flame/keyboard.dart';
|
||||||
import 'package:flame/palette.dart';
|
|
||||||
import 'package:flame_audio/flame_audio.dart';
|
import 'package:flame_audio/flame_audio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flame_audio/bgm.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'Runner.dart';
|
import 'Runner.dart';
|
||||||
|
|
||||||
const COLOR = const Color(0xFFDDC0A3);
|
const COLOR = const Color(0xFFDDC0A3);
|
||||||
const SIZE = 52.0;
|
|
||||||
const GRAVITY = 400.0;
|
const RUNNER_PRIORITY = 100;
|
||||||
const BOOST = -380.0;
|
const PLATFORM_PRIORITY = 50;
|
||||||
|
const WIRE_PRIORITY = 25;
|
||||||
|
const COIN_PRIORITY = 70;
|
||||||
|
const BUG_PRIORITY = 75;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@ -37,7 +38,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
);
|
);
|
||||||
|
|
||||||
late PlatformHolder platformHolder;
|
late PlatformHolder platformHolder;
|
||||||
late Coinholder coinHolder;
|
late CoinHolder coinHolder;
|
||||||
|
late WireHolder wireHolder;
|
||||||
Random random = Random();
|
Random random = Random();
|
||||||
|
|
||||||
late Sprite background1;
|
late Sprite background1;
|
||||||
@ -45,12 +47,6 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
late Runner runner;
|
late Runner runner;
|
||||||
late GameState gameState;
|
late GameState gameState;
|
||||||
var background;
|
var background;
|
||||||
late var platform1;
|
|
||||||
late var platform2;
|
|
||||||
late var platform3;
|
|
||||||
late var wire;
|
|
||||||
late var bug;
|
|
||||||
late var coin;
|
|
||||||
|
|
||||||
var runnerPosition = Vector2(0, 0);
|
var runnerPosition = Vector2(0, 0);
|
||||||
var runnerSize;
|
var runnerSize;
|
||||||
@ -60,25 +56,22 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
late double blockSize;
|
late double blockSize;
|
||||||
|
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
late Wire wire;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
debugMode = true;
|
// debugMode = true;
|
||||||
FlameAudio.bgm.initialize();
|
FlameAudio.bgm.initialize();
|
||||||
background = await Flame.images.load('bg.png');
|
background = await Flame.images.load('bg.png');
|
||||||
background1 = Sprite(background);
|
background1 = Sprite(background);
|
||||||
background2 = Sprite(background);
|
background2 = Sprite(background);
|
||||||
platform1 = await Flame.images.load('platform1.png');
|
|
||||||
platform2 = await Flame.images.load('platform2.png');
|
|
||||||
platform3 = await Flame.images.load('platform3.png');
|
|
||||||
wire = await Flame.images.load('wire.png');
|
|
||||||
bug = await Flame.images.load('bug.png');
|
|
||||||
coin = await Flame.images.load('coin.png');
|
|
||||||
|
|
||||||
platformHolder = PlatformHolder();
|
platformHolder = PlatformHolder();
|
||||||
await platformHolder.loadPlatforms();
|
await platformHolder.loadPlatforms();
|
||||||
coinHolder = Coinholder();
|
coinHolder = CoinHolder();
|
||||||
await coinHolder.loadCoins();
|
await coinHolder.loadCoins();
|
||||||
|
wireHolder = WireHolder();
|
||||||
|
await wireHolder.loadWires();
|
||||||
|
|
||||||
gameState = GameState();
|
gameState = GameState();
|
||||||
await gameState.load(size);
|
await gameState.load(size);
|
||||||
@ -102,9 +95,14 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
|
|
||||||
void fillScreen() {
|
void fillScreen() {
|
||||||
for (int i = 2; i < 9; i = i + 3) {
|
for (int i = 2; i < 9; i = i + 3) {
|
||||||
while (!platformHolder.generatePlatform(this, i, false));
|
while (!platformHolder.generatePlatform(this, i, false)) {}
|
||||||
}
|
}
|
||||||
int choseCoinLevel = random.nextInt(9);
|
int wireChosenRegion = random.nextInt(8) + 1;
|
||||||
|
if (wireChosenRegion % 3 != 2) {
|
||||||
|
wireHolder.generateWire(this, wireChosenRegion, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int choseCoinLevel = random.nextInt(8) + 1;
|
||||||
if (choseCoinLevel % 3 != 2) {
|
if (choseCoinLevel % 3 != 2) {
|
||||||
coinHolder.generateCoin(this, choseCoinLevel, false);
|
coinHolder.generateCoin(this, choseCoinLevel, false);
|
||||||
}
|
}
|
||||||
@ -119,8 +117,6 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
size: Vector2(size.y * (background!.width / background!.height), size.y),
|
size: Vector2(size.y * (background!.width / background!.height), size.y),
|
||||||
);
|
);
|
||||||
super.render(canvas);
|
super.render(canvas);
|
||||||
platformHolder.render(canvas);
|
|
||||||
coinHolder.render(canvas);
|
|
||||||
final fpsCount = fps(1);
|
final fpsCount = fps(1);
|
||||||
textPaint.render(
|
textPaint.render(
|
||||||
canvas,
|
canvas,
|
||||||
@ -133,11 +129,13 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
platformHolder.removePast(this);
|
platformHolder.removePast(this);
|
||||||
coinHolder.removePast(this);
|
coinHolder.removePast(this);
|
||||||
|
wireHolder.removePast(this);
|
||||||
fillScreen();
|
fillScreen();
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
gameState.update(dt);
|
gameState.update(dt);
|
||||||
platformHolder.update(dt);
|
platformHolder.update(dt);
|
||||||
coinHolder.update(dt);
|
coinHolder.update(dt);
|
||||||
|
wireHolder.update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -157,36 +155,36 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mobile controls
|
// Mobile controls
|
||||||
late List<double> xdeltas;
|
late List<double> xDeltas;
|
||||||
late List<double> ydeltas;
|
late List<double> yDeltas;
|
||||||
@override
|
@override
|
||||||
void onPanStart(DragStartInfo info) {
|
void onPanStart(DragStartInfo info) {
|
||||||
xdeltas = List.empty(growable: true);
|
xDeltas = List.empty(growable: true);
|
||||||
ydeltas = List.empty(growable: true);
|
yDeltas = List.empty(growable: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onPanUpdate(DragUpdateInfo info) {
|
void onPanUpdate(DragUpdateInfo info) {
|
||||||
xdeltas.add(info.delta.game.x);
|
xDeltas.add(info.delta.game.x);
|
||||||
ydeltas.add(info.delta.game.y);
|
yDeltas.add(info.delta.game.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onPanEnd(DragEndInfo info) {
|
void onPanEnd(DragEndInfo info) {
|
||||||
double xdelta = xdeltas.isEmpty
|
double xDelta = xDeltas.isEmpty
|
||||||
? 0
|
? 0
|
||||||
: xdeltas.reduce((value, element) => value + element);
|
: xDeltas.reduce((value, element) => value + element);
|
||||||
double ydelta = ydeltas.isEmpty
|
double yDelta = yDeltas.isEmpty
|
||||||
? 0
|
? 0
|
||||||
: ydeltas.reduce((value, element) => value + element);
|
: yDeltas.reduce((value, element) => value + element);
|
||||||
if (xdelta.abs() > ydelta.abs()) {
|
if (xDelta.abs() > yDelta.abs()) {
|
||||||
if (xdelta > 0) {
|
if (xDelta > 0) {
|
||||||
runner.control("right");
|
runner.control("right");
|
||||||
} else {
|
} else {
|
||||||
runner.control("left");
|
runner.control("left");
|
||||||
}
|
}
|
||||||
} else if (xdelta.abs() < ydelta.abs()) {
|
} else if (xDelta.abs() < yDelta.abs()) {
|
||||||
if (ydelta > 0) {
|
if (yDelta > 0) {
|
||||||
runner.control("down");
|
runner.control("down");
|
||||||
} else {
|
} else {
|
||||||
runner.control("up");
|
runner.control("up");
|
||||||
|