Skip to content

Commit

Permalink
favorite foods
Browse files Browse the repository at this point in the history
  • Loading branch information
cheryllium committed Jan 5, 2024
1 parent c51569f commit f4c1c38
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
4 changes: 3 additions & 1 deletion src/fish.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default class Fish {

// Personal information about this fish
this.name = randomFishName();
this.updateMood(Math.random() > 0.5);
this.updateMood(Math.random() > 0.5);

this.favoriteFood = Object.keys(foodImages)[randomIntFromInterval(0, Object.keys(foodImages).length-1)];
}

setRandomVelocity() {
Expand Down
57 changes: 28 additions & 29 deletions src/routines.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@ import { states as fishStates } from './fish.js';
import generateChatScripts from './chats.js';

export const SCRIPTS = {
heart: [
{ type: 'emote', value: 'heart', duration: 3000 },
],
happy: [
{ type: 'emote', value: 'happy', duration: 3000 }, // Set emote to happy, wait 3s
{ type: 'emote', value: null, duration: 1000 }, // Set emote to nothing, wait 1s
{ type: 'emote', value: 'heart', duration: 3000 }, // Set emote to heart, wait 3s
{ type: 'emote', value: 'happy', duration: 3000 },
],
moveToCorner: [
{ type: 'state', value: fishStates.MOVING, duration: 4000, moveto: {x: 500, y: 500} },
{ type: 'state', value: fishStates.IDLING, duration: 4000 }
grumpy: [
{ type: 'emote', value: 'grumpy', duration: 3000 },
],
chat1: [
[
{ type: 'state', value: fishStates.IDLING, duration: 1000 },
{ type: 'emote', value: 'happy', duration: 3000 },
{ type: 'emote', value: 'heart', duration: 4000 },
],
[
{ type: 'state', value: fishStates.IDLING, duration: 2000 },
{ type: 'emote', value: 'sleepy', duration: 3000 },
{ type: 'emote', value: 'heart', duration: 3000 },
],
],
};

export default class RoutineManager {
Expand Down Expand Up @@ -73,12 +61,17 @@ export default class RoutineManager {

if (collision) {
food.remove = true;
actionManager.fishRoutines.push(
{
fish, script: SCRIPTS.happy,
}
);
uiManager.addRecord(`FISH1 ate a delicious ${food.type}!`, fish);
if (food.type == fish.favoriteFood) {
uiManager.addRecord("It's FISH1's favorite food!", fish);
actionManager.fishRoutines.push({
fish, script: SCRIPTS.heart,
});
} else {
actionManager.fishRoutines.push({
fish, script: SCRIPTS.happy,
});
}
fish.updateMood(true, true);
}
});
Expand All @@ -89,16 +82,22 @@ export default class RoutineManager {
}

initialize () {
// Random happy fish
// Random fish emotes
this.addEvent('general-mood', 4000, 0.5, function () {
let filteredFish = fishInTank.filter(fish => !fish.action);
let fish = filteredFish[randomIntFromInterval(0, filteredFish.length - 1)];
actionManager.fishRoutines.push(
{
let fish = filteredFish[randomIntFromInterval(0, filteredFish.length - 1)];

if (fish.goodMood) {
actionManager.fishRoutines.push({
fish,
script: SCRIPTS.happy,
}
);
});
} else {
actionManager.fishRoutines.push({
fish,
script: SCRIPTS.grumpy,
});
}
});

// Random fish conversation
Expand Down
4 changes: 3 additions & 1 deletion src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export default class UIManager {

// Create paragraphs for the name and personality
let fishInfo = document.createElement("div");
fishInfo.innerHTML = `<b>Name: </b>${fish.name}<br><b>Mood: </b>${fish.mood}`;
fishInfo.innerHTML = `<b>Name: </b>${fish.name}`;
fishInfo.innerHTML += `<br><b>Mood: </b>${fish.mood}`;
fishInfo.innerHTML += `<br /><b>Favorite food: </b>${fish.favoriteFood}`;

fishDiv.appendChild(fishImage);
fishDiv.appendChild(fishInfo);
Expand Down

0 comments on commit f4c1c38

Please sign in to comment.