Added the finished platforms and updated how to decide which version is used.
Before Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 395 KiB |
Before Width: | Height: | Size: 397 KiB |
BIN
assets/images/platform-left-nowire-frames.png
Normal file
After Width: | Height: | Size: 264 KiB |
BIN
assets/images/platform-left-wire-frames.png
Normal file
After Width: | Height: | Size: 331 KiB |
BIN
assets/images/platform-mid-nowire-frames.png
Normal file
After Width: | Height: | Size: 333 KiB |
BIN
assets/images/platform-mid-wire-frames.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
assets/images/platform-right-nowire-frames.png
Normal file
After Width: | Height: | Size: 297 KiB |
BIN
assets/images/platform-right-wire-frames.png
Normal file
After Width: | Height: | Size: 365 KiB |
BIN
assets/images/platform-single-nowire-frames.png
Normal file
After Width: | Height: | Size: 365 KiB |
BIN
assets/images/platform-single-wire-frames.png
Normal file
After Width: | Height: | Size: 444 KiB |
@ -25,7 +25,7 @@ class Coin extends MovingObject {
|
|||||||
|
|
||||||
sprite.changePriorityWithoutResorting(COIN_PRIORITY);
|
sprite.changePriorityWithoutResorting(COIN_PRIORITY);
|
||||||
|
|
||||||
var platform = gameRef.platformHolder.getPlatform(0);
|
var platform = gameRef.platformHolder.l1;
|
||||||
|
|
||||||
setSize(
|
setSize(
|
||||||
gameRef.blockSize * (platform!.width / platform!.height / 14),
|
gameRef.blockSize * (platform!.width / platform!.height / 14),
|
||||||
|
@ -4,35 +4,75 @@ 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';
|
||||||
|
|
||||||
enum PlatformState { normal }
|
enum PlatformState {
|
||||||
|
left,
|
||||||
|
mid,
|
||||||
|
right,
|
||||||
|
single,
|
||||||
|
}
|
||||||
|
|
||||||
class Platform extends MovingObject {
|
class Platform extends MovingObject {
|
||||||
|
int row = 0;
|
||||||
List<Function> removeChildren = [];
|
List<Function> removeChildren = [];
|
||||||
|
|
||||||
Platform(MyGame gameRef) : super(gameRef) {
|
Platform(MyGame gameRef) : super(gameRef) {
|
||||||
var random = Random();
|
var random = Random();
|
||||||
int version = random.nextInt(3) + 1;
|
|
||||||
var platform = gameRef.platformHolder.getPlatform(version);
|
int version = random.nextInt(2);
|
||||||
SpriteAnimation normal = SpriteAnimation.fromFrameData(
|
|
||||||
platform,
|
SpriteAnimation left = SpriteAnimation.fromFrameData(
|
||||||
|
version == 0 ? gameRef.platformHolder.l1 : gameRef.platformHolder.l2,
|
||||||
SpriteAnimationData.sequenced(
|
SpriteAnimationData.sequenced(
|
||||||
amount: 7,
|
amount: 5,
|
||||||
stepTime: 0.1,
|
stepTime: 0.12,
|
||||||
textureSize: Vector2(800, 510),
|
textureSize: Vector2(1000, 807),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
SpriteAnimation mid = SpriteAnimation.fromFrameData(
|
||||||
|
version == 0 ? gameRef.platformHolder.m1 : gameRef.platformHolder.m2,
|
||||||
|
SpriteAnimationData.sequenced(
|
||||||
|
amount: 5,
|
||||||
|
stepTime: 0.12,
|
||||||
|
textureSize: Vector2(1000, 807),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
SpriteAnimation right = SpriteAnimation.fromFrameData(
|
||||||
|
version == 0 ? gameRef.platformHolder.r1 : gameRef.platformHolder.r2,
|
||||||
|
SpriteAnimationData.sequenced(
|
||||||
|
amount: 5,
|
||||||
|
stepTime: 0.12,
|
||||||
|
textureSize: Vector2(1000, 807),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
SpriteAnimation single = SpriteAnimation.fromFrameData(
|
||||||
|
version == 0 ? gameRef.platformHolder.o1 : gameRef.platformHolder.o2,
|
||||||
|
SpriteAnimationData.sequenced(
|
||||||
|
amount: 5,
|
||||||
|
stepTime: 0.12,
|
||||||
|
textureSize: Vector2(1000, 807),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
sprite = SpriteAnimationGroupComponent(
|
sprite = SpriteAnimationGroupComponent(
|
||||||
animations: {
|
animations: {
|
||||||
PlatformState.normal: normal,
|
PlatformState.left: left,
|
||||||
|
PlatformState.mid: mid,
|
||||||
|
PlatformState.right: right,
|
||||||
|
PlatformState.single: single,
|
||||||
},
|
},
|
||||||
current: PlatformState.normal,
|
current: PlatformState.single,
|
||||||
);
|
);
|
||||||
|
|
||||||
sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY);
|
sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY);
|
||||||
|
|
||||||
setSize(
|
setSize(
|
||||||
gameRef.blockSize * (platform!.width / platform!.height / 7),
|
gameRef.blockSize *
|
||||||
|
(gameRef.platformHolder.l1!.width /
|
||||||
|
gameRef.platformHolder.l1!.height /
|
||||||
|
5),
|
||||||
gameRef.blockSize,
|
gameRef.blockSize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,4 +88,35 @@ class Platform extends MovingObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void update(double dt) {
|
||||||
|
List<Platform> platformLevel = gameRef.platformHolder.platforms[row];
|
||||||
|
int index = platformLevel.indexOf(this);
|
||||||
|
Vector2 right = Vector2(-200, -200);
|
||||||
|
if (index + 1 < platformLevel.length) {
|
||||||
|
right = platformLevel.elementAt(index + 1).sprite.position;
|
||||||
|
}
|
||||||
|
super.update(dt);
|
||||||
|
if (index == -1 || sprite.position.x <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector2 left = Vector2(-200, -200);
|
||||||
|
if (index - 1 >= 0) {
|
||||||
|
left = platformLevel.elementAt(index - 1).sprite.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasLeft = (left.x - sprite.position.x).abs() < 1.9 * sprite.size.x;
|
||||||
|
bool hasRight = (sprite.position.x - right.x).abs() < 1.9 * sprite.size.x;
|
||||||
|
|
||||||
|
if (hasLeft && hasRight) {
|
||||||
|
sprite.current = PlatformState.mid;
|
||||||
|
} else if (hasLeft && !hasRight) {
|
||||||
|
sprite.current = PlatformState.right;
|
||||||
|
} else if (!hasLeft && hasRight) {
|
||||||
|
sprite.current = PlatformState.left;
|
||||||
|
} else {
|
||||||
|
sprite.current = PlatformState.single;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,26 @@ import 'package:flame/flame.dart';
|
|||||||
import 'Platform.dart';
|
import 'Platform.dart';
|
||||||
|
|
||||||
class PlatformHolder {
|
class PlatformHolder {
|
||||||
var platform1;
|
var l1;
|
||||||
var platform2;
|
var l2;
|
||||||
var platform3;
|
var m1;
|
||||||
|
var m2;
|
||||||
|
var r1;
|
||||||
|
var r2;
|
||||||
|
var o1;
|
||||||
|
var o2;
|
||||||
late List<List<Platform>> platforms = [];
|
late List<List<Platform>> platforms = [];
|
||||||
Random random = Random();
|
Random random = Random();
|
||||||
|
|
||||||
Future loadPlatforms() async {
|
Future loadPlatforms() async {
|
||||||
platform1 = await Flame.images.load('p1-frames.png');
|
l1 = await Flame.images.load('platform-left-nowire-frames.png');
|
||||||
platform2 = await Flame.images.load('p2-frames.png');
|
l2 = await Flame.images.load('platform-left-wire-frames.png');
|
||||||
platform3 = await Flame.images.load('p3-frames.png');
|
m1 = await Flame.images.load('platform-mid-nowire-frames.png');
|
||||||
|
m2 = await Flame.images.load('platform-mid-wire-frames.png');
|
||||||
|
r1 = await Flame.images.load('platform-right-nowire-frames.png');
|
||||||
|
r2 = await Flame.images.load('platform-right-wire-frames.png');
|
||||||
|
o1 = await Flame.images.load('platform-single-nowire-frames.png');
|
||||||
|
o2 = await Flame.images.load('platform-single-wire-frames.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUp() {
|
void setUp() {
|
||||||
@ -29,17 +39,6 @@ class PlatformHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlatform(int imageNumber) {
|
|
||||||
switch (imageNumber) {
|
|
||||||
case 1:
|
|
||||||
return platform1;
|
|
||||||
case 2:
|
|
||||||
return platform2;
|
|
||||||
default:
|
|
||||||
return platform3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool generatePlatform(MyGame gameRef, int level, bool force) {
|
bool generatePlatform(MyGame gameRef, int level, bool force) {
|
||||||
double xCoordinate = 0;
|
double xCoordinate = 0;
|
||||||
if (platforms[level].isNotEmpty) {
|
if (platforms[level].isNotEmpty) {
|
||||||
@ -51,6 +50,7 @@ class PlatformHolder {
|
|||||||
} else {
|
} else {
|
||||||
Platform platform = Platform(gameRef);
|
Platform platform = Platform(gameRef);
|
||||||
platform.setPosition(xCoordinate, gameRef.blockSize * level);
|
platform.setPosition(xCoordinate, gameRef.blockSize * level);
|
||||||
|
platform.row = level;
|
||||||
gameRef.add(platform.sprite);
|
gameRef.add(platform.sprite);
|
||||||
platforms[level].add(platform);
|
platforms[level].add(platform);
|
||||||
return false;
|
return false;
|
||||||
|
@ -41,7 +41,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
setSize(runnerSize, gameRef.blockSize);
|
setSize(runnerSize, gameRef.blockSize);
|
||||||
runnerPosition = Vector2(gameRef.blockSize, gameRef.blockSize * 4);
|
runnerPosition = Vector2(gameRef.blockSize * 2, gameRef.blockSize * 4);
|
||||||
setPosition(runnerPosition);
|
setPosition(runnerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class WireHolder {
|
|||||||
if (level % 3 == 0) {
|
if (level % 3 == 0) {
|
||||||
wire.sprite.renderFlipY = true;
|
wire.sprite.renderFlipY = true;
|
||||||
wire.setPosition(
|
wire.setPosition(
|
||||||
xCoordinate, gameRef.blockSize * level - gameRef.blockSize / 6);
|
xCoordinate, gameRef.blockSize * level - 2 * gameRef.blockSize / 7);
|
||||||
} else {
|
} else {
|
||||||
wire.setPosition(
|
wire.setPosition(
|
||||||
xCoordinate, gameRef.blockSize * level + gameRef.blockSize / 10);
|
xCoordinate, gameRef.blockSize * level + gameRef.blockSize / 10);
|
||||||
|