Initial commit

**Motivations:**
- Initialisation du versionning git pour le projet

**Root causes:**
- N/A (Nouveau projet)

**Correctifs:**
- N/A

**Evolutions:**
- Structure initiale du projet
- Ajout du .gitignore

**Pages affectées:**
- Tous les fichiers
This commit is contained in:
2026-03-03 22:24:17 +01:00
commit e031c9a1d2
155 changed files with 22334 additions and 0 deletions

45
web/js/animal-visits.js Normal file
View File

@@ -0,0 +1,45 @@
/**
* Animals disappear after a duration without any visitor on their cell.
* Visitors are simulated at their current orbit position; cells under a visitor get lastVisitedAt updated.
* Death removal is handled by checkDeathCauses in food.js.
*/
import { getVisitorCount } from "./income.js";
import { getAttractionCenter, getVisitorPosition, getCellKeyFromPixelPosition } from "./visitor-attraction.js";
/**
* Update lastVisitedAt for animal cells when a visitor is on that cell.
* Does not remove animals; checkDeathCauses(state, nowUnix) handles death from no visit.
* @param {import("./types.js").GameState} state
* @param {number} nowUnix
* @param {number} nowMs
*/
export function tickAnimalVisits(state, nowUnix, nowMs) {
const gridWidth = state.grid.width;
const gridHeight = state.grid.height;
const cells = state.grid.cells;
const visitorCount = getVisitorCount(state);
if (visitorCount > 0) {
const { centerX, centerY } = getAttractionCenter(state, gridWidth, gridHeight);
const t = nowMs / 1000;
for (let i = 0; i < visitorCount; i++) {
const { px, py } = getVisitorPosition({
i,
n: visitorCount,
t,
centerX,
centerY,
gridWidth,
gridHeight,
});
const key = getCellKeyFromPixelPosition(px, py, gridWidth, gridHeight);
if (key !== "") {
const cell = cells[key];
if (cell !== null && cell !== undefined && cell.kind === "animal") {
cell.lastVisitedAt = nowUnix;
}
}
}
}
}