Browse Source

Added a function to change stats w/ automatic bounds checking

tags/v0.1.1
Fen Dweller 6 years ago
parent
commit
00878e9c40
2 changed files with 27 additions and 35 deletions
  1. +8
    -0
      game.js
  2. +19
    -35
      stories/fen-snack.js

+ 8
- 0
game.js View File

@@ -40,6 +40,14 @@ function initGamePostSetup(state) {
}); });
} }


function changeStat(stat, amount, state) {
let value = state.player.stats[stat].value;
value += amount;
value = Math.max(value, state.player.stats[stat].min);
value = Math.min(value, state.player.stats[stat].max);
state.player.stats[stat].value = value;
}

// TODO: format string this lol // TODO: format string this lol
function renderTime(time) { function renderTime(time) {
let hours = Math.floor(time / 3600) % 12; let hours = Math.floor(time / 3600) % 12;


+ 19
- 35
stories/fen-snack.js View File

@@ -29,8 +29,8 @@ stories.push({
start: "stomach", start: "stomach",
setup: state => { setup: state => {
state.info.time = 86400 - 60 * 25 - 25; state.info.time = 86400 - 60 * 25 - 25;
state.player.stats.health = {name: "Health", type: "meter", value: 100, max: 100, color: "rgb(255,0,0)"};
state.player.stats.stamina = {name: "Stamina", type: "meter", value: 100, max: 100, color: "rgb(100,255,0)"};
state.player.stats.health = {name: "Health", type: "meter", value: 100, min: 0, max: 100, color: "rgb(255,0,0)"};
state.player.stats.stamina = {name: "Stamina", type: "meter", value: 100, min: 0, max: 100, color: "rgb(100,255,0)"};


startTimer({ startTimer({
id: "movement", id: "movement",
@@ -64,15 +64,15 @@ stories.push({
let bonus = state.player.flags.submission ? 10 : 1; let bonus = state.player.flags.submission ? 10 : 1;


if (location.startsWith("stomach")) { if (location.startsWith("stomach")) {
state.player.stats.health.value -= 1;
changeStat("health", -1, state);
} }


if (location.startsWith("intestines")) { if (location.startsWith("intestines")) {
state.player.stats.health.value -= 0.75;
changeStat("health", -0.75, state);
} }
if (location.startsWith("bowels")) { if (location.startsWith("bowels")) {
state.player.stats.health.value -= 0.5;
changeStat("health", -0.5, state);
} }




@@ -109,25 +109,16 @@ stories.push({
let bonus = state.player.flags.submission ? -3 : 0; let bonus = state.player.flags.submission ? -3 : 0;
bonus += state.player.flags.pinned ? -0.5 : 0; bonus += state.player.flags.pinned ? -0.5 : 0;
if (location.startsWith("stomach")) { if (location.startsWith("stomach")) {
state.player.stats.stamina.value += 1 + bonus;
changeStat("stamina", 1 + bonus, state);
} }


if (location.startsWith("intestines")) { if (location.startsWith("intestines")) {
state.player.stats.stamina.value += 0.5 + bonus;
changeStat("stamina", 0.5 + bonus, state);
} }


if (location.startsWith("bowels")) { if (location.startsWith("bowels")) {
state.player.stats.stamina.value += -0.5 + bonus;
}

if (state.player.stats.stamina.value > 100) {
state.player.stats.stamina.value = 100;
changeStat("stamina", -0.5 + bonus, state);
} }

if (state.player.stats.stamina.value < 0) {
state.player.stats.stamina.value = 0;
}

return true; return true;
}, },
delay: 500, delay: 500,
@@ -175,8 +166,7 @@ stories.push({
id: "stomach-churns", id: "stomach-churns",
func: state => { func: state => {
if (Math.random() > 0.6) { if (Math.random() > 0.6) {
state.player.stats.stamina.value -= 25;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -25, state);
print(["The crux's stomach clenches around you, smothering you in the beast's slimy embrace."]); print(["The crux's stomach clenches around you, smothering you in the beast's slimy embrace."]);
playSfx("sfx/stomach-churn.ogg"); playSfx("sfx/stomach-churn.ogg");
} }
@@ -202,8 +192,7 @@ stories.push({
name: "Rub", name: "Rub",
desc: "Knead on the muscular folds that surround your tasty little body", desc: "Knead on the muscular folds that surround your tasty little body",
execute: (room, state) => { execute: (room, state) => {
state.player.stats.stamina.value -= 15;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -15, state);
print(["You rub all over your prison's walls. Fen's stomach gurgles in response."]); print(["You rub all over your prison's walls. Fen's stomach gurgles in response."]);
} }
}, },
@@ -235,16 +224,14 @@ stories.push({
let stamina = state.player.stats.stamina.value; let stamina = state.player.stats.stamina.value;
let escape; let escape;
if (Math.random() > stamina/100) { if (Math.random() > stamina/100) {
stamina -= 50;
changeStat("stamina", -50, state);
print(["Fen's stomach clenches and ripples, smothering your face in wet flesh and keeping you nice and trapped."]); print(["Fen's stomach clenches and ripples, smothering your face in wet flesh and keeping you nice and trapped."]);
playSfx("sfx/stomach-to-intestines-fail.ogg"); playSfx("sfx/stomach-to-intestines-fail.ogg");
escape = false; escape = false;
} else { } else {
stamina -= 25;
changeStat("stamina", -25, state);
escape = true; escape = true;
} }
stamina = Math.max(stamina, 0)
state.player.stats.stamina.value = stamina;
return escape; return escape;
} }
], ],
@@ -274,8 +261,7 @@ stories.push({
func: state => { func: state => {
if (Math.random() > 0.6) { if (Math.random() > 0.6) {
if (state.player.stats.stamina.value > 50) { if (state.player.stats.stamina.value > 50) {
state.player.stats.stamina.value -= 25;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -25, state);
print(["Your prison's walls ripple and grind, shoving you against the valve leading to the crux's boiling stomach - but you manage to resist the powerful pull."]); print(["Your prison's walls ripple and grind, shoving you against the valve leading to the crux's boiling stomach - but you manage to resist the powerful pull."]);
playSfx("sfx/intestines-churn-stay.ogg"); playSfx("sfx/intestines-churn-stay.ogg");
} else { } else {
@@ -340,8 +326,7 @@ stories.push({
name: "Rub", name: "Rub",
desc: "Knead on the muscular folds that surround your tasty little body", desc: "Knead on the muscular folds that surround your tasty little body",
execute: (room, state) => { execute: (room, state) => {
state.player.stats.stamina.value -= 20;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -20, state);
print(["You rub all over your prison's walls. Fen's guts barely move."]); print(["You rub all over your prison's walls. Fen's guts barely move."]);
} }
}, },
@@ -375,17 +360,17 @@ stories.push({
id: "bowels-churns", id: "bowels-churns",
func: state => { func: state => {
if (state.player.stats.stamina.value > 50) { if (state.player.stats.stamina.value > 50) {
state.player.stats.stamina.value -= 25;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -25, state);
print(["Fen's bowels clench and churn, grinding you into their musky walls."]); print(["Fen's bowels clench and churn, grinding you into their musky walls."]);
playSfx("sfx/bowels-churn-safe.ogg"); playSfx("sfx/bowels-churn-safe.ogg");
} else { } else {
changeStat("stamina", -100, state);
startTimer({ startTimer({
id: "digestion", id: "digestion",
func: state => { func: state => {
let bonus = state.player.flags.submission ? 10 : 1; let bonus = state.player.flags.submission ? 10 : 1;


state.player.stats.health.value -= 1;
changeStat("health", -1, state);
return 500 / bonus; return 500 / bonus;
}, },
delay: 1000, delay: 1000,
@@ -450,8 +435,7 @@ stories.push({
name: "Rub", name: "Rub",
desc: "Knead on the muscular folds that surround your tasty little body", desc: "Knead on the muscular folds that surround your tasty little body",
execute: (room, state) => { execute: (room, state) => {
state.player.stats.stamina.value -= 50;
state.player.stats.stamina.value = Math.max(0, state.player.stats.stamina.value);
changeStat("stamina", -25, state);
print(["You rub all over your prison's walls. Fen's bowels clench in on you as he rurrs with pleasure."]); print(["You rub all over your prison's walls. Fen's bowels clench in on you as he rurrs with pleasure."]);
} }
}, },


Loading…
Cancel
Save