From cb7a641ac25d607acede6c0c2b75a81ab07b5c93 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 10 Mar 2018 09:03:32 -0500 Subject: [PATCH] Basic combat and eating --- combat.js | 27 +++++++++++++++++++++++++++ dialog.js | 21 +++++++++++++++++++++ feast.html | 1 + feast.js | 35 +++++++++++++++++++++++++++++++++++ vore.js | 4 ++++ world.js | 54 +++++++++++++++++++++++++++++++++++++++--------------- 6 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 combat.js diff --git a/combat.js b/combat.js new file mode 100644 index 0000000..8fefdf7 --- /dev/null +++ b/combat.js @@ -0,0 +1,27 @@ +"use strict"; + +function attack(attacker, defender, baseDamage) { + let damage = Math.round((Math.random() * 0.5 - 0.25 + 1) * baseDamage); + defender.health -= damage; + return damage; +} + +function punchAttack(attacker) { + return { + name: "Punch", + desc: "Punch a nerd", + attack: function(defender) { + return "You punch the " + defender.description() + " for " + attack(attacker, defender, attacker.str) + " damage"; + } + }; +} + +function flankAttack(attacker) { + return { + name: "Flank", + desc: "Be sneaky", + attack: function(defender) { + return "You run around the " + defender.description() + " and attack for " + attack(attacker, defender, attacker.dex) + " damage"; + } + }; +} diff --git a/dialog.js b/dialog.js index 6459da0..38712fb 100644 --- a/dialog.js +++ b/dialog.js @@ -60,3 +60,24 @@ function PhoneCall() { nodeCrash.hooks.push(function() { potato() }); } } + +function FallenFoe(foe) { + DialogNode.call(this); + + this.text = "What do you want to do with your enemy?"; + + { + let nodeEat = new DialogNode(); + this.addChoice("Devour!",nodeEat); + nodeEat.text = "You grab your helpless prey and force them down your gullet."; + nodeEat.hooks.push(function() { + player.stomach.feed(foe); + }) + } + + { + let nodeSpare = new DialogNode(); + this.addChoice("Spare",nodeSpare); + nodeSpare.text = "You decide to leave your foe uneaten."; + } +} diff --git a/feast.html b/feast.html index ccecf2e..930e758 100644 --- a/feast.html +++ b/feast.html @@ -5,6 +5,7 @@ Feast + diff --git a/feast.js b/feast.js index a911d57..63eab42 100644 --- a/feast.js +++ b/feast.js @@ -11,6 +11,10 @@ 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); } @@ -54,7 +58,21 @@ function updateExplore() { } function updateCombat() { + let list = document.getElementById("combat"); + + while(list.firstChild) { + list.removeChild(list.firstChild); + } + for (let i = 0; i < 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) }); + li.appendChild(button); + list.appendChild(li); + } } function updateDialog() { @@ -142,6 +160,8 @@ function moveTo(room,desc="You go places lol") { }); update([desc,newline]); + + currentRoom.visit(); } window.addEventListener('load', function(event) { @@ -165,6 +185,21 @@ function update(lines=[]) { updateDisplay(); } +function startCombat(opponent) { + mode = "combat"; + currentFoe = opponent; + update(["Oh shit it's a " + opponent.description()]); +} + +function attackClicked(index) { + update([attacks[index].attack(currentFoe)]); + + if (currentFoe.health <= 0) { + update(["The " + currentFoe.description() + " falls to the ground!"]); + startDialog(new FallenFoe(currentFoe)); + } +} + function startDialog(dialog) { mode = "dialog"; currentDialog = dialog; diff --git a/vore.js b/vore.js index dd1f86b..8100791 100644 --- a/vore.js +++ b/vore.js @@ -9,6 +9,10 @@ function Creature(name = "Creature") { this.mass = 80; this.bowels = new Bowels(); this.stomach = new Stomach(this.bowels); + + this.str = 10; + this.dex = 10; + this.con = 10; } function Player(name = "Player") { diff --git a/world.js b/world.js index a03b542..0105646 100644 --- a/world.js +++ b/world.js @@ -34,7 +34,7 @@ let locationsSrc = [ ], "objs": [ Bed - ] + ], }, { "name": "Bathroom", @@ -88,6 +88,11 @@ let locationsSrc = [ "name": "Crossroads", "dir": SOUTH, "desc": "You walk south" + }, + { + "name": "DANGER ZONE", + "dir": NORTH, + "desc": "You walk into the DANGER ZONE" } ], "objs": [ @@ -108,9 +113,6 @@ let locationsSrc = [ "dir": NORTH, "desc": "You step into the bar." } - ], - "objs": [ - ] }, { @@ -122,9 +124,6 @@ let locationsSrc = [ "dir": SOUTH, "desc": "You step out of the bar" } - ], - "objs": [ - ] }, { @@ -141,9 +140,6 @@ let locationsSrc = [ "dir": SOUTH, "desc": "You walk south" } - ], - "objs": [ - ] }, { @@ -155,9 +151,22 @@ let locationsSrc = [ "dir": NORTH, "desc": "You walk to the crossroads" } + ] + }, + { + "name": "DANGER ZONE", + "desc": "THE DANGER ZONE", + "conn": [ + { + "name": "North Street", + "dir": SOUTH, + "desc": "You walk out of the DANGER ZONE" + } ], - "objs": [ - + "hooks": [ + function() { + startCombat(new Anthro()); + } ] } ]; @@ -168,6 +177,13 @@ function Location(name="Nowhere",desc="Nada") { this.exits = [null,null,null,null,null,null,null,null]; this.exitDescs = [null,null,null,null,null,null,null,null]; this.objects = []; + this.hooks = []; + + this.visit = function() { + this.hooks.forEach(function (x) { + x(); + }); + }; } function opposite(direction) { @@ -193,9 +209,17 @@ function createWorld() { let src = locationsSrc[i]; let location = new Location(src.name,src.desc); locations[src.name] = location; - src.objs.forEach(function (obj) { - location.objects.push(new obj()); - }); + if (src.objs != undefined) { + src.objs.forEach(function (obj) { + location.objects.push(new obj()); + }); + } + if (src.hooks != undefined) { + src.hooks.forEach(function (hook) { + location.hooks.push(hook); + }); + } + } for (let i = 0; i < locationsSrc.length; i++) {