Browse Source

Objects in their own file. Exits are one-way and described. Log scrolls.

tags/v0.2.8
Fen Dweller 7 years ago
parent
commit
d08ded6637
5 changed files with 168 additions and 87 deletions
  1. +7
    -2
      feast.css
  2. +6
    -16
      feast.html
  3. +30
    -52
      feast.js
  4. +67
    -0
      objects.js
  5. +58
    -17
      world.js

+ 7
- 2
feast.css View File

@@ -42,16 +42,21 @@ button {
} }


.dialog-button { .dialog-button {
width: 100px;
height: 100px;
width: 300px;
height: 75px;
font-size: 18px;s font-size: 18px;s
} }


#dialog {
list-style-type: none;
}

#log { #log {
background: #222; background: #222;
width: 100%; width: 100%;
height: 100%; height: 100%;
flex: 3; flex: 3;
overflow: auto;
} }


#stats { #stats {


+ 6
- 16
feast.html View File

@@ -5,6 +5,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Feast</title> <title>Feast</title>
<link rel="stylesheet" href="feast.css"> <link rel="stylesheet" href="feast.css">
<script src="objects.js"></script>
<script src="dialog.js"></script> <script src="dialog.js"></script>
<script src="world.js"></script> <script src="world.js"></script>
<script src="vore.js"></script> <script src="vore.js"></script>
@@ -21,7 +22,7 @@


<div id="game-and-stats"> <div id="game-and-stats">
<div id="log"> <div id="log">
Welcome to Feast v0.0.3
Welcome to Feast v0.0.1
</div> </div>
<div id="stats"> <div id="stats">
<div class="stat-line" id="time">Time: to get a watch</div> <div class="stat-line" id="time">Time: to get a watch</div>
@@ -125,21 +126,10 @@
</div> </div>
</div> </div>
<div class="selector" id="selector-dialog"> <div class="selector" id="selector-dialog">
<div id="combat">
<table>
<tr>
<th>
<button class="dialog-button">Headbang violently</button>
</th>
<th>
<button class="dialog-button">Belch at</button>
</th>
<th>
<button class="dialog-button">Accost</button>
</th>
</tr>
</table>
</div>

<ul id="dialog">
</ul>

</div> </div>
</div> </div>
</body> </body>


+ 30
- 52
feast.js View File

@@ -3,44 +3,18 @@ let currentDialog = null;


let dirButtons = []; let dirButtons = [];
let actionButtons = []; let actionButtons = [];
let dialogButtons = [];


let mode = "explore"; let mode = "explore";
let actions = []; let actions = [];
let time = 9*60;
let time = 9*60*60;
let newline = "&nbsp;"; let newline = "&nbsp;";


let player = new Player(); let player = new Player();


function Object(name="Potato") {
this.name = name;
this.actions = [];
}

function Burger() {
Object.call(this, "Burger");
this.actions.push({
"name": "Punch Burger",
"action": function() {
player.health += 10;
update(["You punch the hamburger."]);
}
});
}

function Nerd() {
Object.call(this, "Nerd");
this.actions.push({
"name": "Eat Nerd",
"action": function() {
startDialog(new EatDude());
}
});
}

function startDialog(dialog) { function startDialog(dialog) {
mode = "dialog"; mode = "dialog";
currentDialog = dialog; currentDialog = dialog;
update([currentDialog.visit()]);
updateDisplay(); updateDisplay();
} }


@@ -87,18 +61,20 @@ function updateCombat() {
} }


function updateDialog() { function updateDialog() {
for (let i = 0; i < dialogButtons.length; i++) {
if (i < currentDialog.choices.length) {
dialogButtons[i].disabled = false;
dialogButtons[i].innerHTML = currentDialog.choices[i].text;
dialogButtons[i].classList.remove("inactive-button");
dialogButtons[i].classList.add("active-button");
} else {
dialogButtons[i].disabled = true;
dialogButtons[i].innerHTML = "";
dialogButtons[i].classList.remove("active-button");
dialogButtons[i].classList.add("inactive-button");
}
let list = document.getElementById("dialog");

while(list.firstChild) {
list.removeChild(list.firstChild);
}

for (let i = 0; i < currentDialog.choices.length; i++) {
let li = document.createElement("li");
let button = document.createElement("button");
button.classList.add("dialog-button");
button.innerHTML = currentDialog.choices[i].text;
button.addEventListener("click", function() { dialogClicked(i); });
li.appendChild(button);
list.appendChild(li);
} }
} }


@@ -115,6 +91,7 @@ function updateDisplay() {
document.getElementById("selector-combat").style.display = "flex"; document.getElementById("selector-combat").style.display = "flex";
document.getElementById("selector-dialog").style.display = "none"; document.getElementById("selector-dialog").style.display = "none";
updateCombat(); updateCombat();
break;
case "dialog": case "dialog":
document.getElementById("selector-explore").style.display = "none"; document.getElementById("selector-explore").style.display = "none";
document.getElementById("selector-combat").style.display = "none"; document.getElementById("selector-combat").style.display = "none";
@@ -130,14 +107,15 @@ function updateDisplay() {
} }


function advanceTime(amount) { function advanceTime(amount) {
time = (time + amount) % 1440;
time = (time + amount) % 86400;
} }

function renderTime(time) { function renderTime(time) {
let suffix = (time < 720) ? "AM" : "PM";
let hour = Math.floor((time % 720) / 60);
let suffix = (time < 43200) ? "AM" : "PM";
let hour = Math.floor((time % 43200) / 3600);
if (hour == 0) if (hour == 0)
hour = 12; hour = 12;
let minute = time % 60;
let minute = Math.floor(time / 60) % 60;
if (minute < 9) if (minute < 9)
minute = "0" + minute; minute = "0" + minute;


@@ -151,21 +129,21 @@ function move(direction) {
return; return;
} }


moveTo(target);
moveTo(target,currentRoom.exitDescs[direction]);
} }


function moveTo(room) {
function moveTo(room,desc="You go places lol") {
actions = []; actions = [];
currentRoom = room; currentRoom = room;
advanceTime(1);
advanceTime(30);


currentRoom.objects.forEach(function (object) { currentRoom.objects.forEach(function (object) {
object.actions.forEach(function (action) { object.actions.forEach(function (action) {
actions.push(action); actions.push(action);
})
})
});
});


update(["You move to " + currentRoom.name,currentRoom.description,newline]);
update([desc,newline]);
} }


window.addEventListener('load', function(event) { window.addEventListener('load', function(event) {
@@ -173,8 +151,6 @@ window.addEventListener('load', function(event) {
loadCompass(); loadCompass();
loadDialog(); loadDialog();
currentRoom = createWorld(); currentRoom = createWorld();
currentRoom.objects.push(new Burger());
currentRoom.objects.push(new Nerd());
moveTo(currentRoom); moveTo(currentRoom);
updateDisplay(); updateDisplay();
}); });
@@ -186,6 +162,8 @@ function update(lines=[]) {
div.innerHTML = lines[i]; div.innerHTML = lines[i];
log.appendChild(div); log.appendChild(div);
} }

log.scrollTop = log.scrollHeight;
updateDisplay(); updateDisplay();
} }




+ 67
- 0
objects.js View File

@@ -0,0 +1,67 @@
function Object(name="Potato") {
this.name = name;
this.actions = [];
}

function Burger() {
Object.call(this, "Burger");
this.actions.push({
"name": "Punch Burger",
"action": function() {
player.health += 10;
update(["You punch the hamburger."]);
}
});
}

function Nerd() {
Object.call(this, "Nerd");
this.actions.push({
"name": "Eat Nerd",
"action": function() {
startDialog(new EatDude());
}
});
}

function Toilet() {
Object.call(this, "Toilet");
this.actions.push({
"name": "Admire toilet",
"action": function() {
update(["You admire the toilet."]);
}
});
}

function TV() {
Object.call(this, "TV");
this.actions.push({
"name": "Watch TV",
"action": function() {
update(["Reruns, again."]);
}
});
}

function Phone() {
Object.call(this, "Phone");
this.actions.push({
"name": "Headbutt phone",
"action": function() {
startDialog(new PhoneCall());
}
});
}

function Bed() {
Object.call(this, "Bed");
this.actions.push({
"name": "Sleep",
"action": function() {
update(["You take a nap."]);
advanceTime(2700);
updateDisplay();
}
});
}

+ 58
- 17
world.js View File

@@ -19,23 +19,35 @@ let locations = {};
let locationsSrc = [ let locationsSrc = [
{ {
"name": "Bedroom", "name": "Bedroom",
"desc": "A bedroom",
"desc": "A bedroom. It has a bed in it.",
"conn": [ "conn": [
{ {
"name": "Bathroom", "name": "Bathroom",
"dir": EAST
"dir": EAST,
"desc": "You step into your bathroom."
}, },
{ {
"name": "Living Room", "name": "Living Room",
"dir": NORTH
"dir": NORTH,
"desc": "You walk into the living room."
} }
],
"objs": [
Bed
] ]
}, },
{ {
"name": "Bathroom", "name": "Bathroom",
"desc": "The bathroom",
"desc": "Your modest bathroom.",
"conn": [ "conn": [

{
"name": "Bedroom",
"dir": WEST,
"desc": "You walk back into your bedroom."
}
],
"objs": [
Toilet
] ]
}, },
{ {
@@ -44,8 +56,18 @@ let locationsSrc = [
"conn": [ "conn": [
{ {
"name": "Street", "name": "Street",
"dir": NORTH
"dir": NORTH,
"desc": "You step outside."
},
{
"name": "Bedroom",
"dir": SOUTH,
"desc": "You walk into your bedroom."
} }
],
"objs": [
TV,
Phone
] ]
}, },
{ {
@@ -54,14 +76,30 @@ let locationsSrc = [
"conn": [ "conn": [
{ {
"name": "Alley", "name": "Alley",
"dir": WEST
"dir": WEST,
"desc": "You wander into the dark alley."
},
{
"name": "Living Room",
"dir": SOUTH,
"desc": "You step back into your apartment."
} }
],
"objs": [
Nerd
] ]
}, },
{ {
"name": "Alley", "name": "Alley",
"desc": "A suspicious alley", "desc": "A suspicious alley",
"conn": [ "conn": [
{
"name": "Street",
"dir": EAST,
"desc": "You hurry back into the open street."
}
],
"objs": [


] ]
} }
@@ -71,6 +109,7 @@ function Location(name="Nowhere",desc="Nada") {
this.name = name; this.name = name;
this.description = desc; this.description = desc;
this.exits = [null,null,null,null,null,null,null,null]; this.exits = [null,null,null,null,null,null,null,null];
this.exitDescs = [null,null,null,null,null,null,null,null];
this.objects = []; this.objects = [];
} }


@@ -78,17 +117,16 @@ function opposite(direction) {
return (direction + 4) % 8; return (direction + 4) % 8;
} }


function connectLocations(loc1,loc2,loc1Exit) {
if (loc1.exits[loc1Exit] != null) {
alert(loc1.name + " is already connected to " + loc1.exits[loc1Exit].name);
return;
} else if (loc2.exits[opposite(loc1Exit)] != null) {
alert(loc2.name + " is already connected to " + loc2.exits[opposite(loc1Exit)].name);
function connectLocations(loc1,loc2,dir,desc) {
if (loc1.exits[dir] != null) {
alert(loc1.name + " is already connected to " + loc1.exits[dir].name);
return; return;
} else { } else {
if (loc1Exit >= 0 && loc1Exit <= 7) {
loc1.exits[loc1Exit] = loc2;
loc2.exits[opposite(loc1Exit)] = loc1;
if (dir >= 0 && dir <= 7) {
loc1.exits[dir] = loc2;
loc1.exitDescs[dir] = desc;
} else {
alert("Invalid direction given when linking " + loc1.name + " and " + loc2.name + ": " + dir);
} }
} }
} }
@@ -98,6 +136,9 @@ function createWorld() {
let src = locationsSrc[i]; let src = locationsSrc[i];
let location = new Location(src.name,src.desc); let location = new Location(src.name,src.desc);
locations[src.name] = location; locations[src.name] = location;
src.objs.forEach(function (obj) {
location.objects.push(new obj());
});
} }


for (let i = 0; i < locationsSrc.length; i++) { for (let i = 0; i < locationsSrc.length; i++) {
@@ -105,7 +146,7 @@ function createWorld() {
let from = locations[src.name]; let from = locations[src.name];
for (let j = 0; j < src.conn.length; j++) { for (let j = 0; j < src.conn.length; j++) {
let to = locations[src.conn[j].name]; let to = locations[src.conn[j].name];
connectLocations(from, to, src.conn[j].dir);
connectLocations(from, to, src.conn[j].dir, src.conn[j].desc);
} }
} }




Loading…
Cancel
Save