2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/bug.dart';
|
2021-09-16 21:15:32 +00:00
|
|
|
import 'package:firo_runner/moving_object.dart';
|
2021-09-02 22:30:18 +00:00
|
|
|
import 'package:firo_runner/main.dart';
|
|
|
|
import 'package:flame/effects.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:flame/extensions.dart';
|
2021-09-02 22:30:18 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-17 01:03:11 +00:00
|
|
|
import 'dart:math';
|
2021-09-02 22:30:18 +00:00
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
|
|
|
enum RunnerState {
|
|
|
|
run,
|
|
|
|
jump,
|
|
|
|
duck,
|
|
|
|
kick,
|
|
|
|
float,
|
|
|
|
fall,
|
|
|
|
die,
|
2021-09-08 21:44:12 +00:00
|
|
|
electrocute,
|
2021-09-06 22:28:56 +00:00
|
|
|
glitch,
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Runner extends Component with HasGameRef<MyGame> {
|
|
|
|
late SpriteAnimationGroupComponent sprite;
|
2021-09-04 03:03:05 +00:00
|
|
|
String runnerState = "run";
|
2021-09-05 22:36:36 +00:00
|
|
|
int level = 4;
|
|
|
|
String previousState = "run";
|
|
|
|
var runnerPosition = Vector2(0, 0);
|
2021-09-08 21:44:12 +00:00
|
|
|
late Vector2 runnerSize;
|
2021-09-16 17:38:46 +00:00
|
|
|
// late Rect runnerRect;
|
2021-09-05 22:36:36 +00:00
|
|
|
bool dead = false;
|
|
|
|
|
|
|
|
void setUp() {
|
|
|
|
dead = false;
|
|
|
|
runnerState = "run";
|
|
|
|
previousState = "run";
|
|
|
|
level = 4;
|
|
|
|
|
|
|
|
runnerSize = Vector2(
|
|
|
|
gameRef.size.y / 9,
|
|
|
|
gameRef.size.y / 9,
|
|
|
|
);
|
|
|
|
|
|
|
|
setSize(runnerSize, gameRef.blockSize);
|
2021-09-08 19:27:06 +00:00
|
|
|
runnerPosition = Vector2(gameRef.blockSize * 2, gameRef.blockSize * 4);
|
2021-09-05 22:36:36 +00:00
|
|
|
setPosition(runnerPosition);
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
|
|
|
|
void setPosition(Vector2 position) {
|
|
|
|
sprite.position = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSize(Vector2 size, double ySize) {
|
|
|
|
sprite.size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite getSprite() {
|
|
|
|
return sprite.animation!.getSprite();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void render(Canvas c) {
|
|
|
|
super.render(c);
|
|
|
|
getSprite().render(c, position: sprite.position, size: sprite.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateLevel() {
|
|
|
|
level = (sprite.position.y / gameRef.blockSize).round();
|
|
|
|
}
|
|
|
|
|
|
|
|
void event(String event) {
|
2021-09-05 22:36:36 +00:00
|
|
|
if (gameRef.gameState.isPaused) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-04 03:03:05 +00:00
|
|
|
previousState = runnerState;
|
2021-09-02 22:30:18 +00:00
|
|
|
switch (event) {
|
|
|
|
case "jump":
|
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.jump;
|
|
|
|
sprite.addEffect(MoveEffect(
|
|
|
|
path: [
|
|
|
|
// sprite.position,
|
|
|
|
Vector2(sprite.x, (level - 1) * gameRef.blockSize),
|
|
|
|
],
|
2021-09-13 19:21:52 +00:00
|
|
|
duration: 0.25,
|
2021-09-02 22:30:18 +00:00
|
|
|
curve: Curves.bounceIn,
|
|
|
|
onComplete: () {
|
|
|
|
updateLevel();
|
2021-09-04 03:03:05 +00:00
|
|
|
this.event("float");
|
2021-09-02 22:30:18 +00:00
|
|
|
},
|
|
|
|
));
|
|
|
|
break;
|
2021-09-08 21:44:12 +00:00
|
|
|
case "double_jump":
|
2021-09-13 19:21:52 +00:00
|
|
|
if (belowPlatform()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprite.clearEffects();
|
2021-09-04 03:03:05 +00:00
|
|
|
if (level - 1 < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
runnerState = event;
|
2021-09-04 22:56:08 +00:00
|
|
|
sprite.current = RunnerState.float;
|
2021-09-02 22:30:18 +00:00
|
|
|
sprite.addEffect(MoveEffect(
|
|
|
|
path: [
|
2021-09-04 03:03:05 +00:00
|
|
|
Vector2(sprite.x, (level - 2) * gameRef.blockSize),
|
2021-09-02 22:30:18 +00:00
|
|
|
],
|
2021-09-16 17:38:46 +00:00
|
|
|
duration: 0.5,
|
2021-09-03 23:29:18 +00:00
|
|
|
curve: Curves.ease,
|
2021-09-02 22:30:18 +00:00
|
|
|
onComplete: () {
|
|
|
|
updateLevel();
|
2021-09-13 19:21:52 +00:00
|
|
|
if (onTopOfPlatform()) {
|
|
|
|
this.event("run");
|
|
|
|
} else {
|
|
|
|
this.event("float");
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
},
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case "fall":
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
2021-09-02 22:30:18 +00:00
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.fall;
|
2021-09-17 01:03:11 +00:00
|
|
|
sprite.addEffect(getFallingEffect());
|
2021-09-02 22:30:18 +00:00
|
|
|
break;
|
|
|
|
case "kick":
|
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.kick;
|
|
|
|
break;
|
|
|
|
case "run":
|
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.run;
|
|
|
|
break;
|
|
|
|
case "float":
|
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.float;
|
|
|
|
sprite.addEffect(MoveEffect(
|
2021-09-04 03:03:05 +00:00
|
|
|
path: [sprite.position],
|
2021-09-13 19:21:52 +00:00
|
|
|
duration: 1.5,
|
2021-09-02 22:30:18 +00:00
|
|
|
curve: Curves.ease,
|
|
|
|
onComplete: () {
|
|
|
|
updateLevel();
|
2021-09-13 19:21:52 +00:00
|
|
|
if (onTopOfPlatform()) {
|
|
|
|
this.event("run");
|
|
|
|
} else {
|
|
|
|
this.event("fall");
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
},
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case "duck":
|
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.duck;
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.addEffect(MoveEffect(
|
|
|
|
path: [sprite.position],
|
|
|
|
duration: 1.5,
|
|
|
|
curve: Curves.linear,
|
|
|
|
onComplete: () {
|
|
|
|
this.event("run");
|
|
|
|
},
|
|
|
|
));
|
2021-09-02 22:30:18 +00:00
|
|
|
break;
|
|
|
|
case "die":
|
2021-09-05 22:36:36 +00:00
|
|
|
if (dead) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
|
|
|
updateLevel();
|
2021-09-02 22:30:18 +00:00
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.die;
|
2021-09-05 22:36:36 +00:00
|
|
|
gameRef.die();
|
2021-09-02 22:30:18 +00:00
|
|
|
break;
|
2021-09-08 21:44:12 +00:00
|
|
|
case "electrocute":
|
2021-09-05 22:36:36 +00:00
|
|
|
if (dead) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
|
|
|
updateLevel();
|
2021-09-02 22:30:18 +00:00
|
|
|
runnerState = event;
|
2021-09-08 21:44:12 +00:00
|
|
|
sprite.current = RunnerState.electrocute;
|
2021-09-05 22:36:36 +00:00
|
|
|
gameRef.die();
|
2021-09-02 22:30:18 +00:00
|
|
|
break;
|
2021-09-06 22:28:56 +00:00
|
|
|
case "glitch":
|
|
|
|
if (dead) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
|
|
|
updateLevel();
|
2021-09-06 22:28:56 +00:00
|
|
|
runnerState = event;
|
|
|
|
sprite.current = RunnerState.glitch;
|
|
|
|
gameRef.die();
|
|
|
|
break;
|
2021-09-02 22:30:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:03:11 +00:00
|
|
|
MoveEffect getFallingEffect() {
|
|
|
|
for (int i = level; i < 9; i++) {
|
|
|
|
if (i % 3 != 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int distance = (i - 1 - level);
|
|
|
|
double time = 0.2;
|
|
|
|
for (int x = 2; x < distance; x++) {
|
|
|
|
time += time * pow(0.5, x - 1);
|
|
|
|
}
|
|
|
|
double estimatedXCoordinate =
|
|
|
|
time * gameRef.gameState.getVelocity() + sprite.x;
|
|
|
|
for (MovingObject p in gameRef.platformHolder.objects[i]) {
|
|
|
|
if (estimatedXCoordinate >= p.sprite.x - p.sprite.width / 2 &&
|
|
|
|
estimatedXCoordinate <= p.sprite.x + p.sprite.width) {
|
|
|
|
return MoveEffect(
|
|
|
|
path: [
|
|
|
|
Vector2(sprite.x, (i - 1) * gameRef.blockSize),
|
|
|
|
],
|
|
|
|
duration: time,
|
|
|
|
curve: Curves.ease,
|
|
|
|
onComplete: () {
|
|
|
|
updateLevel();
|
|
|
|
if (onTopOfPlatform()) {
|
|
|
|
event("run");
|
|
|
|
} else {
|
|
|
|
event("fall");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MoveEffect(
|
|
|
|
path: [
|
|
|
|
Vector2(sprite.x, 8 * gameRef.blockSize),
|
|
|
|
],
|
|
|
|
duration: 0.2 * (8 - level),
|
|
|
|
curve: Curves.ease,
|
|
|
|
onComplete: () {
|
|
|
|
updateLevel();
|
|
|
|
if (onTopOfPlatform()) {
|
|
|
|
event("run");
|
|
|
|
} else {
|
|
|
|
event("fall");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
void control(String input) {
|
2021-09-05 22:36:36 +00:00
|
|
|
if (gameRef.gameState.isPaused) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
switch (input) {
|
|
|
|
case "up":
|
|
|
|
if (runnerState == "run") {
|
|
|
|
event("jump");
|
2021-09-04 03:03:05 +00:00
|
|
|
} else if (runnerState == "float" && previousState == "jump") {
|
2021-09-08 21:44:12 +00:00
|
|
|
event("double_jump");
|
2021-09-02 22:30:18 +00:00
|
|
|
} else if (runnerState == "duck") {
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
2021-09-02 22:30:18 +00:00
|
|
|
event("run");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "down":
|
|
|
|
if (runnerState == "run") {
|
|
|
|
event("duck");
|
2021-09-04 03:03:05 +00:00
|
|
|
} else if (runnerState == "float" && onTopOfPlatform()) {
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
2021-09-04 03:03:05 +00:00
|
|
|
event("run");
|
2021-09-02 22:30:18 +00:00
|
|
|
} else if (runnerState == "float") {
|
2021-09-13 19:21:52 +00:00
|
|
|
sprite.clearEffects();
|
2021-09-02 22:30:18 +00:00
|
|
|
event("fall");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
if (runnerState == "run") {
|
|
|
|
event("kick");
|
|
|
|
}
|
|
|
|
break;
|
2021-09-14 17:23:02 +00:00
|
|
|
case "left":
|
|
|
|
if (runnerState == "kick") {
|
|
|
|
sprite.animation!.reset();
|
|
|
|
sprite.clearEffects();
|
|
|
|
event("run");
|
|
|
|
}
|
|
|
|
break;
|
2021-09-02 22:30:18 +00:00
|
|
|
case "center":
|
2021-09-13 19:21:52 +00:00
|
|
|
// if (runnerState == "fall") {
|
|
|
|
// updateLevel();
|
|
|
|
// event("float");
|
|
|
|
// }
|
2021-09-02 22:30:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void update(double dt) {
|
|
|
|
super.update(dt);
|
2021-09-10 19:25:01 +00:00
|
|
|
if (sprite.position.y + sprite.size.y >= gameRef.size.y) {
|
|
|
|
event("die");
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
// If the animation is finished
|
|
|
|
if (sprite.animation?.done() ?? false) {
|
|
|
|
sprite.animation!.reset();
|
|
|
|
if (runnerState == "kick") {
|
|
|
|
event("run");
|
|
|
|
}
|
|
|
|
sprite.current = RunnerState.run;
|
|
|
|
}
|
|
|
|
|
2021-09-04 03:03:05 +00:00
|
|
|
intersecting();
|
2021-09-02 22:30:18 +00:00
|
|
|
sprite.update(dt);
|
|
|
|
}
|
|
|
|
|
2021-09-04 03:03:05 +00:00
|
|
|
bool onTopOfPlatform() {
|
|
|
|
Rect runnerRect = sprite.toRect();
|
|
|
|
bool onTopOfPlatform = false;
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> platformLevel in gameRef.platformHolder.objects) {
|
|
|
|
for (MovingObject p in platformLevel) {
|
2021-09-04 03:03:05 +00:00
|
|
|
String side = p.intersect(runnerRect);
|
|
|
|
if (side == "none") {
|
|
|
|
Rect belowRunner = Rect.fromLTRB(runnerRect.left, runnerRect.top,
|
|
|
|
runnerRect.right, runnerRect.bottom + 1);
|
|
|
|
if (p.intersect(belowRunner) != "none") {
|
|
|
|
onTopOfPlatform = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return onTopOfPlatform;
|
|
|
|
}
|
|
|
|
|
2021-09-13 19:21:52 +00:00
|
|
|
bool belowPlatform() {
|
|
|
|
Rect runnerRect = sprite.toRect();
|
|
|
|
bool belowPlatform = false;
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> platformLevel in gameRef.platformHolder.objects) {
|
|
|
|
for (MovingObject p in platformLevel) {
|
2021-09-13 19:21:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-09-04 03:03:05 +00:00
|
|
|
void intersecting() {
|
2021-09-05 22:36:36 +00:00
|
|
|
if (gameRef.gameState.isPaused) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-04 03:03:05 +00:00
|
|
|
Rect runnerRect = sprite.toRect();
|
2021-09-16 17:38:46 +00:00
|
|
|
bool onTopOfPlatform = this.onTopOfPlatform();
|
2021-09-04 03:03:05 +00:00
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> coinLevel in gameRef.coinHolder.objects) {
|
2021-09-04 04:17:12 +00:00
|
|
|
for (int i = 0; i < coinLevel.length;) {
|
|
|
|
if (coinLevel[i].intersect(runnerRect) != "none") {
|
|
|
|
gameRef.gameState.numCoins++;
|
2021-09-09 22:56:26 +00:00
|
|
|
if (gameRef.gameState.numCoins % 5 == 0) {
|
|
|
|
gameRef.fireworks.reset();
|
|
|
|
}
|
2021-09-05 22:36:36 +00:00
|
|
|
gameRef.coinHolder.remove(coinLevel, i);
|
2021-09-04 04:17:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> wireLevel in gameRef.wireHolder.objects) {
|
2021-09-04 22:56:08 +00:00
|
|
|
for (int i = 0; i < wireLevel.length; i++) {
|
|
|
|
if (wireLevel[i].intersect(runnerRect) != "none") {
|
2021-09-08 21:44:12 +00:00
|
|
|
event("electrocute");
|
2021-09-05 22:36:36 +00:00
|
|
|
return;
|
2021-09-04 22:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> bugLevel in gameRef.bugHolder.objects) {
|
2021-09-05 00:18:37 +00:00
|
|
|
for (int i = 0; i < bugLevel.length; i++) {
|
|
|
|
String intersectState = bugLevel[i].intersect(runnerRect);
|
|
|
|
if (bugLevel[i].sprite.current == BugState.breaking) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (intersectState == "none") {
|
|
|
|
Rect above = Rect.fromLTRB(runnerRect.left, runnerRect.top - 1,
|
|
|
|
runnerRect.right, runnerRect.bottom);
|
|
|
|
String aboveIntersect = bugLevel[i].intersect(above);
|
|
|
|
if (aboveIntersect != "none" &&
|
|
|
|
(runnerState == "duck" || runnerState == "float")) {
|
|
|
|
continue;
|
|
|
|
} else if (aboveIntersect != "none") {
|
2021-09-06 22:28:56 +00:00
|
|
|
event("glitch");
|
2021-09-05 22:36:36 +00:00
|
|
|
return;
|
2021-09-05 00:18:37 +00:00
|
|
|
}
|
|
|
|
} else if (intersectState == "left" && runnerState == "kick") {
|
|
|
|
bugLevel[i].sprite.current = BugState.breaking;
|
2021-09-17 03:26:57 +00:00
|
|
|
gameRef.coinHolder.generateCoin(gameRef, level,
|
|
|
|
force: true, xPosition: bugLevel[i].sprite.x + gameRef.blockSize);
|
2021-09-05 00:18:37 +00:00
|
|
|
} else {
|
2021-09-06 22:28:56 +00:00
|
|
|
event("glitch");
|
2021-09-05 22:36:36 +00:00
|
|
|
return;
|
2021-09-05 00:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:39:42 +00:00
|
|
|
for (List<MovingObject> debrisLevel in gameRef.debrisHolder.objects) {
|
|
|
|
for (int i = 0; i < debrisLevel.length; i++) {
|
|
|
|
Rect slim = Rect.fromLTRB(
|
|
|
|
runnerRect.left + sprite.width / 3,
|
|
|
|
runnerRect.top,
|
|
|
|
runnerRect.right - sprite.width / 3,
|
|
|
|
runnerRect.bottom);
|
|
|
|
String intersectState = debrisLevel[i].intersect(slim);
|
|
|
|
if (intersectState == "none") {
|
|
|
|
continue;
|
2021-09-17 03:17:51 +00:00
|
|
|
} else if (runnerState == "duck" && intersectState != "above") {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
event("die");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (List<MovingObject> debrisLevel in gameRef.wallHolder.objects) {
|
|
|
|
for (int i = 0; i < debrisLevel.length; i++) {
|
|
|
|
Rect slim = Rect.fromLTRB(
|
|
|
|
runnerRect.left + sprite.width / 3,
|
|
|
|
runnerRect.top + sprite.height / (runnerState == "duck" ? 3 : 6),
|
|
|
|
runnerRect.right - sprite.width / 3,
|
|
|
|
runnerRect.bottom - sprite.height / 3);
|
|
|
|
String intersectState = debrisLevel[i].intersect(slim);
|
|
|
|
if (intersectState == "none") {
|
2021-09-17 01:39:42 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
event("die");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-04 03:03:05 +00:00
|
|
|
if (!onTopOfPlatform &&
|
|
|
|
(runnerState == "run" ||
|
|
|
|
runnerState == "kick" ||
|
|
|
|
runnerState == "duck")) {
|
|
|
|
event("fall");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
Future load(loadSpriteAnimation) async {
|
|
|
|
SpriteAnimation running = await loadSpriteAnimation(
|
|
|
|
'run-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 7,
|
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
SpriteAnimation jumping = await loadSpriteAnimation(
|
|
|
|
'jump-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 5,
|
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
loop: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
SpriteAnimation ducking = await loadSpriteAnimation(
|
|
|
|
'crawl-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 3,
|
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
SpriteAnimation kicking = await loadSpriteAnimation(
|
|
|
|
'kick-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
2021-09-14 17:23:02 +00:00
|
|
|
amount: 19,
|
|
|
|
stepTime: 0.03,
|
2021-09-02 22:30:18 +00:00
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
loop: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
SpriteAnimation floating = await loadSpriteAnimation(
|
2021-09-04 22:56:08 +00:00
|
|
|
'hover-frames.png',
|
2021-09-02 22:30:18 +00:00
|
|
|
SpriteAnimationData.sequenced(
|
2021-09-04 22:56:08 +00:00
|
|
|
amount: 3,
|
2021-09-02 22:30:18 +00:00
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
SpriteAnimation falling = await loadSpriteAnimation(
|
2021-09-09 22:56:26 +00:00
|
|
|
'fall-frames.png',
|
2021-09-02 22:30:18 +00:00
|
|
|
SpriteAnimationData.sequenced(
|
2021-09-09 22:56:26 +00:00
|
|
|
amount: 7,
|
2021-09-02 22:30:18 +00:00
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-09-04 22:56:08 +00:00
|
|
|
SpriteAnimation dying = await loadSpriteAnimation(
|
2021-09-02 22:30:18 +00:00
|
|
|
'death-normal-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 20,
|
2021-09-03 23:29:18 +00:00
|
|
|
stepTime: 0.05,
|
2021-09-02 22:30:18 +00:00
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
loop: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-09-04 22:56:08 +00:00
|
|
|
SpriteAnimation dyingElectrocuted = await loadSpriteAnimation(
|
|
|
|
'electrocuted-frames.png',
|
2021-09-02 22:30:18 +00:00
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 2,
|
2021-09-05 22:36:36 +00:00
|
|
|
stepTime: 0.25,
|
2021-09-02 22:30:18 +00:00
|
|
|
textureSize: Vector2(512, 512),
|
2021-09-05 22:36:36 +00:00
|
|
|
loop: false,
|
2021-09-02 22:30:18 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-09-06 22:28:56 +00:00
|
|
|
SpriteAnimation dyingGlitch = await loadSpriteAnimation(
|
|
|
|
'death-glitched-frames.png',
|
|
|
|
SpriteAnimationData.sequenced(
|
|
|
|
amount: 8,
|
|
|
|
stepTime: 0.1,
|
|
|
|
textureSize: Vector2(512, 512),
|
|
|
|
loop: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
sprite = SpriteAnimationGroupComponent(
|
|
|
|
animations: {
|
|
|
|
RunnerState.run: running,
|
|
|
|
RunnerState.jump: jumping,
|
|
|
|
RunnerState.duck: ducking,
|
|
|
|
RunnerState.kick: kicking,
|
|
|
|
RunnerState.float: floating,
|
|
|
|
RunnerState.fall: falling,
|
2021-09-04 22:56:08 +00:00
|
|
|
RunnerState.die: dying,
|
2021-09-08 21:44:12 +00:00
|
|
|
RunnerState.electrocute: dyingElectrocuted,
|
2021-09-06 22:28:56 +00:00
|
|
|
RunnerState.glitch: dyingGlitch,
|
2021-09-02 22:30:18 +00:00
|
|
|
},
|
|
|
|
current: RunnerState.run,
|
|
|
|
);
|
2021-09-04 22:56:08 +00:00
|
|
|
|
|
|
|
changePriorityWithoutResorting(RUNNER_PRIORITY);
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
2021-09-16 17:38:46 +00:00
|
|
|
|
|
|
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
|
|
|
sprite.x = gameRef.blockSize * 2;
|
|
|
|
sprite.y = gameRef.blockSize * level;
|
|
|
|
sprite.size.x = gameRef.blockSize;
|
|
|
|
sprite.size.y = gameRef.blockSize;
|
|
|
|
if (sprite.effects.isNotEmpty) {
|
|
|
|
sprite.effects.first.onComplete!();
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|