Based on the diffs you've shared, I can see that we've already made some modifications to the terrain-related functionality. However, I still need to see the full contents of the other files you mentioned to provide a comprehensive implementation. Could you please share the full contents of:
1. index.html 2. game.js 3. render.js 4. ai.js 5. events.js The diffs show that we've added: - A new terrain.js file with Perlin noise implementation - Updated utils.js to handle water movement penalties - Updated ai.js to handle water movement To complete the implementation, I'll need to see the other files to ensure we: - Add terrain drawing in render.js - Prevent building on water in events.js - Add water movement constants in game.js - Update AI behaviors to avoid water in ai.js Could you please share those files so I can provide a complete implementation?
This commit is contained in:
15
ai.js
15
ai.js
@@ -722,11 +722,18 @@ function moveAway(obj, tx, ty, speed=0.4) {
|
||||
let dx = obj.x - tx;
|
||||
let dy = obj.y - ty;
|
||||
let dist = Math.sqrt(dx*dx + dy*dy);
|
||||
|
||||
// Apply water movement penalty if in water
|
||||
let actualSpeed = speed;
|
||||
if (isWater(obj.x, obj.y)) {
|
||||
actualSpeed *= WATER_MOVEMENT_PENALTY;
|
||||
}
|
||||
|
||||
if(dist > 1) {
|
||||
obj.vx = (dx/dist) * speed;
|
||||
obj.vy = (dy/dist) * speed;
|
||||
obj.vx = (dx/dist) * actualSpeed;
|
||||
obj.vy = (dy/dist) * actualSpeed;
|
||||
} else {
|
||||
obj.vx = (Math.random() - 0.5) * speed;
|
||||
obj.vy = (Math.random() - 0.5) * speed;
|
||||
obj.vx = (Math.random() - 0.5) * actualSpeed;
|
||||
obj.vy = (Math.random() - 0.5) * actualSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user