Parcourir la source

Added some theming based on mode. Enemies can fight back

tags/v0.2.8
Fen Dweller il y a 7 ans
Parent
révision
290c99ff58
4 fichiers modifiés avec 59 ajouts et 11 suppressions
  1. +6
    -0
      combat.js
  2. +12
    -0
      feast.css
  3. +33
    -10
      feast.js
  4. +8
    -1
      vore.js

+ 6
- 0
combat.js Voir le fichier

@@ -12,6 +12,9 @@ function punchAttack(attacker) {
desc: "Punch a nerd",
attack: function(defender) {
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",
attack: function(defender) {
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 Voir le fichier

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

body.combat {
background: #311;
}

body.explore {
background: #111;
}

body.eaten {
background: #500;
}

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


+ 33
- 10
feast.js Voir le fichier

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

let player = new Player();

let attacks = [];

attacks.push(new punchAttack(player));
attacks.push(new flankAttack(player));
function round(number, digits) {
return Math.round(number * Math.pow(10,digits)) / Math.pow(10,digits);
}
@@ -64,13 +60,13 @@ function updateCombat() {
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 button = document.createElement("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);
list.appendChild(li);
}
@@ -186,6 +182,23 @@ function update(lines=[]) {
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) {
mode = "combat";
currentFoe = opponent;
@@ -193,17 +206,27 @@ function startCombat(opponent) {
}

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

if (currentFoe.health <= 0) {
update(["The " + currentFoe.description() + " falls to the ground!"]);
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) {
document.getElementById("combat-desc").innerHTML = attacks[index].desc;
document.getElementById("combat-desc").innerHTML = player.attacks[index].desc;
}

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


+ 8
- 1
vore.js Voir le fichier

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

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

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

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

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

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

function Micro() {


Chargement…
Annuler
Enregistrer