Add petting option in menu

This commit is contained in:
Idrees Hassan
2024-12-26 10:55:48 -05:00
parent 953392f702
commit a78ec9209d

64
birb.js
View File

@@ -151,11 +151,12 @@ const styles = `
.birb-window-separator { .birb-window-separator {
width: 100%; width: 100%;
height: 1px; height: 1.5px;
background-color: #000000; background-color: #000000;
box-sizing: border-box; box-sizing: border-box;
margin-top: 6px; margin-top: 6px;
margin-bottom: 6px; margin-bottom: 6px;
opacity: 0.45;
} }
`; `;
@@ -572,35 +573,42 @@ if (window === window.top) {
document.body.appendChild(canvas); document.body.appendChild(canvas);
} }
function makeElement(className, textContent, id) {
const element = document.createElement("div");
element.classList.add(className);
if (textContent) {
element.textContent = textContent;
}
if (id) {
element.id = id;
}
return element;
}
function insertStartMenu() { function insertStartMenu() {
if (document.querySelector(".birb-window")) { if (document.querySelector(".birb-window")) {
return; return;
} }
let html = ` let startMenu = makeElement("birb-window");
<div class="birb-window"> let header = makeElement("birb-window-header");
<div class="birb-window-header"> header.innerHTML = '<div class="birb-window-title">birbOS</div>';
<div class="birb-window-title">birbOS</div> let content = makeElement("birb-window-content");
</div> let petButton = makeElement("birb-window-list-item", "Pet Birb");
<div class="birb-window-content"> petButton.addEventListener("click", () => {
<div class="birb-window-list-item">Pet Birb</div> removeStartMenu();
<div class="birb-window-list-item">Field Guide</div> pet();
<div class="birb-window-list-item">Decorations</div> });
<div class="birb-window-list-item">Programs</div> content.appendChild(petButton);
<div class="birb-window-separator"></div> content.appendChild(makeElement("birb-window-list-item", "Field Guide"));
<div class="birb-window-list-item">Settings</div> content.appendChild(makeElement("birb-window-list-item", "Decorations"));
</div> content.appendChild(makeElement("birb-window-list-item", "Programs"));
</div> content.appendChild(makeElement("birb-window-separator"));
`; content.appendChild(makeElement("birb-window-list-item", "Settings"));
// Insert the start menu into the body startMenu.appendChild(header);
document.body.insertAdjacentHTML("beforeend", html); startMenu.appendChild(content);
// Make the start menu draggable document.body.appendChild(startMenu);
makeDraggable(document.querySelector(".birb-window-header")); makeDraggable(document.querySelector(".birb-window-header"));
// Position the start menu
const startMenu = document.querySelector(".birb-window");
if (!(startMenu instanceof HTMLElement)) {
return;
}
let x = birdX; let x = birdX;
let y = window.innerHeight - birdY; let y = window.innerHeight - birdY;
const offset = 20; const offset = 20;
@@ -699,7 +707,7 @@ let petStack = [];
function update() { function update() {
ticks++; ticks++;
if (currentState === States.IDLE) { if (currentState === States.IDLE) {
if (Math.random() < 1 / (60 * 3) && !isStartMenuOpen()) { if (Math.random() < 1 / (60 * 3) && currentAnimation !== Animations.HEART && !isStartMenuOpen()) {
hop(); hop();
} }
} else if (currentState === States.HOP) { } else if (currentState === States.HOP) {
@@ -928,6 +936,12 @@ function hop() {
} }
} }
function pet() {
if (currentState === States.IDLE) {
setAnimation(Animations.HEART);
}
}
/** /**
* @param {number} x * @param {number} x
* @param {number} y * @param {number} y