Bladeren bron

Got some basic player-prey mechanics going

tags/v0.2.8
Fen Dweller 7 jaren geleden
bovenliggende
commit
543b9e2ff8
6 gewijzigde bestanden met toevoegingen van 195 en 13 verwijderingen
  1. +11
    -0
      combat.js
  2. +11
    -0
      feast.css
  3. +8
    -2
      feast.html
  4. +65
    -11
      feast.js
  5. +79
    -0
      vore.js
  6. +21
    -0
      world.js

+ 11
- 0
combat.js Bestand weergeven

@@ -31,3 +31,14 @@ function flankAttack(attacker) {
}
};
}

function devourPlayer(attacker) {
return {
name: "Devours YOU!",
desc: "You won't see this",
attackPlayer: function(defender) {
changeMode("eaten");
return "The voracious " + attacker.description() + " pins you down and devours you in seconds.";
}
}
}

+ 11
- 0
feast.css Bestand weergeven

@@ -56,6 +56,13 @@ button {
user-select: none;
}

.eaten-button {
width: 200px;
height: 50px;
font-size: 18px;
user-select: none;
}

#combat-desc {
width: 200px;
height: 400px;
@@ -77,6 +84,10 @@ button {
list-style-type: none;
}

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

#log {
background: #222;
width: 100%;


+ 8
- 2
feast.html Bestand weergeven

@@ -1,4 +1,4 @@
<!DOCTYPE html>
0.0.2<!DOCTYPE html>
<html lang="en">

<head>
@@ -23,7 +23,7 @@

<div id="game-and-stats">
<div id="log">
Welcome to Feast v0.0.1
Welcome to Feast v0.0.2
</div>
<div id="stats">
<div class="stat-line" id="time">Time: to get a watch</div>
@@ -115,6 +115,12 @@
<div id="combat-desc">
</div>
</div>
<div class="selector" id="selector-eaten">
<ul id="eaten">
</ul>
<div id="eaten-desc">
</div>
</div>
<div class="selector" id="selector-dialog">

<ul id="dialog">


+ 65
- 11
feast.js Bestand weergeven

@@ -1,3 +1,4 @@

let currentRoom = null;
let currentDialog = null;

@@ -11,6 +12,8 @@ let newline = "&nbsp;";

let player = new Player();

let respawnRoom;

function round(number, digits) {
return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits);
}
@@ -53,6 +56,25 @@ function updateExplore() {
updateExploreActions();
}

function updateEaten() {
let list = document.getElementById("eaten");

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

for (let i = 0; i < currentFoe.struggles.length; i++) {
let li = document.createElement("li");
let button = document.createElement("button");
button.classList.add("eaten-button");
button.innerHTML = currentFoe.struggles[i].name;
button.addEventListener("click", function() { struggleClicked(i); } );
button.addEventListener("mouseover", function() { struggleHovered(i); } );
li.appendChild(button);
list.appendChild(li);
}

}
function updateCombat() {
let list = document.getElementById("combat");

@@ -91,25 +113,27 @@ function updateDialog() {
}

function updateDisplay() {

document.querySelectorAll(".selector").forEach(function (x) {
x.style.display = "none";
});
switch(mode) {
case "explore":
document.getElementById("selector-explore").style.display = "flex";
document.getElementById("selector-combat").style.display = "none";
document.getElementById("selector-dialog").style.display = "none";
updateExplore();
break;
case "combat":
document.getElementById("selector-explore").style.display = "none";
document.getElementById("selector-combat").style.display = "flex";
document.getElementById("selector-dialog").style.display = "none";
updateCombat();
break;
case "dialog":
document.getElementById("selector-explore").style.display = "none";
document.getElementById("selector-combat").style.display = "none";
document.getElementById("selector-dialog").style.display = "flex";
updateDialog();
break;
case "eaten":
document.getElementById("selector-eaten").style.display = "flex";
updateEaten();
break;
}

document.getElementById("time").innerHTML = "Time: " + renderTime(time);
@@ -166,6 +190,7 @@ window.addEventListener('load', function(event) {
loadCompass();
loadDialog();
currentRoom = createWorld();
respawnRoom = currentRoom;
moveTo(currentRoom);
updateDisplay();
});
@@ -182,8 +207,8 @@ function update(lines=[]) {
updateDisplay();
}

function changeMode(mode) {
this.mode = mode;
function changeMode(newMode) {
mode = newMode;
let body = document.querySelector("body");
body.className = "";
switch(mode) {
@@ -198,9 +223,11 @@ function changeMode(mode) {
body.classList.add("eaten");
break;
}

updateDisplay();
}
function startCombat(opponent) {
mode = "combat";
changeMode("combat");
currentFoe = opponent;
update(["Oh shit it's a " + opponent.description()]);
}
@@ -219,6 +246,7 @@ function attackClicked(index) {
if (player.health <= 0) {
update(["You fall to the ground..."]);
changeMode("eaten");
updateDisplay();
}
}
}
@@ -227,8 +255,34 @@ function attackHovered(index) {
document.getElementById("combat-desc").innerHTML = player.attacks[index].desc;
}

function struggleClicked(index) {
let struggle = currentFoe.struggles[index];

let result = struggle.struggle(player);

update([result.lines]);

if (result.escape) {
changeMode("explore");
} else {
player.health -= 20;

if (player.health <= -100) {
update(["You digest in the depths of the " + currentFoe.description()]);
moveTo(respawnRoom);
changeMode("explore");
player.health = 100;
update(["You wake back up in your bed."]);
}
}
}

function struggleHovered(index) {
document.getElementById("eaten-desc").innerHTML = player.struggles[index].desc;
}

function startDialog(dialog) {
mode = "dialog";
changeMode("dialog");
currentDialog = dialog;
update([currentDialog.text]);
currentDialog.visit();
@@ -240,7 +294,7 @@ function dialogClicked(index) {
update([currentDialog.text]);
currentDialog.visit();
if (currentDialog.choices.length == 0) {
mode = "explore";
changeMode("explore");
updateDisplay();
}
}


+ 79
- 0
vore.js Bestand weergeven

@@ -46,6 +46,26 @@ function Anthro() {

this.attacks.push(new punchAttack(this));
this.attacks.push(new flankAttack(this));

this.struggles = [];

this.struggles.push(new plead(this));
this.struggles.push(new struggle(this));
}

function Fen() {
Anthro.call(this, name);

this.build = "loomy";
this.species = "crux";

this.attacks = [];

this.attacks.push(new devourPlayer(this));

this.struggles = [];

this.struggles.push(new rub(this));
}

function Micro() {
@@ -208,3 +228,62 @@ function WasteContainer(name) {
function Bowels() {
WasteContainer.call(this, "Bowels");
}

// PLAYER PREY

function plead(predator) {
return {
name: "Plead",
desc: "Ask very, very nicely for the predator to let you go. More effective if you haven't hurt your predator.",
struggle: function(player) {
let escape = Math.random() < predator.health / predator.maxHealth;

if (escape) {
return {
"escape": escape,
"lines": ["You plead for the " + predator.description() + " to let you free, and they begrudingly agree, horking you up and leaving you shivering on the ground"]
};
} else {
return {
"escape": escape,
"lines": ["You plead with the " + predator.description() + " to let you go, but they refuse."]
};
}
}
};
}

function struggle(predator) {
return {
name: "Struggle",
desc: "Try to squirm free. More effective if you've hurt your predator.",
struggle: function(player) {
let escape = Math.random() > predator.health / predator.maxHealth;

if (escape) {
return {
"escape": escape,
"lines": ["You struggle and squirm, forcing the " + predator.description() + " to hork you up. They groan and stumble away, exhausted by your efforts."]
};
} else {
return {
"escape": escape,
"lines": ["You squirm and writhe within the " + predator.description() + " to no avail."]
};
}
}
};
}

function rub(predator) {
return {
name: "Rub",
desc: "Rub rub rub",
struggle: function(player) {
return {
"escape": false,
"lines": ["You rub the walls of your predator's belly. At least the " + predator.description() + " is getting something out of this."]
};
}
};
}

+ 21
- 0
world.js Bestand weergeven

@@ -161,6 +161,11 @@ let locationsSrc = [
"name": "North Street",
"dir": SOUTH,
"desc": "You walk out of the DANGER ZONE"
},
{
"name": "SUPER DANGER ZONE",
"dir": NORTH,
"desc": "Getting eaten is fun!"
}
],
"hooks": [
@@ -168,6 +173,22 @@ let locationsSrc = [
startCombat(new Anthro());
}
]
},
{
"name": "SUPER DANGER ZONE",
"desc": "Very dangerous",
"conn": [
{
"name": "DANGER ZONE",
"dir": SOUTH,
"desc": "You hurriedly leave the SUPER DANGER ZONE"
}
],
"hooks": [
function() {
startCombat(new Fen());
}
]
}
];



Laden…
Annuleren
Opslaan