Kaynağa Gözat

Worked on conditional exits

tags/v0.1.0
Fen Dweller 6 yıl önce
ebeveyn
işleme
6e8fb9b8d0
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: E80B35A6F11C3656
3 değiştirilmiş dosya ile 61 ekleme ve 39 silme
  1. +0
    -15
      satiate.html
  2. +11
    -17
      satiate.js
  3. +50
    -7
      world.js

+ 0
- 15
satiate.html Dosyayı Görüntüle

@@ -36,27 +36,12 @@
</div>
<div id="control-area">
<div id="actions">
<button class="action-button" id="load">Load Sounds</button>
<button class="action-button" id="sfx">Play Sound</button>
<button class="action-button" id="loop">Play Loop</button>
<button class="action-button" id="stop">Stop Loop</button>
</div>
<div id="desc">
this is a description of your action
</div>
<div id="moves">
beep beep
<div id="move-holder">
<button class="move-button" id="move-up-left">Potato Factory</button>
<button class="move-button" id="move-up">Door</button>
<button class="move-button" id="move-up-right">Butts</button>
<button class="move-button" id="move-left">Fen's Snack Pile</button>
<button class="move-button" id="move-right">Vore</button>
<button class="move-button" id="move-down-left">Dennis</button>
<button class="move-button" id="move-down">Ectoplasm</button>
<button class="move-button" id="move-down-right">E</button>
<button class="move-button" id="move-ascend">Penthouse</button>
<button class="move-button" id="move-descend">Basement</button>
</div>
</div>
</div>


+ 11
- 17
satiate.js Dosyayı Görüntüle

@@ -2,28 +2,22 @@

let audioContext;

let state = {
player: {
items: {
keys: [
"Locked Room"
]
}
}
}

// setup the game

function init() {
initAudio();

document.querySelector("#load").addEventListener("click", () => {
loadAudio("sfx/test.ogg");
loadAudio("loop/test.ogg");
});

document.querySelector("#sfx").addEventListener("click", () => {
playSfx("sfx/test.ogg");
});

document.querySelector("#loop").addEventListener("click", () => {
playLoop("loop/test.ogg");
});

document.querySelector("#stop").addEventListener("click", () => {
stopLoop("loop/test.ogg");
});

moveToRoom("Home", state);
}

window.addEventListener("load", init);

+ 50
- 7
world.js Dosyayı Görüntüle

@@ -11,7 +11,11 @@ dirs = {
"descend": "Down"
}

function updateRoom(dest) {
function moveToRoom(dest, state) {
updateRoom(dest, state);
}

function updateRoom(dest, state) {
const room = world[dest];

const areaName = document.querySelector("#area-name");
@@ -20,18 +24,40 @@ function updateRoom(dest) {
areaName.innerText = room.name;
areaDesc.innerText = room.desc;

document.querySelectorAll(".move-button").forEach(button => {
const dir = button.id.replace("move-", "");
const holder = document.querySelector("#move-holder");

holder.innerHTML = "";

Object.entries(dirs).forEach(([dir, name]) => {
const button = document.createElement("button");
button.classList.add("move-button")
button.id = "move-" + dir;
button.classList.add("disabled");
button.setAttribute("disabled", "true");
button.innerText = dirs[dir];
holder.appendChild(button);
});

Object.entries(room.exits).forEach(([dir, val]) => {
Object.entries(room.exits).forEach(([dir, exit]) => {
const button = document.querySelector("#move-" + dir);
const dest = world[exit.target];

// if any condition fails, don't enable/add a listener
if (exit.conditions) {
console.log(exit.conditions);
if (!exit.conditions.every(cond => cond(state))) {
return;
}
}

button.classList.remove("disabled");
button.removeAttribute("disabled");
button.innerText = dest.name;

button.innerText = val.target;
button.addEventListener("click", () => {
// todo: log
moveToRoom(exit.target, state);
})
});
}

@@ -41,8 +67,25 @@ world = {
"desc": "Where the wifi autoconnects",
"exits": {
"up": {
"target": "Dennis",
"desc": "The obvious exit, but better."
"target": "Locked Room",
"desc": "It's locked!",
"move": "You enter the secret locked room",
"conditions": [
state => {
return state.player.items.keys.includes("Locked Room");
}
]
}
}
},
"Locked Room": {
"name": "Locked Room",
"desc": "Super seecret",
"exits": {
"down": {
"target": "Home",
"desc": "Back to home",
"move": "You dab"
}
}
}


Yükleniyor…
İptal
Kaydet