Просмотр исходного кода

fixed turbos, added turbo test table

rdefeo 1 год назад
Родитель
Сommit
a26111cfcf
4 измененных файлов с 79 добавлено и 11 удалено
  1. 60 0
      assets/tables/45_dbg Turbos.json
  2. 5 5
      objects.cxx
  3. 9 4
      objects.h
  4. 5 2
      table_parser.cxx

+ 60 - 0
assets/tables/45_dbg Turbos.json

@@ -0,0 +1,60 @@
+{
+    "lives": 3,
+    "balls": [
+        {
+            "position": [ 220, 200 ]
+        }
+    ],
+    "flippers": [
+        {
+            "position": [ 130, 1180 ],
+            "side": "LEFT",
+            "size": 120
+        },
+        {
+            "position": [ 490, 1180 ],
+            "side": "RIGHT",
+            "size": 120
+        }
+    ],
+    "rails": [
+        // left wall
+        {
+            "start": [ 0, 0 ],
+            "end": [ 0, 1080 ]
+        },
+        // bottom left
+        {
+            "start": [ 0, 1080 ],
+            "end": [ 130, 1160 ]
+        },
+        // bottom right
+        {
+            "start": [ 490, 1160 ],
+            "end": [ 630, 1080 ]
+        },
+        // right wall
+        {
+            "start": [ 630, 1080 ],
+            "end": [ 630, 0 ]
+        }
+    ],
+    "turbos": [
+        {
+            "position": [ 100, 400 ],
+            "angle": 0
+        },
+        {
+            "position": [ 300, 400 ],
+            "angle": 270
+        },
+        {
+            "position": [ 300, 600 ],
+            "angle": 180
+        },
+        {
+            "position": [ 100, 600 ],
+            "angle": 90
+        }
+    ]
+}

+ 5 - 5
objects.cxx

@@ -569,12 +569,12 @@ void Turbo::draw(Canvas* canvas) {
 }
 
 bool Turbo::collide(Ball& ball) {
-    Vec2 dir = ball.p - p;
-    float dist = dir.mag();
-    if(dist < 30) {
+    float dist = (ball.p - p).mag();
+    // our distance check doesn't include the ball radius as we want the ball
+    // to enter the turbo area a bit before being affected by the boost
+    if(dist < r + 10) {
         // apply the turbo in 'dir' with force of 'boost'
-        FURI_LOG_I(TAG, "TURBO! dir: %.3f,%.3f", (double)dir.x, (double)dir.y);
-        ball.accelerate(dir * (boost / 50.0f));
+        ball.prev_p = ball.p - (dir * (boost));
     }
     return false;
 }

+ 9 - 4
objects.h

@@ -8,6 +8,8 @@
 #define DEF_BUMPER_BOUNCE 1.0f
 #define DEF_FLIPPER_SIZE  120
 #define DEF_RAIL_BOUNCE   0.9f
+#define DEF_TURBO_RADIUS  20
+#define DEF_TURBO_BOOST   5
 
 #define ARC_TANGENT_RESTITUTION 1.0f
 #define ARC_NORMAL_RESTITUTION  0.8f
@@ -215,15 +217,16 @@ public:
 
 class Turbo : public FixedObject {
 public:
-    Turbo(const Vec2& p_, float angle_, float boost_)
+    Turbo(const Vec2& p_, float angle_, float boost_, float radius_)
         : FixedObject()
         , p(p_)
         , angle(angle_)
-        , boost(boost_) {
+        , boost(boost_)
+        , r(radius_) {
+        // Our boost direction
         dir = Vec2(cosf(angle), -sinf(angle));
 
-        // for now, fix the radius to 30 or whatever
-        size_t r = 30;
+        // define the points of the chevrons at the 0 angle
         chevron_1[0] = Vec2(p.x, p.y - r);
         chevron_1[1] = Vec2(p.x + r, p.y);
         chevron_1[2] = Vec2(p.x, p.y + r);
@@ -232,6 +235,7 @@ public:
         chevron_2[1] = Vec2(p.x, p.y);
         chevron_2[2] = Vec2(p.x - r, p.y + r);
 
+        // rotate the chevrons to the correct angle
         for(size_t i = 0; i < 3; i++) {
             Vec2& v = chevron_1[i];
             Vec2 d = v - p;
@@ -249,6 +253,7 @@ public:
     Vec2 p;
     float angle;
     float boost;
+    float r;
 
     Vec2 dir; // unit normal of turbo direction
 

+ 5 - 2
table_parser.cxx

@@ -559,10 +559,13 @@ Table* table_load_table_from_file(PinballApp* pb, size_t index) {
                 table_file_parse_float(turbo, "angle", angle);
                 angle *= pi_180;
 
-                float boost = 10;
+                float boost = DEF_TURBO_BOOST;
                 table_file_parse_float(turbo, "boost", boost);
 
-                Turbo* new_turbo = new Turbo(p, angle, boost);
+                float radius = DEF_TURBO_RADIUS;
+                table_file_parse_float(turbo, "radius", radius);
+
+                Turbo* new_turbo = new Turbo(p, angle, boost, radius);
 
                 table->objects.push_back(new_turbo);
             }