zeroed-some/sprong / b9e8ba5

Browse files

switch to translation for bop

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b9e8ba5383959ab8da8c058d0e166c1e6a5193b2
Parents
09335cd
Tree
2685a80

4 changed files

StatusFile+-
M index.html 1 1
M js/ai.js 10 10
M js/game-systems.js 28 34
M js/sprong.js 6 4
index.htmlmodified
@@ -3,7 +3,7 @@
33
 <head>
44
     <meta charset="UTF-8">
55
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
-    <title>Sprong :: Physics-based Pong</title>
6
+    <title>Sprong :: Pong with Physick</title>
77
     <link rel="stylesheet" href="sprong.css">
88
 </head>
99
 <body>
js/ai.jsmodified
@@ -20,11 +20,11 @@ const AI_TRACKING_AGGRESSION = 0.15; // How aggressively AI tracks the ball
2020
 // ============= AI SETTINGS =============
2121
 const AI_SETTINGS = {
2222
     easy: {
23
-        reactionTime: 400,
23
+        reactionTime: 350,
2424
         accuracy: 0.7,
2525
         speed: 0.8,
2626
         prediction: 0.3,
27
-        aggression: 0.2,
27
+        aggression: 0.4,
2828
         oscillation: 0.3,
2929
         bopChance: 0.25,
3030
         windupSpeed: 0.1,
@@ -36,11 +36,11 @@ const AI_SETTINGS = {
3636
         trackingAggression: 0.1
3737
     },
3838
     medium: {
39
-        reactionTime: 250,
39
+        reactionTime: 200,
4040
         accuracy: 0.85,
4141
         speed: 1.0,
4242
         prediction: 0.6,
43
-        aggression: 0.5,
43
+        aggression: 0.7,
4444
         oscillation: 0.7,
4545
         bopChance: 0.55,
4646
         windupSpeed: 0.15,
@@ -52,18 +52,18 @@ const AI_SETTINGS = {
5252
         trackingAggression: 0.15
5353
     },
5454
     hard: {
55
-        reactionTime: 150,
55
+        reactionTime: 100,
5656
         accuracy: 0.95,
57
-        speed: 1.3,  // Increased from 1.2
58
-        prediction: 0.85, // Increased from 0.8
59
-        aggression: 0.9,  // Increased from 0.8
57
+        speed: 1.5,
58
+        prediction: 0.85,
59
+        aggression: 1.0,
6060
         oscillation: 1.0,
6161
         bopChance: 0.85,
6262
         windupSpeed: 0.2,
63
-        windupRadius: 60,  // Increased from 50
63
+        windupRadius: 60,
6464
         comboBopChance: 0.5,
6565
         circularMotion: 0.8,
66
-        phaseSpeed: 0.12,  // Increased from 0.1
66
+        phaseSpeed: 0.12,
6767
         idleMovement: 0.8,
6868
         trackingAggression: 0.25
6969
     }
js/game-systems.jsmodified
@@ -41,12 +41,12 @@ const IMPACT_PARTICLES = 8;
4141
 const SPRING_PARTICLE_RATE  = 0.3;
4242
 
4343
 // Bop system constants
44
-const BOP_FORCE             = 0.5;  // self explanatory.      BOP   it.
44
+const BOP_FORCE             = 0.2;  // self explanatory.      BOP   it.
4545
 const BOP_RANGE             = 40;   // also self explanatory. TWIST it.
46
-const BOP_DURATION          = 900;  // traversal duration.    SHAKE it.
46
+const BOP_DURATION          = 1500; // traversal duration.    SHAKE it.
4747
 const BOP_COOLDOWN          = 500;  // also also self expl.   PULL  it.
4848
 const ANCHOR_RECOIL         = 40;   // How far the anchor moves backward during bop
49
-const BOP_VELOCITY_BOOST    = 6;    // Initial velocity boost for paddle
49
+const BOP_VELOCITY_BOOST    = 5;    // Initial velocity boost for paddle
5050
 
5151
 // ============= BOP SYSTEM =============
5252
 let bopState = {
@@ -103,42 +103,38 @@ function activateBop(side, currentTime, paddle, support, engine, particles) {
103103
     // Calculate direction from support to paddle
104104
     let dx = paddle.position.x - support.position.x;
105105
     let dy = paddle.position.y - support.position.y;
106
-    
106
+
107107
     // Normalize direction
108108
     let magnitude = Math.sqrt(dx * dx + dy * dy);
109109
     if (magnitude > 0) {
110110
         dx /= magnitude;
111111
         dy /= magnitude;
112
+        // Calculate anchor recoil distance
113
+        let anchorRecoilDistance = ANCHOR_RECOIL * 0.3;
114
+
115
+        // Move support and paddle in one solver step (no teleport → no ghost collisions)
116
+        Body.translate(support, { x: -dx * anchorRecoilDistance, y: -dy * anchorRecoilDistance });
117
+        Body.translate(paddle,  { x: -dx * anchorRecoilDistance, y: -dy * anchorRecoilDistance });
118
+
119
+        // Remember where the support started so we can ease it back later
120
+        const preSupportPos = { x: support.position.x + dx * anchorRecoilDistance,
121
+                                y: support.position.y + dy * anchorRecoilDistance };
122
+        bopState[side].originalPos = preSupportPos;
112123
         
113
-        // Calculate anchor recoil distance (reduced for gentler motion)
114
-        let anchorRecoilDistance = ANCHOR_RECOIL * 0.3; // Reduced from 0.4
115
-        
116
-        // Move the support BACKWARD (recoil effect)
117
-        let newSupportX = support.position.x - dx * anchorRecoilDistance;
118
-        let newSupportY = support.position.y - dy * anchorRecoilDistance;
119
-        
120
-        Body.setPosition(support, { x: newSupportX, y: newSupportY });
121
-        
122
-        // Store original support position for recovery
123
-        bopState[side].originalPos = { 
124
-            x: support.position.x + dx * anchorRecoilDistance, 
125
-            y: support.position.y + dy * anchorRecoilDistance 
126
-        };
127
-        
128
-        // Set paddle velocity directly for immediate forward thrust (gentler)
129
-        let forwardSpeed = BOP_VELOCITY_BOOST * 0.8; // Reduced intensity
124
+        // Now apply forward thrust from this new position
125
+        let forwardSpeed = BOP_VELOCITY_BOOST * 1.0; // Restored to full power
130126
         Body.setVelocity(paddle, {
131127
             x: paddle.velocity.x + dx * forwardSpeed,
132128
             y: paddle.velocity.y + dy * forwardSpeed
133129
         });
134
-        
135
-        // Apply a forward force for continued acceleration (gentler)
130
+
131
+        // Apply a forward force for continued acceleration
136132
         Body.applyForce(paddle, paddle.position, {
137
-            x: dx * bopState[side].power * BOP_RANGE * 0.05, // Reduced from 0.1
138
-            y: dy * bopState[side].power * BOP_RANGE * 0.05
133
+            x: dx * bopState[side].power * BOP_RANGE * 0.08,
134
+            y: dy * bopState[side].power * BOP_RANGE * 0.08
139135
         });
140
-        
141
-        // Create particle burst for visual feedback
136
+
137
+        // Create particle burst for visual feedback at the support position
142138
         for (let i = 0; i < 5; i++) {
143139
             let angle = Math.atan2(dy, dx) + (Math.random() - 0.5) * 0.5;
144140
             let speed = Math.random() * 4 + 2;
@@ -176,6 +172,7 @@ function updateBopStates(currentTime, leftSupport, rightSupport, leftPaddle, rig
176172
                 let currentX = support.position.x;
177173
                 let currentY = support.position.y;
178174
                 
175
+                // Smooth return motion with easing
179176
                 let returnSpeed = 0.15 * (1 - Math.pow(1 - progress, 3));
180177
                 let newX = currentX + (bopState.left.originalPos.x - currentX) * returnSpeed;
181178
                 let newY = currentY + (bopState.left.originalPos.y - currentY) * returnSpeed;
@@ -187,7 +184,7 @@ function updateBopStates(currentTime, leftSupport, rightSupport, leftPaddle, rig
187184
         }
188185
     }
189186
     
190
-    // Update right bop
187
+    // Update right bop (same logic)
191188
     if (bopState.right.active) {
192189
         let elapsed = currentTime - bopState.right.startTime;
193190
         let progress = elapsed / bopState.right.duration;
@@ -392,12 +389,9 @@ function setupCollisionHandlers(engine, ball, leftPaddle, rightPaddle, particles
392389
                     if (contactPoint) {
393390
                         isValidCollision = true;
394391
                     } else {
395
-                        // Fallback distance check
396
-                        let dx = ball.position.x - paddle.position.x;
397
-                        let dy = ball.position.y - paddle.position.y;
398
-                        let distance = Math.sqrt(dx * dx + dy * dy);
399
-                        let collisionThreshold = BALL_RADIUS + Math.max(PADDLE_WIDTH, PADDLE_HEIGHT)/2 + 10;
400
-                        isValidCollision = distance < collisionThreshold;
392
+                        // Use penetration depth as fallback to avoid false positives
393
+                        const depth = collision.depth || 0;
394
+                        isValidCollision = depth > 0.5;
401395
                     }
402396
                     
403397
                     if (isValidCollision) {
js/sprong.jsmodified
@@ -48,6 +48,7 @@ let mouseInput = {
4848
 // Make necessary variables globally accessible for other scripts
4949
 window.inputBuffer = inputBuffer;
5050
 window.moveSupportEnhanced = moveSupportEnhanced;
51
+window.ball = null;
5152
 
5253
 function setup() {
5354
     let canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);
@@ -77,6 +78,7 @@ function setup() {
7778
     
7879
     // Create ball
7980
     ball = resetBall(null, world, width, height);
81
+    window.ball = ball;
8082
     
8183
     // Add everything to the world
8284
     World.add(world, [
@@ -101,10 +103,7 @@ function draw() {
101103
         updateParticles();
102104
         checkBallPosition();
103105
         
104
-        // Enhanced collision detection during bops
105
-        if (bopState.left.active || bopState.right.active) {
106
-            Engine.update(engine, 8);
107
-        }
106
+        
108107
         
109108
         // Draw everything
110109
         drawParticles();
@@ -197,6 +196,7 @@ function checkBallPosition() {
197196
         rightScore++;
198197
         updateScore();
199198
         ball = resetBall(ball, world, width, height);
199
+        window.ball = ball;  // ADD THIS LINE - Update global reference
200200
         gameStarted = false;
201201
     }
202202
     
@@ -204,6 +204,7 @@ function checkBallPosition() {
204204
         leftScore++;
205205
         updateScore();
206206
         ball = resetBall(ball, world, width, height);
207
+        window.ball = ball;  // ADD THIS LINE - Update global reference
207208
         gameStarted = false;
208209
     }
209210
 }
@@ -249,6 +250,7 @@ function keyPressed() {
249250
         rightScore = 0;
250251
         updateScore();
251252
         ball = resetBall(ball, world, width, height);
253
+        window.ball = ball;
252254
         gameStarted = false;
253255
         
254256
         inputBuffer.left = 0;