| @@ -169,13 +169,13 @@ function checkCache(type, name, hit, miss) { | |||||
| } | } | ||||
| } | } | ||||
| function initAudio(game, state) { | |||||
| function initAudio(story, state) { | |||||
| if (!audioContext) | if (!audioContext) | ||||
| audioContext = new (window.AudioContext || window.webkitAudioContext)(); | audioContext = new (window.AudioContext || window.webkitAudioContext)(); | ||||
| createCache(); | createCache(); | ||||
| games[game].sounds.forEach(sound => { | |||||
| story.sounds.forEach(sound => { | |||||
| loadAudio(sound); | loadAudio(sound); | ||||
| }); | }); | ||||
| } | } | ||||
| @@ -1,4 +1,6 @@ | |||||
| function initGame(game, state) { | |||||
| stories = []; | |||||
| function initGame(story, state) { | |||||
| state.info = {}; | state.info = {}; | ||||
| state.info.time = 60 * 60 * 9; | state.info.time = 60 * 60 * 9; | ||||
| @@ -6,6 +6,24 @@ html, body, .scene { | |||||
| font-family: sans-serif; | 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 { | #info-area { | ||||
| position: relative; | position: relative; | ||||
| display: flex; | display: flex; | ||||
| @@ -7,6 +7,7 @@ | |||||
| <script src="audio.js"></script> | <script src="audio.js"></script> | ||||
| <script src="entity.js"></script> | <script src="entity.js"></script> | ||||
| <script src="game.js"></script> | <script src="game.js"></script> | ||||
| <script src="stories/demo.js"></script> | |||||
| <script src="world.js"></script> | <script src="world.js"></script> | ||||
| <script src="satiate.js"></script> | <script src="satiate.js"></script> | ||||
| <meta name="theme-color" content="#000000" /> | <meta name="theme-color" content="#000000" /> | ||||
| @@ -18,8 +19,13 @@ | |||||
| </head> | </head> | ||||
| <body> | <body> | ||||
| <div class="scene" id= | |||||
| <div class="scene" id="game"> | |||||
| <div class="scene" id="pick"> | |||||
| <select id="game-select"> | |||||
| </select> | |||||
| <button id="start-button">Start</button> | |||||
| </div> | |||||
| <div class="hidden-scene" id="game"> | |||||
| <div id="info-area"> | <div id="info-area"> | ||||
| <div class="sidebar"> | <div class="sidebar"> | ||||
| <div id="menu"> | <div id="menu"> | ||||
| @@ -53,5 +59,12 @@ | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <!-- | |||||
| <div class="modal" id="settings"> | |||||
| <div class="modal-content"> | |||||
| <button>butt</button> | |||||
| </div> | |||||
| </div> | |||||
| --> | |||||
| </body> | </body> | ||||
| </html> | </html> | ||||
| @@ -34,14 +34,39 @@ function refresh() { | |||||
| updatePlayerInfo(state); | 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); | 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); | |||||
| @@ -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; | |||||
| } | |||||
| ] | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }); | |||||
| @@ -11,8 +11,8 @@ dirs = { | |||||
| "descend": "Down" | "descend": "Down" | ||||
| } | } | ||||
| function initWorld(worldChoice, state) { | |||||
| state.world = games[worldChoice]["world"]; | |||||
| function initWorld(story, state) { | |||||
| state.world = story["world"]; | |||||
| initRoomState(state); | initRoomState(state); | ||||
| } | } | ||||
| @@ -72,7 +72,7 @@ function goToRoom(dest, state) { | |||||
| } | } | ||||
| state.player.location = dest; | state.player.location = dest; | ||||
| refresh(); | 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; | |||||
| } | |||||
| ] | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||