From 8d225bda06e77fe4413237acd67f5b6be8e1b2f2 Mon Sep 17 00:00:00 2001
From: marco <marco@cypherstack.com>
Date: Thu, 16 Sep 2021 19:03:11 -0600
Subject: [PATCH] Added more linear falling.

---
 lib/runner.dart | 67 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/lib/runner.dart b/lib/runner.dart
index a25cbf3..a9c1b25 100644
--- a/lib/runner.dart
+++ b/lib/runner.dart
@@ -4,6 +4,7 @@ import 'package:firo_runner/main.dart';
 import 'package:flame/effects.dart';
 import 'package:flame/extensions.dart';
 import 'package:flutter/material.dart';
+import 'dart:math';
 
 import 'package:flame/components.dart';
 
@@ -119,21 +120,7 @@ class Runner extends Component with HasGameRef<MyGame> {
         sprite.clearEffects();
         runnerState = event;
         sprite.current = RunnerState.fall;
-        sprite.addEffect(MoveEffect(
-          path: [
-            Vector2(sprite.x, (level + 1) * gameRef.blockSize),
-          ],
-          duration: 0.2,
-          curve: Curves.ease,
-          onComplete: () {
-            updateLevel();
-            if (onTopOfPlatform()) {
-              this.event("run");
-            } else {
-              this.event("fall");
-            }
-          },
-        ));
+        sprite.addEffect(getFallingEffect());
         break;
       case "kick":
         runnerState = event;
@@ -207,6 +194,56 @@ class Runner extends Component with HasGameRef<MyGame> {
     }
   }
 
+  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");
+        }
+      },
+    );
+  }
+
   void control(String input) {
     if (gameRef.gameState.isPaused) {
       return;