Skip to content

Commit

Permalink
fix: player can eat its own food
Browse files Browse the repository at this point in the history
  • Loading branch information
yamcodes committed Feb 7, 2022
1 parent f21748f commit 92ce941
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"randomColor": true
},
"blob": {
"strokeSize": 9,
"strokeSize": 10,
"strokeOpacity": 0.1
},
"pellets": {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/Food.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Food {
) {
const foodVect = p5.createVector(food.x, food.y);
const trajectory = food.mouse;
if (!this.player.contains(food)) {
if (!this.player.eats(food)) {
food.speed = p5.lerp(0, food.speed, settings.food.deceleration);
}
trajectory.setMag(food.speed);
Expand Down
4 changes: 2 additions & 2 deletions src/assets/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export default class Player extends Blob {
}

reduceMass(m) {
const initialMass = p5.round(Player.getMassByRadius(settings.player.initialRadius));
const foodMass = Player.getMassByRadius(settings.food.radius);
const newMass = this.mass - m;
if (newMass > initialMass) {
if (newMass > foodMass) {
this.mass = newMass;
return true;
}
Expand Down

0 comments on commit 92ce941

Please sign in to comment.