Sfoglia il codice sorgente

Got some basic player-prey mechanics going

tags/v0.2.8
Fen Dweller 7 anni fa
parent
commit
543b9e2ff8
6 ha cambiato i file con 195 aggiunte e 13 eliminazioni
  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 Vedi File

@@ -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 Vedi File

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


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

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


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

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


+ 8
- 2
feast.html Vedi File

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


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


<div id="game-and-stats"> <div id="game-and-stats">
<div id="log"> <div id="log">
Welcome to Feast v0.0.1
Welcome to Feast v0.0.2
</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>
@@ -115,6 +115,12 @@
<div id="combat-desc"> <div id="combat-desc">
</div> </div>
</div> </div>
<div class="selector" id="selector-eaten">
<ul id="eaten">
</ul>
<div id="eaten-desc">
</div>
</div>
<div class="selector" id="selector-dialog"> <div class="selector" id="selector-dialog">


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


+ 65
- 11
feast.js Vedi File

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

let currentRoom = null; let currentRoom = null;
let currentDialog = null; let currentDialog = null;


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


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


let respawnRoom;

function round(number, digits) { function round(number, digits) {
return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits); return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits);
} }
@@ -53,6 +56,25 @@ function updateExplore() {
updateExploreActions(); 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() { function updateCombat() {
let list = document.getElementById("combat"); let list = document.getElementById("combat");


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


function updateDisplay() { function updateDisplay() {

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


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


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

updateDisplay();
} }
function startCombat(opponent) { function startCombat(opponent) {
mode = "combat";
changeMode("combat");
currentFoe = opponent; currentFoe = opponent;
update(["Oh shit it's a " + opponent.description()]); update(["Oh shit it's a " + opponent.description()]);
} }
@@ -219,6 +246,7 @@ function attackClicked(index) {
if (player.health <= 0) { if (player.health <= 0) {
update(["You fall to the ground..."]); update(["You fall to the ground..."]);
changeMode("eaten"); changeMode("eaten");
updateDisplay();
} }
} }
} }
@@ -227,8 +255,34 @@ function attackHovered(index) {
document.getElementById("combat-desc").innerHTML = player.attacks[index].desc; 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) { function startDialog(dialog) {
mode = "dialog";
changeMode("dialog");
currentDialog = dialog; currentDialog = dialog;
update([currentDialog.text]); update([currentDialog.text]);
currentDialog.visit(); currentDialog.visit();
@@ -240,7 +294,7 @@ function dialogClicked(index) {
update([currentDialog.text]); update([currentDialog.text]);
currentDialog.visit(); currentDialog.visit();
if (currentDialog.choices.length == 0) { if (currentDialog.choices.length == 0) {
mode = "explore";
changeMode("explore");
updateDisplay(); updateDisplay();
} }
} }


+ 79
- 0
vore.js Vedi File

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


this.attacks.push(new punchAttack(this)); this.attacks.push(new punchAttack(this));
this.attacks.push(new flankAttack(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() { function Micro() {
@@ -208,3 +228,62 @@ function WasteContainer(name) {
function Bowels() { function Bowels() {
WasteContainer.call(this, "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 Vedi File

@@ -161,6 +161,11 @@ let locationsSrc = [
"name": "North Street", "name": "North Street",
"dir": SOUTH, "dir": SOUTH,
"desc": "You walk out of the DANGER ZONE" "desc": "You walk out of the DANGER ZONE"
},
{
"name": "SUPER DANGER ZONE",
"dir": NORTH,
"desc": "Getting eaten is fun!"
} }
], ],
"hooks": [ "hooks": [
@@ -168,6 +173,22 @@ let locationsSrc = [
startCombat(new Anthro()); 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());
}
]
} }
]; ];




Loading…
Annulla
Salva