Browse Source

Added some theming based on mode. Enemies can fight back

tags/v0.2.8
Fen Dweller 7 years ago
parent
commit
290c99ff58
4 changed files with 59 additions and 11 deletions
  1. +6
    -0
      combat.js
  2. +12
    -0
      feast.css
  3. +33
    -10
      feast.js
  4. +8
    -1
      vore.js

+ 6
- 0
combat.js View File

@@ -12,6 +12,9 @@ function punchAttack(attacker) {
desc: "Punch a nerd", desc: "Punch a nerd",
attack: function(defender) { attack: function(defender) {
return "You punch the " + defender.description() + " for " + attack(attacker, defender, attacker.str) + " damage"; return "You punch the " + defender.description() + " for " + attack(attacker, defender, attacker.str) + " damage";
},
attackPlayer: function(defender) {
return "The " + attacker.description() + " punches you for " + attack(attacker, defender, attacker.str) + " damage";
} }
}; };
} }
@@ -22,6 +25,9 @@ function flankAttack(attacker) {
desc: "Be sneaky", desc: "Be sneaky",
attack: function(defender) { attack: function(defender) {
return "You run around the " + defender.description() + " and attack for " + attack(attacker, defender, attacker.dex) + " damage"; return "You run around the " + defender.description() + " and attack for " + attack(attacker, defender, attacker.dex) + " damage";
},
attackPlayer: function(defender) {
return "The " + attacker.description() + " runs past you, then turns and hits you for " + attack(attacker, defender, attacker.str) + " damage";
} }
}; };
} }

+ 12
- 0
feast.css View File

@@ -6,6 +6,18 @@ body {
font-family: sans-serif; font-family: sans-serif;
} }


body.combat {
background: #311;
}

body.explore {
background: #111;
}

body.eaten {
background: #500;
}

button { button {
background: #222; background: #222;
color: #eee; color: #eee;


+ 33
- 10
feast.js View File

@@ -11,10 +11,6 @@ let newline = " ";


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


let attacks = [];

attacks.push(new punchAttack(player));
attacks.push(new flankAttack(player));
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);
} }
@@ -64,13 +60,13 @@ function updateCombat() {
list.removeChild(list.firstChild); list.removeChild(list.firstChild);
} }


for (let i = 0; i < attacks.length; i++) {
for (let i = 0; i < player.attacks.length; i++) {
let li = document.createElement("li"); let li = document.createElement("li");
let button = document.createElement("button"); let button = document.createElement("button");
button.classList.add("combat-button"); button.classList.add("combat-button");
button.innerHTML = attacks[i].name;
button.addEventListener("click", function() { attackClicked(i) });
button.addEventListener("mouseover", function() { attackHovered(i) });
button.innerHTML = player.attacks[i].name;
button.addEventListener("click", function() { attackClicked(i); } );
button.addEventListener("mouseover", function() { attackHovered(i); } );
li.appendChild(button); li.appendChild(button);
list.appendChild(li); list.appendChild(li);
} }
@@ -186,6 +182,23 @@ function update(lines=[]) {
updateDisplay(); updateDisplay();
} }


function changeMode(mode) {
this.mode = mode;
let body = document.querySelector("body");
body.className = "";
switch(mode) {
case "explore":
case "dialog":
body.classList.add("explore");
break;
case "combat":
body.classList.add("combat");
break;
case "eaten":
body.classList.add("eaten");
break;
}
}
function startCombat(opponent) { function startCombat(opponent) {
mode = "combat"; mode = "combat";
currentFoe = opponent; currentFoe = opponent;
@@ -193,17 +206,27 @@ function startCombat(opponent) {
} }


function attackClicked(index) { function attackClicked(index) {
update([attacks[index].attack(currentFoe)]);
update([player.attacks[index].attack(currentFoe)]);


if (currentFoe.health <= 0) { if (currentFoe.health <= 0) {
update(["The " + currentFoe.description() + " falls to the ground!"]); update(["The " + currentFoe.description() + " falls to the ground!"]);
startDialog(new FallenFoe(currentFoe)); startDialog(new FallenFoe(currentFoe));
} else {
let attack = pick(currentFoe.attacks);

update([attack.attackPlayer(player)]);

if (player.health <= 0) {
update(["You fall to the ground..."]);
changeMode("eaten");
}
} }
} }


function attackHovered(index) { function attackHovered(index) {
document.getElementById("combat-desc").innerHTML = attacks[index].desc;
document.getElementById("combat-desc").innerHTML = player.attacks[index].desc;
} }

function startDialog(dialog) { function startDialog(dialog) {
mode = "dialog"; mode = "dialog";
currentDialog = dialog; currentDialog = dialog;


+ 8
- 1
vore.js View File

@@ -10,6 +10,7 @@ function Creature(name = "Creature") {
this.bowels = new Bowels(); this.bowels = new Bowels();
this.stomach = new Stomach(this.bowels); this.stomach = new Stomach(this.bowels);
this.butt = new Butt(this.bowels,this.stomach); this.butt = new Butt(this.bowels,this.stomach);
this.attacks = [];


this.str = 10; this.str = 10;
this.dex = 10; this.dex = 10;
@@ -21,7 +22,10 @@ function Player(name = "Player") {


this.fullness = function() { this.fullness = function() {
return this.stomach.fullness(); return this.stomach.fullness();
}
};

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


function Anthro() { function Anthro() {
@@ -39,6 +43,9 @@ function Anthro() {
this.description = function() { this.description = function() {
return this.build + " " + this.species; return this.build + " " + this.species;
}; };

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


function Micro() { function Micro() {


Loading…
Cancel
Save