| @@ -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"; | |||||
| } | |||||
| }; | |||||
| } | |||||
| @@ -60,3 +60,24 @@ function PhoneCall() { | |||||
| nodeCrash.hooks.push(function() { potato() }); | 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."; | |||||
| } | |||||
| } | |||||
| @@ -5,6 +5,7 @@ | |||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <title>Feast</title> | <title>Feast</title> | ||||
| <link rel="stylesheet" href="feast.css"> | <link rel="stylesheet" href="feast.css"> | ||||
| <script src="combat.js"></script> | |||||
| <script src="objects.js"></script> | <script src="objects.js"></script> | ||||
| <script src="dialog.js"></script> | <script src="dialog.js"></script> | ||||
| <script src="world.js"></script> | <script src="world.js"></script> | ||||
| @@ -11,6 +11,10 @@ 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); | ||||
| } | } | ||||
| @@ -54,7 +58,21 @@ function updateExplore() { | |||||
| } | } | ||||
| function updateCombat() { | 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() { | function updateDialog() { | ||||
| @@ -142,6 +160,8 @@ function moveTo(room,desc="You go places lol") { | |||||
| }); | }); | ||||
| update([desc,newline]); | update([desc,newline]); | ||||
| currentRoom.visit(); | |||||
| } | } | ||||
| window.addEventListener('load', function(event) { | window.addEventListener('load', function(event) { | ||||
| @@ -165,6 +185,21 @@ function update(lines=[]) { | |||||
| updateDisplay(); | 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) { | function startDialog(dialog) { | ||||
| mode = "dialog"; | mode = "dialog"; | ||||
| currentDialog = dialog; | currentDialog = dialog; | ||||
| @@ -9,6 +9,10 @@ function Creature(name = "Creature") { | |||||
| this.mass = 80; | this.mass = 80; | ||||
| this.bowels = new Bowels(); | this.bowels = new Bowels(); | ||||
| this.stomach = new Stomach(this.bowels); | this.stomach = new Stomach(this.bowels); | ||||
| this.str = 10; | |||||
| this.dex = 10; | |||||
| this.con = 10; | |||||
| } | } | ||||
| function Player(name = "Player") { | function Player(name = "Player") { | ||||
| @@ -34,7 +34,7 @@ let locationsSrc = [ | |||||
| ], | ], | ||||
| "objs": [ | "objs": [ | ||||
| Bed | Bed | ||||
| ] | |||||
| ], | |||||
| }, | }, | ||||
| { | { | ||||
| "name": "Bathroom", | "name": "Bathroom", | ||||
| @@ -88,6 +88,11 @@ let locationsSrc = [ | |||||
| "name": "Crossroads", | "name": "Crossroads", | ||||
| "dir": SOUTH, | "dir": SOUTH, | ||||
| "desc": "You walk south" | "desc": "You walk south" | ||||
| }, | |||||
| { | |||||
| "name": "DANGER ZONE", | |||||
| "dir": NORTH, | |||||
| "desc": "You walk into the DANGER ZONE" | |||||
| } | } | ||||
| ], | ], | ||||
| "objs": [ | "objs": [ | ||||
| @@ -108,9 +113,6 @@ let locationsSrc = [ | |||||
| "dir": NORTH, | "dir": NORTH, | ||||
| "desc": "You step into the bar." | "desc": "You step into the bar." | ||||
| } | } | ||||
| ], | |||||
| "objs": [ | |||||
| ] | ] | ||||
| }, | }, | ||||
| { | { | ||||
| @@ -122,9 +124,6 @@ let locationsSrc = [ | |||||
| "dir": SOUTH, | "dir": SOUTH, | ||||
| "desc": "You step out of the bar" | "desc": "You step out of the bar" | ||||
| } | } | ||||
| ], | |||||
| "objs": [ | |||||
| ] | ] | ||||
| }, | }, | ||||
| { | { | ||||
| @@ -141,9 +140,6 @@ let locationsSrc = [ | |||||
| "dir": SOUTH, | "dir": SOUTH, | ||||
| "desc": "You walk south" | "desc": "You walk south" | ||||
| } | } | ||||
| ], | |||||
| "objs": [ | |||||
| ] | ] | ||||
| }, | }, | ||||
| { | { | ||||
| @@ -155,9 +151,22 @@ let locationsSrc = [ | |||||
| "dir": NORTH, | "dir": NORTH, | ||||
| "desc": "You walk to the crossroads" | "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.exits = [null,null,null,null,null,null,null,null]; | ||||
| this.exitDescs = [null,null,null,null,null,null,null,null]; | this.exitDescs = [null,null,null,null,null,null,null,null]; | ||||
| this.objects = []; | this.objects = []; | ||||
| this.hooks = []; | |||||
| this.visit = function() { | |||||
| this.hooks.forEach(function (x) { | |||||
| x(); | |||||
| }); | |||||
| }; | |||||
| } | } | ||||
| function opposite(direction) { | function opposite(direction) { | ||||
| @@ -193,9 +209,17 @@ function createWorld() { | |||||
| let src = locationsSrc[i]; | let src = locationsSrc[i]; | ||||
| let location = new Location(src.name,src.desc); | let location = new Location(src.name,src.desc); | ||||
| locations[src.name] = location; | 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++) { | for (let i = 0; i < locationsSrc.length; i++) { | ||||