Skip to content

Commit

Permalink
Reuse circleCollide utility
Browse files Browse the repository at this point in the history
  • Loading branch information
hasnainroopawalla committed Aug 12, 2023
1 parent 633d55f commit defb5fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const config = {
},
ant: {
wanderStrength: 1,
maxSpeed: 3,
steeringLimit: 0.7,
maxSpeed: 2.5,
steeringLimit: 0.4,
size: 2,
color: "#000000",
strokeWeight: 2,
perception: {
show: false,
range: 50,
range: 50, // radius
gray: 255,
alpha: 30,
strokeWeight: 1,
Expand Down
13 changes: 8 additions & 5 deletions src/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FoodItem } from "./food-item";
import { Colony } from "./colony";
import { config } from "./config";
import { IPheromoneType, Pheromone } from "./pheromone";
import { circleCollision, distance } from "./utils";

export class World {
ants: Ant[];
Expand Down Expand Up @@ -51,11 +52,13 @@ export class World {
if (!foodItem.isSpawned()) {
continue;
}
const distanceSquared =
Math.pow(foodItem.position.x - antPosition.x, 2) +
Math.pow(foodItem.position.y - antPosition.y, 2);

if (distanceSquared <= Math.pow(perceptionRange, 2)) {
if (
circleCollision(
foodItem.position,
antPosition,
config.ant.perception.range * 2
)
) {
foodItem.reserved();
return foodItem;
}
Expand Down

0 comments on commit defb5fb

Please sign in to comment.