diff --git a/audio.js b/audio.js index 78cf09b..4baccf3 100644 --- a/audio.js +++ b/audio.js @@ -169,13 +169,13 @@ function checkCache(type, name, hit, miss) { } } -function initAudio(game, state) { +function initAudio(story, state) { if (!audioContext) audioContext = new (window.AudioContext || window.webkitAudioContext)(); createCache(); - games[game].sounds.forEach(sound => { + story.sounds.forEach(sound => { loadAudio(sound); }); } diff --git a/game.js b/game.js index a423202..13f8975 100644 --- a/game.js +++ b/game.js @@ -1,4 +1,6 @@ -function initGame(game, state) { +stories = []; + +function initGame(story, state) { state.info = {}; state.info.time = 60 * 60 * 9; diff --git a/satiate.css b/satiate.css index c3bc5cc..1d04fb3 100644 --- a/satiate.css +++ b/satiate.css @@ -6,6 +6,24 @@ html, body, .scene { font-family: sans-serif; } +.hidden-scene { + display: none; +} + +.modal { + position: fixed; + z-index: 1; + height: 100%; + width: 100%; + left: 0; + top: 0; + background-color: rgba(0,0,0,0.5); +} + +.modal-content { + margin: 50%; +} + #info-area { position: relative; display: flex; diff --git a/satiate.html b/satiate.html index dfd87d8..3c9ae20 100644 --- a/satiate.html +++ b/satiate.html @@ -7,6 +7,7 @@ + @@ -18,8 +19,13 @@ -
+
+ + +
+
+ diff --git a/satiate.js b/satiate.js index aa2ba42..c61a836 100644 --- a/satiate.js +++ b/satiate.js @@ -34,14 +34,39 @@ function refresh() { updatePlayerInfo(state); } -// setup the game +// set up the game -function init() { - initWorld("demo", state); - initAudio("demo", state); - initGame("demo", state); +function init(story) { + initWorld(story, state); + initAudio(story, state); + initGame(story, state); goToRoom("Home", state); } -window.addEventListener("load", init); +// set up the load screen + +function initStart() { + const select = document.querySelector("#game-select"); + const options = {}; + + stories.forEach(story => { + const option = document.createElement("option"); + option.value = story.id; + option.textContent = story.name; + select.appendChild(option); + options[story.id] = story; + }) + + const start = document.querySelector("#start-button"); + + start.addEventListener("click", (event) => { + init(options[select.value]); + document.querySelector("#pick").classList.remove("scene"); + document.querySelector("#pick").classList.add("hidden-scene"); + document.querySelector("#game").classList.remove("hidden-scene"); + document.querySelector("#game").classList.add("scene"); + }); +} + +window.addEventListener("load", initStart); diff --git a/stories/demo.js b/stories/demo.js new file mode 100644 index 0000000..1f45702 --- /dev/null +++ b/stories/demo.js @@ -0,0 +1,95 @@ +stories.push({ + "id": "demo", + "name": "Tech Demo", + "sounds": [ + "sfx/oof.ogg" + ], + "world": { + "Home": { + "id": "Home", + "name": "Home", + "desc": "Where the wifi autoconnects", + "move": (room, state) => { + print(["You go back to your living room"]); + }, + "actions": [ + { + "name": "Squint", + "desc": "Squint in a very aggressive manner", + "execute": (room, state) => { + state.player.rooms[room.id].squinted = true; + print(["You stare at the wall and notice a secret door. But where is the key?"]); + } + }, + { + "name": "Find Keys", + "desc": "Find your keys", + "execute": (room, state) => { + state.player.items.keys.push("Locked Room"); + print(["You found your keys under the couch cushions"]); + }, + "show": [ + (room, state) => { + return state.player.rooms[room.id].squinted; + }, + (room, state) => { + return !state.player.items.keys.includes("Locked Room"); + } + ] + } + ], + "exits": { + "up": { + "target": "Locked Room", + "desc": "It's locked!", + "conditions": [ + (room, state) => { + return state.player.items.keys.includes("Locked Room"); + } + ], + "show": [ + (room, state) => { + return state.player.rooms[room.id].squinted; + } + ] + } + }, + "hooks": [ + (room, state) => { + print(["This is a test of the hooks"]); + return true; + } + ] + }, + "Locked Room": { + "id": "Locked Room", + "name": "Locked Room", + "desc": "Super seecret", + "move": (room, state) => { + print(["You enter the locked room. wowie!"]); + }, + "actions": [ + { + name: "Oof", + desc: "Oof", + execute: (room, state) => { + print(["Oof"]); + playSfx("sfx/oof.ogg"); + } + } + ], + "exits": { + "down": { + "target": "Home", + "desc": "Back to home", + "hooks": [ + (room, exit, state) => { + print(["Potato"]); + return true; + } + ] + } + } + } + } +}); diff --git a/world.js b/world.js index c37c6ed..97e2858 100644 --- a/world.js +++ b/world.js @@ -11,8 +11,8 @@ dirs = { "descend": "Down" } -function initWorld(worldChoice, state) { - state.world = games[worldChoice]["world"]; +function initWorld(story, state) { + state.world = story["world"]; initRoomState(state); } @@ -72,7 +72,7 @@ function goToRoom(dest, state) { } state.player.location = dest; - + refresh(); } @@ -178,104 +178,4 @@ function updateRoom(state) { }); } - - - -} - -games = { - "demo": { - "id": "demo", - "sounds": [ - "sfx/oof.ogg" - ], - "world": { - "Home": { - "id": "Home", - "name": "Home", - "desc": "Where the wifi autoconnects", - "move": (room, state) => { - print(["You go back to your living room"]); - }, - "actions": [ - { - "name": "Squint", - "desc": "Squint in a very aggressive manner", - "execute": (room, state) => { - state.player.rooms[room.id].squinted = true; - print(["You stare at the wall and notice a secret door. But where is the key?"]); - } - }, - { - "name": "Find Keys", - "desc": "Find your keys", - "execute": (room, state) => { - state.player.items.keys.push("Locked Room"); - print(["You found your keys under the couch cushions"]); - }, - "show": [ - (room, state) => { - return state.player.rooms[room.id].squinted; - }, - (room, state) => { - return !state.player.items.keys.includes("Locked Room"); - } - ] - } - ], - "exits": { - "up": { - "target": "Locked Room", - "desc": "It's locked!", - "conditions": [ - (room, state) => { - return state.player.items.keys.includes("Locked Room"); - } - ], - "show": [ - (room, state) => { - return state.player.rooms[room.id].squinted; - } - ] - } - }, - "hooks": [ - (room, state) => { - print(["This is a test of the hooks"]); - return true; - } - ] - }, - "Locked Room": { - "id": "Locked Room", - "name": "Locked Room", - "desc": "Super seecret", - "move": (room, state) => { - print(["You enter the locked room. wowie!"]); - }, - "actions": [ - { - name: "Oof", - desc: "Oof", - execute: (room, state) => { - print(["Oof"]); - playSfx("sfx/oof.ogg"); - } - } - ], - "exits": { - "down": { - "target": "Home", - "desc": "Back to home", - "hooks": [ - (room, exit, state) => { - print(["Potato"]); - return true; - } - ] - } - } - } - } - } }