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 @@
3
 <head>
3
 <head>
4
     <meta charset="UTF-8">
4
     <meta charset="UTF-8">
5
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
     <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>
7
     <link rel="stylesheet" href="sprong.css">
7
     <link rel="stylesheet" href="sprong.css">
8
 </head>
8
 </head>
9
 <body>
9
 <body>
js/ai.jsmodified
@@ -20,11 +20,11 @@ const AI_TRACKING_AGGRESSION = 0.15; // How aggressively AI tracks the ball
20
 // ============= AI SETTINGS =============
20
 // ============= AI SETTINGS =============
21
 const AI_SETTINGS = {
21
 const AI_SETTINGS = {
22
     easy: {
22
     easy: {
23
-        reactionTime: 400,
23
+        reactionTime: 350,
24
         accuracy: 0.7,
24
         accuracy: 0.7,
25
         speed: 0.8,
25
         speed: 0.8,
26
         prediction: 0.3,
26
         prediction: 0.3,
27
-        aggression: 0.2,
27
+        aggression: 0.4,
28
         oscillation: 0.3,
28
         oscillation: 0.3,
29
         bopChance: 0.25,
29
         bopChance: 0.25,
30
         windupSpeed: 0.1,
30
         windupSpeed: 0.1,
@@ -36,11 +36,11 @@ const AI_SETTINGS = {
36
         trackingAggression: 0.1
36
         trackingAggression: 0.1
37
     },
37
     },
38
     medium: {
38
     medium: {
39
-        reactionTime: 250,
39
+        reactionTime: 200,
40
         accuracy: 0.85,
40
         accuracy: 0.85,
41
         speed: 1.0,
41
         speed: 1.0,
42
         prediction: 0.6,
42
         prediction: 0.6,
43
-        aggression: 0.5,
43
+        aggression: 0.7,
44
         oscillation: 0.7,
44
         oscillation: 0.7,
45
         bopChance: 0.55,
45
         bopChance: 0.55,
46
         windupSpeed: 0.15,
46
         windupSpeed: 0.15,
@@ -52,18 +52,18 @@ const AI_SETTINGS = {
52
         trackingAggression: 0.15
52
         trackingAggression: 0.15
53
     },
53
     },
54
     hard: {
54
     hard: {
55
-        reactionTime: 150,
55
+        reactionTime: 100,
56
         accuracy: 0.95,
56
         accuracy: 0.95,
57
-        speed: 1.3,  // Increased from 1.2
57
+        speed: 1.5,
58
-        prediction: 0.85, // Increased from 0.8
58
+        prediction: 0.85,
59
-        aggression: 0.9,  // Increased from 0.8
59
+        aggression: 1.0,
60
         oscillation: 1.0,
60
         oscillation: 1.0,
61
         bopChance: 0.85,
61
         bopChance: 0.85,
62
         windupSpeed: 0.2,
62
         windupSpeed: 0.2,
63
-        windupRadius: 60,  // Increased from 50
63
+        windupRadius: 60,
64
         comboBopChance: 0.5,
64
         comboBopChance: 0.5,
65
         circularMotion: 0.8,
65
         circularMotion: 0.8,
66
-        phaseSpeed: 0.12,  // Increased from 0.1
66
+        phaseSpeed: 0.12,
67
         idleMovement: 0.8,
67
         idleMovement: 0.8,
68
         trackingAggression: 0.25
68
         trackingAggression: 0.25
69
     }
69
     }
js/game-systems.jsmodified
@@ -41,12 +41,12 @@ const IMPACT_PARTICLES = 8;
41
 const SPRING_PARTICLE_RATE  = 0.3;
41
 const SPRING_PARTICLE_RATE  = 0.3;
42
 
42
 
43
 // Bop system constants
43
 // Bop system constants
44
-const BOP_FORCE             = 0.5;  // self explanatory.      BOP   it.
44
+const BOP_FORCE             = 0.2;  // self explanatory.      BOP   it.
45
 const BOP_RANGE             = 40;   // also self explanatory. TWIST it.
45
 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.
47
 const BOP_COOLDOWN          = 500;  // also also self expl.   PULL  it.
47
 const BOP_COOLDOWN          = 500;  // also also self expl.   PULL  it.
48
 const ANCHOR_RECOIL         = 40;   // How far the anchor moves backward during bop
48
 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
50
 
50
 
51
 // ============= BOP SYSTEM =============
51
 // ============= BOP SYSTEM =============
52
 let bopState = {
52
 let bopState = {
@@ -103,42 +103,38 @@ function activateBop(side, currentTime, paddle, support, engine, particles) {
103
     // Calculate direction from support to paddle
103
     // Calculate direction from support to paddle
104
     let dx = paddle.position.x - support.position.x;
104
     let dx = paddle.position.x - support.position.x;
105
     let dy = paddle.position.y - support.position.y;
105
     let dy = paddle.position.y - support.position.y;
106
-    
106
+
107
     // Normalize direction
107
     // Normalize direction
108
     let magnitude = Math.sqrt(dx * dx + dy * dy);
108
     let magnitude = Math.sqrt(dx * dx + dy * dy);
109
     if (magnitude > 0) {
109
     if (magnitude > 0) {
110
         dx /= magnitude;
110
         dx /= magnitude;
111
         dy /= magnitude;
111
         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;
112
         
123
         
113
-        // Calculate anchor recoil distance (reduced for gentler motion)
124
+        // Now apply forward thrust from this new position
114
-        let anchorRecoilDistance = ANCHOR_RECOIL * 0.3; // Reduced from 0.4
125
+        let forwardSpeed = BOP_VELOCITY_BOOST * 1.0; // Restored to full power
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
130
         Body.setVelocity(paddle, {
126
         Body.setVelocity(paddle, {
131
             x: paddle.velocity.x + dx * forwardSpeed,
127
             x: paddle.velocity.x + dx * forwardSpeed,
132
             y: paddle.velocity.y + dy * forwardSpeed
128
             y: paddle.velocity.y + dy * forwardSpeed
133
         });
129
         });
134
-        
130
+
135
-        // Apply a forward force for continued acceleration (gentler)
131
+        // Apply a forward force for continued acceleration
136
         Body.applyForce(paddle, paddle.position, {
132
         Body.applyForce(paddle, paddle.position, {
137
-            x: dx * bopState[side].power * BOP_RANGE * 0.05, // Reduced from 0.1
133
+            x: dx * bopState[side].power * BOP_RANGE * 0.08,
138
-            y: dy * bopState[side].power * BOP_RANGE * 0.05
134
+            y: dy * bopState[side].power * BOP_RANGE * 0.08
139
         });
135
         });
140
-        
136
+
141
-        // Create particle burst for visual feedback
137
+        // Create particle burst for visual feedback at the support position
142
         for (let i = 0; i < 5; i++) {
138
         for (let i = 0; i < 5; i++) {
143
             let angle = Math.atan2(dy, dx) + (Math.random() - 0.5) * 0.5;
139
             let angle = Math.atan2(dy, dx) + (Math.random() - 0.5) * 0.5;
144
             let speed = Math.random() * 4 + 2;
140
             let speed = Math.random() * 4 + 2;
@@ -176,6 +172,7 @@ function updateBopStates(currentTime, leftSupport, rightSupport, leftPaddle, rig
176
                 let currentX = support.position.x;
172
                 let currentX = support.position.x;
177
                 let currentY = support.position.y;
173
                 let currentY = support.position.y;
178
                 
174
                 
175
+                // Smooth return motion with easing
179
                 let returnSpeed = 0.15 * (1 - Math.pow(1 - progress, 3));
176
                 let returnSpeed = 0.15 * (1 - Math.pow(1 - progress, 3));
180
                 let newX = currentX + (bopState.left.originalPos.x - currentX) * returnSpeed;
177
                 let newX = currentX + (bopState.left.originalPos.x - currentX) * returnSpeed;
181
                 let newY = currentY + (bopState.left.originalPos.y - currentY) * returnSpeed;
178
                 let newY = currentY + (bopState.left.originalPos.y - currentY) * returnSpeed;
@@ -187,7 +184,7 @@ function updateBopStates(currentTime, leftSupport, rightSupport, leftPaddle, rig
187
         }
184
         }
188
     }
185
     }
189
     
186
     
190
-    // Update right bop
187
+    // Update right bop (same logic)
191
     if (bopState.right.active) {
188
     if (bopState.right.active) {
192
         let elapsed = currentTime - bopState.right.startTime;
189
         let elapsed = currentTime - bopState.right.startTime;
193
         let progress = elapsed / bopState.right.duration;
190
         let progress = elapsed / bopState.right.duration;
@@ -392,12 +389,9 @@ function setupCollisionHandlers(engine, ball, leftPaddle, rightPaddle, particles
392
                     if (contactPoint) {
389
                     if (contactPoint) {
393
                         isValidCollision = true;
390
                         isValidCollision = true;
394
                     } else {
391
                     } else {
395
-                        // Fallback distance check
392
+                        // Use penetration depth as fallback to avoid false positives
396
-                        let dx = ball.position.x - paddle.position.x;
393
+                        const depth = collision.depth || 0;
397
-                        let dy = ball.position.y - paddle.position.y;
394
+                        isValidCollision = depth > 0.5;
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;
401
                     }
395
                     }
402
                     
396
                     
403
                     if (isValidCollision) {
397
                     if (isValidCollision) {
js/sprong.jsmodified
@@ -48,6 +48,7 @@ let mouseInput = {
48
 // Make necessary variables globally accessible for other scripts
48
 // Make necessary variables globally accessible for other scripts
49
 window.inputBuffer = inputBuffer;
49
 window.inputBuffer = inputBuffer;
50
 window.moveSupportEnhanced = moveSupportEnhanced;
50
 window.moveSupportEnhanced = moveSupportEnhanced;
51
+window.ball = null;
51
 
52
 
52
 function setup() {
53
 function setup() {
53
     let canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);
54
     let canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);
@@ -77,6 +78,7 @@ function setup() {
77
     
78
     
78
     // Create ball
79
     // Create ball
79
     ball = resetBall(null, world, width, height);
80
     ball = resetBall(null, world, width, height);
81
+    window.ball = ball;
80
     
82
     
81
     // Add everything to the world
83
     // Add everything to the world
82
     World.add(world, [
84
     World.add(world, [
@@ -101,10 +103,7 @@ function draw() {
101
         updateParticles();
103
         updateParticles();
102
         checkBallPosition();
104
         checkBallPosition();
103
         
105
         
104
-        // Enhanced collision detection during bops
106
+        
105
-        if (bopState.left.active || bopState.right.active) {
106
-            Engine.update(engine, 8);
107
-        }
108
         
107
         
109
         // Draw everything
108
         // Draw everything
110
         drawParticles();
109
         drawParticles();
@@ -197,6 +196,7 @@ function checkBallPosition() {
197
         rightScore++;
196
         rightScore++;
198
         updateScore();
197
         updateScore();
199
         ball = resetBall(ball, world, width, height);
198
         ball = resetBall(ball, world, width, height);
199
+        window.ball = ball;  // ADD THIS LINE - Update global reference
200
         gameStarted = false;
200
         gameStarted = false;
201
     }
201
     }
202
     
202
     
@@ -204,6 +204,7 @@ function checkBallPosition() {
204
         leftScore++;
204
         leftScore++;
205
         updateScore();
205
         updateScore();
206
         ball = resetBall(ball, world, width, height);
206
         ball = resetBall(ball, world, width, height);
207
+        window.ball = ball;  // ADD THIS LINE - Update global reference
207
         gameStarted = false;
208
         gameStarted = false;
208
     }
209
     }
209
 }
210
 }
@@ -249,6 +250,7 @@ function keyPressed() {
249
         rightScore = 0;
250
         rightScore = 0;
250
         updateScore();
251
         updateScore();
251
         ball = resetBall(ball, world, width, height);
252
         ball = resetBall(ball, world, width, height);
253
+        window.ball = ball;
252
         gameStarted = false;
254
         gameStarted = false;
253
         
255
         
254
         inputBuffer.left = 0;
256
         inputBuffer.left = 0;