瀏覽代碼

World is chosen at the start. Can have multiple worlds

tags/v0.1.0
Fen Dweller 6 年之前
父節點
當前提交
664325b3c2
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: E80B35A6F11C3656
共有 2 個文件被更改,包括 81 次插入69 次删除
  1. +2
    -2
      satiate.js
  2. +79
    -67
      world.js

+ 2
- 2
satiate.js 查看文件

@@ -29,10 +29,10 @@ function print(lines) {
// setup the game

function init() {
initWorld(state);
initWorld("demo", state);
initAudio();

moveToRoom("Home", state);
moveToRoom("Home", state, false);
}

window.addEventListener("load", init);

+ 79
- 67
world.js 查看文件

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

function initWorld(state) {
function initWorld(worldChoice, state) {
state.world = worlds[worldChoice];
initRoomState(state);
}

function initRoomState(state) {
console.log(state.world);
state.player.rooms = {};
Object.entries(world).forEach(([key, val]) => {
Object.entries(state.world).forEach(([key, val]) => {
state.player.rooms[key] = {};
});
}
@@ -34,8 +36,8 @@ function removeActionDescription() {
descHolder.textContent = "";
}

function moveToRoom(dest, state) {
const room = world[dest];
function moveToRoom(dest, state, announce=true) {
const room = state.world[dest];

console.log(room);

@@ -47,11 +49,14 @@ function moveToRoom(dest, state) {
}
}

if (announce)
state.world[dest].move(state.world[dest], state);

updateRoom(dest, state);
}

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

if (!state.player.rooms[dest.id]) {
state.player.rooms[dest.id] = {};
@@ -80,7 +85,7 @@ function updateRoom(dest, state) {
if (room.exits) {
Object.entries(room.exits).forEach(([dir, exit]) => {
const button = document.querySelector("#move-" + dir);
const dest = world[exit.target];
const dest = state.world[exit.target];

// don't even show an exit if this fails!

@@ -156,71 +161,78 @@ function updateRoom(dest, state) {

}

world = {
"Home": {
"id": "Home",
"name": "Home",
"desc": "Where the wifi autoconnects",
"actions": [
{
"name": "Squint",
"desc": "Squint in a very aggressive manner",
"execute": (self, state) => {
state.player.rooms[self.id].squinted = true;
print(["You stare at the wall and notice a secret door. But where is the key?"]);
}
worlds = {
"demo": {
"Home": {
"id": "Home",
"name": "Home",
"desc": "Where the wifi autoconnects",
"move": (self, state) => {
print(["You go back to your living room"]);
},
{
"name": "Find Keys",
"desc": "Find your keys",
"execute": (self, state) => {
state.player.items.keys.push("Locked Room");
print(["You found your keys under the couch cushions"]);
"actions": [
{
"name": "Squint",
"desc": "Squint in a very aggressive manner",
"execute": (self, state) => {
state.player.rooms[self.id].squinted = true;
print(["You stare at the wall and notice a secret door. But where is the key?"]);
}
},
"show": [
(self, state) => {
return state.player.rooms[self.id].squinted;
{
"name": "Find Keys",
"desc": "Find your keys",
"execute": (self, state) => {
state.player.items.keys.push("Locked Room");
print(["You found your keys under the couch cushions"]);
},
(self, state) => {
return !state.player.items.keys.includes("Locked Room");
}
]
}
],
"exits": {
"up": {
"target": "Locked Room",
"desc": "It's locked!",
"move": "You enter the secret locked room",
"conditions": [
(self, state) => {
return state.player.items.keys.includes("Locked Room");
}
],
"show": [
(self, state) => {
console.log(self);
return state.player.rooms[self.id].squinted;
}
]
}
"show": [
(self, state) => {
return state.player.rooms[self.id].squinted;
},
(self, state) => {
return !state.player.items.keys.includes("Locked Room");
}
]
}
],
"exits": {
"up": {
"target": "Locked Room",
"desc": "It's locked!",
"conditions": [
(self, state) => {
return state.player.items.keys.includes("Locked Room");
}
],
"show": [
(self, state) => {
console.log(self);
return state.player.rooms[self.id].squinted;
}
]
}
},
"hooks": [
(self, state) => {
print(["This is a test of the hooks"]);
return true;
}
]
},
"hooks": [
(self, state) => {
print(["This is a test of the hooks"]);
return true;
}
]
},
"Locked Room": {
"id": "Locked Room",
"name": "Locked Room",
"desc": "Super seecret",
"exits": {
"down": {
"target": "Home",
"desc": "Back to home",
"move": "You dab"
"Locked Room": {
"id": "Locked Room",
"name": "Locked Room",
"desc": "Super seecret",
"move": (self, state) => {
print(["You enter the locked room. wowie!"]);
},
"exits": {
"down": {
"target": "Home",
"desc": "Back to home",
"move": "You dab"
}
}
}
}


Loading…
取消
儲存