Fixed #1 such that resizing the window still keeps every item where it should be, and maintains collision on all platforms.
This commit is contained in:
parent
ee87a47672
commit
5e48cb0444
@ -117,4 +117,14 @@ class BugHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
for (List<Bug> platformLevel in bugs) {
|
||||||
|
for (Bug p in platformLevel) {
|
||||||
|
p.resize(newSize, xRatio, yRatio);
|
||||||
|
p.sprite.y = (p.sprite.position.y / p.gameRef.blockSize).round() *
|
||||||
|
p.gameRef.blockSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,8 +140,6 @@ class CircuitBackground extends MovingObject {
|
|||||||
void setUp() {
|
void setUp() {
|
||||||
windowA.current = WindowState.first;
|
windowA.current = WindowState.first;
|
||||||
windowB.current = WindowState.first;
|
windowB.current = WindowState.first;
|
||||||
// gameRef.add(windowA);
|
|
||||||
// gameRef.add(windowB);
|
|
||||||
background1Position = Vector2(0, 0);
|
background1Position = Vector2(0, 0);
|
||||||
background1Size = Vector2(
|
background1Size = Vector2(
|
||||||
gameRef.viewport.canvasSize.y * (background.width / background.height),
|
gameRef.viewport.canvasSize.y * (background.width / background.height),
|
||||||
@ -219,4 +217,19 @@ class CircuitBackground extends MovingObject {
|
|||||||
windowB.render(canvas);
|
windowB.render(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
background1Size =
|
||||||
|
Vector2(newSize.y * (background.width / background.height), newSize.y);
|
||||||
|
windowA.position = background1Position;
|
||||||
|
windowA.size = background1Size;
|
||||||
|
|
||||||
|
background2Position =
|
||||||
|
Vector2(background1Position.x + background1Size.x - 1, 0);
|
||||||
|
background2Size =
|
||||||
|
Vector2(newSize.y * (background.width / background.height), newSize.y);
|
||||||
|
windowB.position = background2Position;
|
||||||
|
windowB.size = background2Size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,26 +70,6 @@ class CoinHolder {
|
|||||||
gameRef.add(coin.sprite);
|
gameRef.add(coin.sprite);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// double xCoordinate = gameRef.platformHolder.getFlushX();
|
|
||||||
// xCoordinate = xCoordinate +
|
|
||||||
// gameRef.blockSize * random.nextInt(5) +
|
|
||||||
// gameRef.blockSize * 20;
|
|
||||||
//
|
|
||||||
// if (xCoordinate < gameRef.size.x || random.nextInt(100) > 25) {
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// Coin coin = Coin(gameRef);
|
|
||||||
// coin.setPosition(xCoordinate, gameRef.blockSize * level);
|
|
||||||
//
|
|
||||||
// if (gameRef.isTooNearOtherObstacles(coin.sprite.toRect())) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// coins[level].add(coin);
|
|
||||||
// gameRef.add(coin.sprite);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalCoins() {
|
int totalCoins() {
|
||||||
@ -125,4 +105,12 @@ class CoinHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
for (List<Coin> coinLevel in coins) {
|
||||||
|
for (Coin p in coinLevel) {
|
||||||
|
p.resize(newSize, xRatio, yRatio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,4 +97,16 @@ class Firework extends Component {
|
|||||||
sprite1.animation!.reset();
|
sprite1.animation!.reset();
|
||||||
sprite2.animation!.reset();
|
sprite2.animation!.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
sprite1.x *= xRatio;
|
||||||
|
sprite1.y *= yRatio;
|
||||||
|
sprite1.width *= xRatio;
|
||||||
|
sprite1.height *= yRatio;
|
||||||
|
|
||||||
|
sprite2.x *= xRatio;
|
||||||
|
sprite2.y *= yRatio;
|
||||||
|
sprite2.width *= xRatio;
|
||||||
|
sprite2.height *= yRatio;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,20 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onResize(Vector2 canvasSize) {
|
void onResize(Vector2 canvasSize) {
|
||||||
|
Vector2 oldSize = viewport.canvasSize;
|
||||||
super.onResize(canvasSize);
|
super.onResize(canvasSize);
|
||||||
blockSize = canvasSize.y / 9;
|
blockSize = canvasSize.y / 9;
|
||||||
|
if (loaded) {
|
||||||
|
double xRatio = canvasSize.x / oldSize.x;
|
||||||
|
double yRatio = canvasSize.y / oldSize.y;
|
||||||
|
circuitBackground.resize(canvasSize, xRatio, yRatio);
|
||||||
|
runner.resize(canvasSize, xRatio, yRatio);
|
||||||
|
platformHolder.resize(canvasSize, xRatio, yRatio);
|
||||||
|
coinHolder.resize(canvasSize, xRatio, yRatio);
|
||||||
|
wireHolder.resize(canvasSize, xRatio, yRatio);
|
||||||
|
bugHolder.resize(canvasSize, xRatio, yRatio);
|
||||||
|
fireworks.resize(canvasSize, xRatio, yRatio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mobile controls
|
// Mobile controls
|
||||||
|
@ -47,4 +47,11 @@ class MovingObject {
|
|||||||
}
|
}
|
||||||
return "none";
|
return "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
sprite.x *= xRatio;
|
||||||
|
sprite.y *= yRatio;
|
||||||
|
sprite.width *= xRatio;
|
||||||
|
sprite.height *= yRatio;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,4 +196,14 @@ class PlatformHolder {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
for (List<Platform> platformLevel in platforms) {
|
||||||
|
for (Platform p in platformLevel) {
|
||||||
|
p.resize(newSize, xRatio, yRatio);
|
||||||
|
p.sprite.y = (p.sprite.position.y / p.gameRef.blockSize).round() *
|
||||||
|
p.gameRef.blockSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
String previousState = "run";
|
String previousState = "run";
|
||||||
var runnerPosition = Vector2(0, 0);
|
var runnerPosition = Vector2(0, 0);
|
||||||
late Vector2 runnerSize;
|
late Vector2 runnerSize;
|
||||||
|
// late Rect runnerRect;
|
||||||
bool dead = false;
|
bool dead = false;
|
||||||
|
|
||||||
void setUp() {
|
void setUp() {
|
||||||
@ -104,7 +105,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
path: [
|
path: [
|
||||||
Vector2(sprite.x, (level - 2) * gameRef.blockSize),
|
Vector2(sprite.x, (level - 2) * gameRef.blockSize),
|
||||||
],
|
],
|
||||||
speed: 150,
|
duration: 0.5,
|
||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
@ -315,22 +316,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Rect runnerRect = sprite.toRect();
|
Rect runnerRect = sprite.toRect();
|
||||||
bool onTopOfPlatform = false;
|
bool onTopOfPlatform = this.onTopOfPlatform();
|
||||||
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,
|
|
||||||
runnerRect.right, runnerRect.bottom + 1);
|
|
||||||
if (p.intersect(belowRunner) != "none") {
|
|
||||||
onTopOfPlatform = true;
|
|
||||||
}
|
|
||||||
} else if (side == "bottom") {
|
|
||||||
// event("die");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (List<Coin> coinLevel in gameRef.coinHolder.coins) {
|
for (List<Coin> coinLevel in gameRef.coinHolder.coins) {
|
||||||
for (int i = 0; i < coinLevel.length;) {
|
for (int i = 0; i < coinLevel.length;) {
|
||||||
@ -493,4 +479,14 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
|
|
||||||
changePriorityWithoutResorting(RUNNER_PRIORITY);
|
changePriorityWithoutResorting(RUNNER_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,4 +118,12 @@ class WireHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
|
for (List<Wire> platformLevel in wires) {
|
||||||
|
for (Wire p in platformLevel) {
|
||||||
|
p.resize(newSize, xRatio, yRatio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user