getting draft mode buttons and selection menu

This commit is contained in:
landgreen
2019-12-28 04:58:36 -08:00
parent 8115126e08
commit 21bc7046c3
8 changed files with 287 additions and 195 deletions

View File

@@ -39,6 +39,7 @@
<div id="health-bg"></div> <div id="health-bg"></div>
<div id="health"></div> <div id="health"></div>
<div id="dmg"></div> <div id="dmg"></div>
<div id="choose-background"></div>
<!-- guns --> <!-- guns -->
<!-- <audio id="snare2" src="sounds\guns\snare2.ogg" preload="auto"></audio> <!-- <audio id="snare2" src="sounds\guns\snare2.ogg" preload="auto"></audio>
@@ -76,25 +77,18 @@
<canvas id="canvas"></canvas> <canvas id="canvas"></canvas>
<!-- ********** intro page *********************************************** <!-- ********** intro page ***********************************************
******************************************************************************* --> ******************************************************************************* -->
<div id="choose-grid"></div>
<!-- <div id="build-details">
<div class="build-grid-module"></div>
<details>
<summary>build</summary>
<div id="details-div">
</div>
</details>
</div> -->
<!-- <div id="choose-grid"></div> -->
<div id="build-grid"></div> <div id="build-grid"></div>
<!-- <button type="button" id="build-button">challenge run</button> -->
<svg class="SVG-button" id="build-button" width="110" height="40"> <svg class="SVG-button" id="build-button" width="110" height="40">
<g stroke='none' fill='#333' stroke-width="2" font-size="28px" font-family="Arial, sans-serif"> <g stroke='none' fill='#333' stroke-width="2" font-size="28px" font-family="Arial, sans-serif">
<text x="10" y="30">custom</text> <text x="10" y="30">custom</text>
</g> </g>
</svg> </svg>
<svg class="SVG-button" id="draft-button" width="80" height="40">
<g stroke='none' fill='#333' stroke-width="2" font-size="28px" font-family="Arial, sans-serif">
<text x="10" y="30">draft</text>
</g>
</svg>
<div id="settings"> <div id="settings">
<details> <details>
<summary>settings</summary> <summary>settings</summary>

View File

@@ -250,11 +250,24 @@ const b = {
} }
}, },
], ],
giveMod(i) { giveMod(index = 'random') {
b.mods[i].effect(); //give specific mod if (index === 'random') {
b.modCount++ let options = [];
b.mods[i].have = true for (let i = 0; i < b.mods.length; i++) {
game.updateModHUD(); if (!b.mods[i].have) options.push(i);
}
// give a random mod from the mods I don't have
if (options.length > 0) {
let newMod = options[Math.floor(Math.random() * options.length)]
b.giveMod(newMod)
}
} else {
b.mods[index].effect(); //give specific mod
b.modCount++
b.mods[index].have = true
game.updateModHUD();
}
}, },
activeGun: null, //current gun in use by player activeGun: null, //current gun in use by player
inventoryGun: 0, inventoryGun: 0,
@@ -812,7 +825,7 @@ const b = {
have: false, have: false,
isStarterGun: true, isStarterGun: true,
fire() { fire() {
mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 25 : 18) * b.modFireRate); // cool down mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 35 : 20) * b.modFireRate); // cool down
b.muzzleFlash(20); b.muzzleFlash(20);
// mobs.alert(450); // mobs.alert(450);
const SPEED = mech.crouch ? 55 : 35 const SPEED = mech.crouch ? 55 : 35
@@ -1665,7 +1678,7 @@ const b = {
}, },
{ {
name: "laser", //14 name: "laser", //14
description: "emit a beam of collimated coherent <strong>light</strong><br>uses <strong class='color-f'>energy</strong> instead of ammunition", description: "emit a beam of collimated coherent <strong>light</strong><br>drains <strong class='color-f'>energy</strong> instead of ammunition",
ammo: 0, ammo: 0,
ammoPack: Infinity, ammoPack: Infinity,
have: false, have: false,
@@ -1784,7 +1797,7 @@ const b = {
x: best.x, x: best.x,
y: best.y y: best.y
}; };
laserHitMob(0.75); laserHitMob(0.8);
//2nd reflection beam //2nd reflection beam
//ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body //ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
@@ -1797,7 +1810,19 @@ const b = {
x: best.x, x: best.x,
y: best.y y: best.y
}; };
laserHitMob(0.5); laserHitMob(0.63);
reflection();
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
path[path.length - 1] = {
x: best.x,
y: best.y
};
laserHitMob(0.5);
}
} }
} }
} }
@@ -1814,7 +1839,7 @@ const b = {
ctx.moveTo(path[i - 1].x, path[i - 1].y); ctx.moveTo(path[i - 1].x, path[i - 1].y);
ctx.lineTo(path[i].x, path[i].y); ctx.lineTo(path[i].x, path[i].y);
ctx.stroke(); ctx.stroke();
ctx.globalAlpha *= 0.5; //reflections are less intense ctx.globalAlpha *= 0.65; //reflections are less intense
// ctx.globalAlpha -= 0.1; //reflections are less intense // ctx.globalAlpha -= 0.1; //reflections are less intense
} }
ctx.setLineDash([0, 0]); ctx.setLineDash([0, 0]);

View File

@@ -83,6 +83,7 @@ const game = {
buttonCD: 0, buttonCD: 0,
isBodyDamage: true, isBodyDamage: true,
isEasyMode: false, isEasyMode: false,
isDraftMode: false,
difficulty: null, difficulty: null,
// dropFPS(cap = 40, time = 15) { // dropFPS(cap = 40, time = 15) {
// game.fpsCap = cap // game.fpsCap = cap
@@ -308,7 +309,6 @@ const game = {
} else if (keys[53]) { // 5 } else if (keys[53]) { // 5
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod"); powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
} else if (keys[54]) { // 6 spawn mob } else if (keys[54]) { // 6 spawn mob
const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)]; const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)];
spawn.allowShields = false; spawn.allowShields = false;
spawn[pick](game.mouseInGame.x, game.mouseInGame.y); spawn[pick](game.mouseInGame.x, game.mouseInGame.y);
@@ -321,19 +321,16 @@ const game = {
body[index].classType = "body"; body[index].classType = "body";
World.add(engine.world, body[index]); //add to world World.add(engine.world, body[index]); //add to world
} else if (keys[70]) { //cycle fields with F } else if (keys[70]) { //cycle fields with F
if (mech.fieldMode === mech.fieldUpgrades.length - 1) { const mode = (mech.fieldMode === mech.fieldUpgrades.length - 1) ? 0 : mech.fieldMode + 1
mech.fieldUpgrades[0].effect() mech.setField(mode)
} else {
mech.fieldUpgrades[mech.fieldMode + 1].effect()
}
} else if (keys[71]) { // give all guns with G } else if (keys[71]) { // give all guns with G
// b.giveGuns("all", 1000) // b.giveGuns("all", 1000)
powerUps.gun.effect() powerUps.gun.effect()
} else if (keys[72]) { // heal with H } else if (keys[72]) { // heal with H
mech.addHealth(Infinity) mech.addHealth(Infinity)
mech.fieldMeter = mech.fieldEnergyMax; mech.fieldMeter = mech.fieldEnergyMax;
} else if (keys[89]) { //add all mods with y } else if (keys[89]) { //add mods with y
powerUps.mod.effect() b.giveMod()
} else if (keys[82]) { // teleport to mouse with R } else if (keys[82]) { // teleport to mouse with R
Matter.Body.setPosition(player, game.mouseInGame); Matter.Body.setPosition(player, game.mouseInGame);
Matter.Body.setVelocity(player, { Matter.Body.setVelocity(player, {
@@ -456,9 +453,8 @@ const game = {
b.activeGun = null; b.activeGun = null;
b.setModDefaults(); //remove mods b.setModDefaults(); //remove mods
game.updateModHUD(); game.updateModHUD();
mech.fieldEnergyMax = 1
mech.maxHealth = 1 mech.maxHealth = 1
mech.fieldUpgrades[0].effect(); //set to default field mech.fieldEnergyMax = 1
game.paused = false; game.paused = false;
build.isShowingBuilds = false build.isShowingBuilds = false
engine.timing.timeScale = 1; engine.timing.timeScale = 1;
@@ -490,7 +486,11 @@ const game = {
document.getElementById("text-log").style.opacity = 0; document.getElementById("text-log").style.opacity = 0;
document.getElementById("fade-out").style.opacity = 0; document.getElementById("fade-out").style.opacity = 0;
document.title = "n-gon"; document.title = "n-gon";
if (!mech.fieldMode) mech.fieldUpgrades[0].effect(); //reset to starting field? or let them keep the field //set to default field
mech.fieldMode = 0;
game.replaceTextLog = true;
game.makeTextLog(`${game.SVGrightMouse}<strong style='font-size:30px;'> ${mech.fieldUpgrades[mech.fieldMode].name}</strong><br><span class='faded'></span><br>${mech.fieldUpgrades[mech.fieldMode].description}`, 600);
mech.setField(mech.fieldMode)
}, },
firstRun: true, firstRun: true,
splashReturn() { splashReturn() {
@@ -499,8 +499,10 @@ const game = {
document.getElementById("splash").onclick = function () { document.getElementById("splash").onclick = function () {
game.startGame(); game.startGame();
}; };
document.getElementById("choose-grid").style.display = "none"
document.getElementById("controls").style.display = "inline"; document.getElementById("controls").style.display = "inline";
document.getElementById("build-button").style.display = "inline" document.getElementById("build-button").style.display = "inline"
document.getElementById("draft-button").style.display = "inline"
isShowingBuilds = false isShowingBuilds = false
document.getElementById("settings").style.display = "inline"; document.getElementById("settings").style.display = "inline";
document.getElementById("splash").style.display = "inline"; document.getElementById("splash").style.display = "inline";
@@ -511,13 +513,15 @@ const game = {
fpsInterval: 0, //set in startGame fpsInterval: 0, //set in startGame
then: null, then: null,
startGame() { startGame() {
level.isBuildRun = false; //can get set back to true in buld.startBuildRun() level.isBuildRun = false; //can get set back to true in build.startBuildRun()
game.onTitlePage = false; game.onTitlePage = false;
document.body.style.overflow = "hidden" document.body.style.overflow = "hidden"
document.getElementById("choose-grid").style.display = "none"
document.getElementById("build-grid").style.display = "none" document.getElementById("build-grid").style.display = "none"
document.getElementById("controls").style.display = "none"; document.getElementById("controls").style.display = "none";
document.getElementById("settings").style.display = "none"; document.getElementById("settings").style.display = "none";
document.getElementById("build-button").style.display = "none"; document.getElementById("build-button").style.display = "none";
document.getElementById("draft-button").style.display = "none"
document.getElementById("splash").onclick = null; //removes the onclick effect so the function only runs once document.getElementById("splash").onclick = null; //removes the onclick effect so the function only runs once
document.getElementById("splash").style.display = "none"; //hides the element that spawned the function document.getElementById("splash").style.display = "none"; //hides the element that spawned the function
document.getElementById("dmg").style.display = "inline"; document.getElementById("dmg").style.display = "inline";

View File

@@ -82,26 +82,6 @@ game mechanics
*/ */
//find what mods I don't have
function doNotHave(who) {
let options = [];
for (let i = 0; i < who.length; i++) {
if (!who[i].have) options.push(i);
}
if (options.length > 0) return options[Math.floor(Math.random() * options.length)]
}
//give a random mod from the mods I don't have
let newMod = doNotHave(b.mods)
let t = ""
for (let i = 0; i < 3; i++) {
t += `<div class="choose-grid-module" onclick="build.choosePowerUp(this,${i},'mod')"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name}</div> ${b.mods[i].description}</div>`
}
// document.getElementById("choose-grid").innerHTML = t
//collision groups //collision groups
// cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield // cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield
const cat = { const cat = {
@@ -115,6 +95,13 @@ const cat = {
mobShield: 0x10000000, mobShield: 0x10000000,
} }
document.getElementById("draft-button").addEventListener("click", () => {
game.isDraftMode = true;
game.startGame();
});
//build build grid display //build build grid display
const build = { const build = {
isShowingBuilds: false, isShowingBuilds: false,
@@ -140,7 +127,6 @@ const build = {
} }
if (build.list.length < 5) { //add to build array if (build.list.length < 5) { //add to build array
// who.style.border = "2px solid #333"
who.style.backgroundColor = "#919ba8" //"#868f9a" who.style.backgroundColor = "#919ba8" //"#868f9a"
build.list[build.list.length] = { build.list[build.list.length] = {
who: who, who: who,
@@ -151,7 +137,7 @@ const build = {
}, },
startBuildRun() { startBuildRun() {
spawn.setSpawnList(); spawn.setSpawnList();
spawn.setSpawnList(); spawn.setSpawnList(); //gives random mobs, not starter
game.startGame(); game.startGame();
game.difficulty = 6; game.difficulty = 6;
level.isBuildRun = true; level.isBuildRun = true;
@@ -169,6 +155,7 @@ const build = {
document.getElementById("build-button").addEventListener("click", () => { document.getElementById("build-button").addEventListener("click", () => {
document.getElementById("build-button").style.display = "none"; document.getElementById("build-button").style.display = "none";
document.getElementById("draft-button").style.display = "none";
const el = document.getElementById("build-grid") const el = document.getElementById("build-grid")
if (build.isShowingBuilds) { if (build.isShowingBuilds) {
el.style.display = "none" el.style.display = "none"

View File

@@ -70,7 +70,7 @@ const level = {
level.exit.x = 3500; level.exit.x = 3500;
level.exit.y = -870; level.exit.y = -870;
level.testingMap.addZone(level.exit.x, level.exit.y, 100, 30, "nextLevel"); level.addZone(level.exit.x, level.exit.y, 100, 30, "nextLevel");
document.body.style.backgroundColor = "#dcdcde"; document.body.style.backgroundColor = "#dcdcde";
@@ -105,10 +105,10 @@ const level = {
// spawn.lineBoss(-500, -600, spawn.allowedBossList[Math.floor(Math.random() * spawn.allowedBossList.length)]); // spawn.lineBoss(-500, -600, spawn.allowedBossList[Math.floor(Math.random() * spawn.allowedBossList.length)]);
// spawn.bodyRect(-135, -50, 50, 50); // spawn.bodyRect(-135, -50, 50, 50);
// spawn.bodyRect(-140, -100, 50, 50); // spawn.bodyRect(-140, -100, 50, 50);
powerUps.spawn(420, -400, "field", false); powerUps.spawn(420, -400, "mod", false);
powerUps.spawn(420, -400, "field", false); // powerUps.spawn(420, -400, "field", false);
powerUps.spawn(420, -400, "field", false); // powerUps.spawn(420, -400, "field", false);
powerUps.spawn(420, -400, "field", false); // powerUps.spawn(420, -400, "field", false);
// powerUps.spawn(450, -400, "mod", false, 6); // powerUps.spawn(450, -400, "mod", false, 6);
// powerUps.spawn(450, -400, "mod", false); // powerUps.spawn(450, -400, "mod", false);
// spawn.bodyRect(-45, -100, 40, 50); // spawn.bodyRect(-45, -100, 40, 50);

View File

@@ -1033,21 +1033,17 @@ const mech = {
} }
}, },
hold() {}, hold() {},
fieldText() { setField(index) {
game.replaceTextLog = true; mech.fieldMode = index;
game.makeTextLog(`${game.SVGrightMouse}<strong style='font-size:30px;'> ${mech.fieldUpgrades[mech.fieldMode].name}</strong><br><span class='faded'></span><br>${mech.fieldUpgrades[mech.fieldMode].description}`, 1000); document.getElementById("field").innerHTML = mech.fieldUpgrades[index].name
game.replaceTextLog = false; mech.setHoldDefaults();
document.getElementById("field").innerHTML = mech.fieldUpgrades[mech.fieldMode].name //add field mech.fieldUpgrades[index].effect();
}, },
fieldUpgrades: [{ fieldUpgrades: [{
name: "field emitter", name: "field emitter",
description: "use <strong class='color-f'>energy</strong> to <strong>shield</strong> yourself from <strong class='color-d'>damage</strong><br>lets you <strong>pick up</strong> and <strong>throw</strong> objects", description: "use <strong class='color-f'>energy</strong> to <strong>shield</strong> yourself from <strong class='color-d'>damage</strong><br>lets you <strong>pick up</strong> and <strong>throw</strong> objects",
effect: () => { effect: () => {
mech.fieldMode = 0;
mech.fieldText();
game.replaceTextLog = true; //allow text over write game.replaceTextLog = true; //allow text over write
// game.makeTextLog("<strong style='font-size:30px;'></strong><br> <strong class='faded'>(right click or space bar)</strong><p></p>", 1200);
mech.setHoldDefaults();
mech.hold = function () { mech.hold = function () {
if (mech.isHolding) { if (mech.isHolding) {
mech.drawHold(mech.holdingTarget); mech.drawHold(mech.holdingTarget);
@@ -1071,9 +1067,6 @@ const mech = {
name: "time dilation field", name: "time dilation field",
description: "use <strong class='color-f'>energy</strong> to <strong style='letter-spacing: 1px;'>stop time</strong><br><em>can fire bullets while field is active</em>", description: "use <strong class='color-f'>energy</strong> to <strong style='letter-spacing: 1px;'>stop time</strong><br><em>can fire bullets while field is active</em>",
effect: () => { effect: () => {
mech.fieldMode = 1;
mech.fieldText();
mech.setHoldDefaults();
mech.fieldFire = true; mech.fieldFire = true;
mech.grabRange = 130 mech.grabRange = 130
mech.isBodiesAsleep = false; mech.isBodiesAsleep = false;
@@ -1140,9 +1133,6 @@ const mech = {
name: "plasma torch", name: "plasma torch",
description: "use <strong class='color-f'>energy</strong> to emit <strong class='color-d'>damaging</strong> plasma<br><em>effective at close range</em>", description: "use <strong class='color-f'>energy</strong> to emit <strong class='color-d'>damaging</strong> plasma<br><em>effective at close range</em>",
effect: () => { effect: () => {
mech.fieldMode = 2;
mech.fieldText();
mech.setHoldDefaults();
// mech.fieldShieldingScale = 2; // mech.fieldShieldingScale = 2;
// mech.grabRange = 125; // mech.grabRange = 125;
mech.fieldArc = 0.1 //run calculateFieldThreshold after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob) mech.fieldArc = 0.1 //run calculateFieldThreshold after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob)
@@ -1309,9 +1299,6 @@ const mech = {
name: "negative mass field", name: "negative mass field",
description: "use <strong class='color-f'>energy</strong> to nullify &nbsp; <strong style='letter-spacing: 10px;'>gravity</strong><br><em>can fire bullets while active</em>", description: "use <strong class='color-f'>energy</strong> to nullify &nbsp; <strong style='letter-spacing: 10px;'>gravity</strong><br><em>can fire bullets while active</em>",
effect: () => { effect: () => {
mech.fieldMode = 3;
mech.fieldText();
mech.setHoldDefaults();
mech.fieldFire = true; mech.fieldFire = true;
mech.hold = function () { mech.hold = function () {
@@ -1396,9 +1383,6 @@ const mech = {
name: "standing wave harmonics", name: "standing wave harmonics",
description: "three oscillating <strong>shields</strong> are permanently active<br><strong class='color-f'>energy</strong> regenerates while field is active", description: "three oscillating <strong>shields</strong> are permanently active<br><strong class='color-f'>energy</strong> regenerates while field is active",
effect: () => { effect: () => {
mech.fieldMode = 4;
mech.fieldText();
mech.setHoldDefaults();
// mech.fieldRegen *= 0.6; // mech.fieldRegen *= 0.6;
mech.fieldShieldingScale = 1.33; mech.fieldShieldingScale = 1.33;
@@ -1441,9 +1425,6 @@ const mech = {
name: "nano-scale manufacturing", name: "nano-scale manufacturing",
description: "excess <strong class='color-f'>energy</strong> used to build <strong>drones</strong><br><strong>2x</strong> <strong class='color-f'>energy</strong> regeneration", description: "excess <strong class='color-f'>energy</strong> used to build <strong>drones</strong><br><strong>2x</strong> <strong class='color-f'>energy</strong> regeneration",
effect: () => { effect: () => {
mech.fieldMode = 5;
mech.fieldText();
mech.setHoldDefaults();
mech.fieldRegen *= 2; mech.fieldRegen *= 2;
mech.hold = function () { mech.hold = function () {
if (mech.fieldMeter > mech.fieldEnergyMax - 0.02) { if (mech.fieldMeter > mech.fieldEnergyMax - 0.02) {
@@ -1473,9 +1454,6 @@ const mech = {
name: "phase decoherence field", name: "phase decoherence field",
description: "use <strong class='color-f'>energy</strong> to to become <strong>intangible</strong><br><em style='opacity: 0.6;'>can't see or be seen outside field</em>", description: "use <strong class='color-f'>energy</strong> to to become <strong>intangible</strong><br><em style='opacity: 0.6;'>can't see or be seen outside field</em>",
effect: () => { effect: () => {
mech.fieldMode = 6;
mech.fieldText();
mech.setHoldDefaults();
// mech.grabRange = 230 // mech.grabRange = 230
mech.hold = function () { mech.hold = function () {
mech.isStealth = false //isStealth is checked in mob foundPlayer() mech.isStealth = false //isStealth is checked in mob foundPlayer()

View File

@@ -1,6 +1,37 @@
let powerUp = []; let powerUp = [];
const powerUps = { const powerUps = {
choose(type, index) {
if (type === "gun") {
if (b.activeGun === null) b.activeGun = index //if no active gun switch to new gun
b.guns[index].have = true;
b.inventory.push(index);
b.guns[index].ammo += b.guns[index].ammoPack * 2;
game.makeGunHUD();
// game.replaceTextLog = true;
// game.makeTextLog(`${game.SVGleftMouse} <strong style='font-size:30px;'>${b.guns[index].name}</strong><br><br>${b.guns[index].description}`, 500);
// game.replaceTextLog = false;
} else if (type === "field") {
mech.setField(index)
} else if (type === "mod") {
b.giveMod(index)
// game.replaceTextLog = true;
// game.makeTextLog(`<div class="circle mod"></div> &nbsp; <strong style='font-size:30px;'>${b.mods[index].name}</strong><br><br> ${b.mods[index].description}`, 500);
// game.replaceTextLog = false;
}
document.body.style.cursor = "none";
document.getElementById("choose-grid").style.display = "none"
document.getElementById("choose-background").style.display = "none"
game.paused = false;
requestAnimationFrame(cycle);
},
showDraft() {
document.getElementById("choose-grid").style.display = "grid"
document.getElementById("choose-background").style.display = "inline"
document.body.style.cursor = "auto";
game.paused = true;
},
heal: { heal: {
name: "heal", name: "heal",
color: "#0eb", color: "#0eb",
@@ -60,26 +91,54 @@ const powerUps = {
return 45; return 45;
}, },
effect() { effect() {
const previousMode = mech.fieldMode if (game.isDraftMode) {
if (this.mode) { //this.mode is set if the power up has been ejected from player function doNotHave(who, skip1 = -1, skip2 = -1) {
mech.fieldUpgrades[this.mode].effect(); //set a predetermined power up let options = [];
} else { //choose a random mode that you don't already have for (let i = 1; i < who.length; i++) {
availableModes = [] if (i !== mech.fieldMode && i !== skip1 && i !== skip2) options.push(i);
for (let i = 1; i < mech.fieldUpgrades.length; i++) { //start on 1 to skip the default field
if (i !== previousMode) {
availableModes.push(i)
} }
if (options.length > 0) return options[Math.floor(Math.random() * options.length)]
} }
const mode = availableModes[Math.floor(Math.random() * availableModes.length)]
mech.fieldUpgrades[mode].effect();
}
//pop the old field out in case player wants to swap back
if (previousMode !== 0) {
mech.fieldCDcycle = mech.cycle + 40; //trigger fieldCD to stop power up grab automatic pick up of spawn
setTimeout(function () {
powerUps.spawn(mech.pos.x, mech.pos.y - 15, "field", false, previousMode);
}, 100);
let choice1 = doNotHave(mech.fieldUpgrades)
let choice2 = doNotHave(mech.fieldUpgrades, choice1)
let choice3 = doNotHave(mech.fieldUpgrades, choice1, choice2)
if (choice1 > -1) {
let text = `<h3 style = 'color:#fff; text-align:left; margin: 0px;'>choose a field</h3>`
text += `<div class="choose-grid-module" onclick="powerUps.choose('field',${choice1})"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[choice1].name}</div> ${mech.fieldUpgrades[choice1].description}</div>`
if (choice2 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('field',${choice2})"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[choice2].name}</div> ${mech.fieldUpgrades[choice2].description}</div>`
if (choice3 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('field',${choice3})"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[choice3].name}</div> ${mech.fieldUpgrades[choice3].description}</div>`
// text += `<div style = 'color:#fff'>${game.SVGrightMouse} activate the shield with the right mouse<br>fields shield you from damage <br>and let you pick up and throw blocks</div>`
document.getElementById("choose-grid").innerHTML = text
powerUps.showDraft();
} else {
powerUps.giveRandomAmmo()
}
} else {
const previousMode = mech.fieldMode
if (this.mode) { //this.mode is set if the power up has been ejected from player
// mech.fieldUpgrades[this.mode].effect(); //set a predetermined power up
mech.setField(this.mode)
} else { //choose a random mode that you don't already have
availableModes = []
for (let i = 1; i < mech.fieldUpgrades.length; i++) { //start on 1 to skip the default field
if (i !== previousMode) {
availableModes.push(i)
}
}
const mode = availableModes[Math.floor(Math.random() * availableModes.length)]
mech.setField(mode)
}
game.replaceTextLog = true;
game.makeTextLog(`${game.SVGrightMouse}<strong style='font-size:30px;'> ${mech.fieldUpgrades[mech.fieldMode].name}</strong><br><span class='faded'></span><br>${mech.fieldUpgrades[mech.fieldMode].description}`, 600);
game.replaceTextLog = false;
//pop the old field out in case player wants to swap back
if (previousMode !== 0) {
mech.fieldCDcycle = mech.cycle + 40; //trigger fieldCD to stop power up grab automatic pick up of spawn
setTimeout(function () {
powerUps.spawn(mech.pos.x, mech.pos.y - 15, "field", false, previousMode);
}, 100);
}
} }
} }
}, },
@@ -90,18 +149,43 @@ const powerUps = {
return 42; return 42;
}, },
effect() { effect() {
//find what mods I don't have if (game.isDraftMode) {
let options = []; function doNotHave(who, skip1 = -1, skip2 = -1) {
for (let i = 0; i < b.mods.length; i++) { let options = [];
if (!b.mods[i].have) options.push(i); for (let i = 0; i < who.length; i++) {
} if (!who[i].have && i !== skip1 && i !== skip2) options.push(i);
//give a random mod from the mods I don't have }
if (options.length > 0) { if (options.length > 0) return options[Math.floor(Math.random() * options.length)]
let newMod = options[Math.floor(Math.random() * options.length)] }
b.giveMod(newMod)
game.replaceTextLog = true; let choice1 = doNotHave(b.mods)
game.makeTextLog(`<div class="circle mod"></div> &nbsp; <strong style='font-size:30px;'>${b.mods[newMod].name}</strong><br><br> ${b.mods[newMod].description}`, 1000); let choice2 = doNotHave(b.mods, choice1)
game.replaceTextLog = false; let choice3 = doNotHave(b.mods, choice1, choice2)
if (choice1 > -1) {
let text = "<h3 style = 'color:#fff; text-align:center; margin: 0px;'>choose a mod</h3>"
text += `<div class="choose-grid-module" onclick="powerUps.choose('mod',${choice1})"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[choice1].name}</div> ${b.mods[choice1].description}</div>`
if (choice2 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('mod',${choice2})"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[choice2].name}</div> ${b.mods[choice2].description}</div>`
if (choice3 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('mod',${choice3})"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[choice3].name}</div> ${b.mods[choice3].description}</div>`
document.getElementById("choose-grid").innerHTML = text
powerUps.showDraft();
} else {
powerUps.giveRandomAmmo()
}
} else {
//find what mods I don't have
let options = [];
for (let i = 0; i < b.mods.length; i++) {
if (!b.mods[i].have) options.push(i);
}
// give a random mod from the mods I don 't have
if (options.length > 0) {
let newMod = options[Math.floor(Math.random() * options.length)]
b.giveMod(newMod)
game.replaceTextLog = true;
game.makeTextLog(`<div class="circle mod"></div> &nbsp; <strong style='font-size:30px;'>${b.mods[newMod].name}</strong><br><br> ${b.mods[newMod].description}`, 1000);
game.replaceTextLog = false;
}
} }
} }
}, },
@@ -112,40 +196,68 @@ const powerUps = {
return 35; return 35;
}, },
effect() { effect() {
//find what guns I don't have if (game.isDraftMode) {
let options = [];
if (b.activeGun === null && game.difficulty < 3) { function doNotHave(who, skip1 = -1, skip2 = -1) {
//choose the first gun to be one that is good for the early game let options = [];
for (let i = 0; i < b.guns.length; ++i) { for (let i = 0; i < who.length; i++) {
if (!b.guns[i].have && b.guns[i].isStarterGun) options.push(i); if (!who[i].have && i !== skip1 && i !== skip2) options.push(i);
}
if (options.length > 0) return options[Math.floor(Math.random() * options.length)]
}
let choice1 = doNotHave(b.guns)
let choice2 = doNotHave(b.guns, choice1)
let choice3 = doNotHave(b.guns, choice1, choice2)
if (choice1 > -1) {
let text = "<h3 style = 'color:#fff; text-align:center; margin: 0px;'>choose a gun</h3>"
text += `<div class="choose-grid-module" onclick="powerUps.choose('gun',${choice1})"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[choice1].name}</div> ${b.guns[choice1].description}</div>`
if (choice2 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('gun',${choice2})"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[choice2].name}</div> ${b.guns[choice2].description}</div>`
if (choice3 > -1) text += `<div class="choose-grid-module" onclick="powerUps.choose('gun',${choice3})"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[choice3].name}</div> ${b.guns[choice3].description}</div>`
document.getElementById("choose-grid").innerHTML = text
powerUps.showDraft();
} else {
powerUps.giveRandomAmmo()
} }
} else { } else {
//choose a gun you don't have //find what guns I don't have
for (let i = 0; i < b.guns.length; ++i) { let options = [];
if (!b.guns[i].have) options.push(i); if (b.activeGun === null && game.difficulty < 3) {
//choose the first gun to be one that is good for the early game
for (let i = 0; i < b.guns.length; ++i) {
if (!b.guns[i].have && b.guns[i].isStarterGun) options.push(i);
}
} else {
//choose a gun you don't have
for (let i = 0; i < b.guns.length; ++i) {
if (!b.guns[i].have) options.push(i);
}
} }
//give player a gun they don't already have if possible
game.replaceTextLog = true;
if (options.length > 0) {
let newGun = options[Math.floor(Math.random() * options.length)];
if (b.activeGun === null) b.activeGun = newGun //if no active gun switch to new gun
b.guns[newGun].have = true;
b.inventory.push(newGun);
b.guns[newGun].ammo += b.guns[newGun].ammoPack * 2;
game.makeGunHUD();
game.makeTextLog(`${game.SVGleftMouse} <strong style='font-size:30px;'>${b.guns[newGun].name}</strong><br><br>${b.guns[newGun].description}`, 900);
} else {
powerUps.giveRandomAmmo()
}
game.replaceTextLog = false
} }
//give player a gun they don't already have if possible
game.replaceTextLog = true;
if (options.length > 0) {
let newGun = options[Math.floor(Math.random() * options.length)];
if (b.activeGun === null) b.activeGun = newGun //if no active gun switch to new gun
game.makeTextLog(`${game.SVGleftMouse} <strong style='font-size:30px;'>${b.guns[newGun].name}</strong><br><br>${b.guns[newGun].description}`, 900);
b.guns[newGun].have = true;
b.inventory.push(newGun);
b.guns[newGun].ammo += b.guns[newGun].ammoPack * 2;
game.makeGunHUD();
} else {
//if you have all guns then get ammo
const ammoTarget = Math.floor(Math.random() * (b.guns.length));
const ammo = Math.ceil(b.guns[ammoTarget].ammoPack * 2);
b.guns[ammoTarget].ammo += ammo;
game.updateGunHUD();
game.makeTextLog("<span style='font-size:110%;'>+" + ammo + " ammo for " + b.guns[ammoTarget].name + "</span>", 300);
}
game.replaceTextLog = false
} }
}, },
giveRandomAmmo() {
const ammoTarget = Math.floor(Math.random() * (b.guns.length));
const ammo = Math.ceil(b.guns[ammoTarget].ammoPack * 2);
b.guns[ammoTarget].ammo += ammo;
game.updateGunHUD();
game.makeTextLog("<span style='font-size:110%;'>+" + ammo + " ammo for " + b.guns[ammoTarget].name + "</span>", 300);
},
spawnRandomPowerUp(x, y) { //mostly used after mob dies spawnRandomPowerUp(x, y) { //mostly used after mob dies
if (Math.random() * Math.random() - 0.25 > Math.sqrt(mech.health) || Math.random() < 0.04) { //spawn heal chance is higher at low health if (Math.random() * Math.random() - 0.25 > Math.sqrt(mech.health) || Math.random() < 0.04) { //spawn heal chance is higher at low health
powerUps.spawn(x, y, "heal"); powerUps.spawn(x, y, "heal");
@@ -167,7 +279,7 @@ const powerUps = {
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod"); if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod");
return; return;
} }
if (Math.random() < 0.005) { if (Math.random() < 0.003) {
powerUps.spawn(x, y, "field"); powerUps.spawn(x, y, "field");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field"); if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field");
return; return;
@@ -177,21 +289,29 @@ const powerUps = {
if (mech.fieldMode === 0) { if (mech.fieldMode === 0) {
powerUps.spawn(x, y, "field") powerUps.spawn(x, y, "field")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field") if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field")
} else if (Math.random() < 0.27) { } else if (Math.random() < 0.4) {
powerUps.spawn(x, y, "mod") powerUps.spawn(x, y, "mod")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod") if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "mod")
} else if (Math.random() < 0.27) { } else if (Math.random() < 0.3) {
powerUps.spawn(x, y, "field");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field");
} else if (Math.random() < 0.27) {
powerUps.spawn(x, y, "gun") powerUps.spawn(x, y, "gun")
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun") if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "gun")
} else if (Math.random() < 0.15) {
powerUps.spawn(x, y, "field");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "field");
} else if (mech.health < 0.6) { } else if (mech.health < 0.6) {
powerUps.spawn(x, y, "heal"); powerUps.spawn(x, y, "heal");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "heal"); powerUps.spawn(x, y, "heal");
if (Math.random() < b.modMoreDrops) {
powerUps.spawn(x, y, "heal");
powerUps.spawn(x, y, "heal");
}
} else { } else {
powerUps.spawn(x, y, "ammo"); powerUps.spawn(x, y, "ammo");
if (Math.random() < b.modMoreDrops) powerUps.spawn(x, y, "ammo"); powerUps.spawn(x, y, "ammo");
if (Math.random() < b.modMoreDrops) {
powerUps.spawn(x, y, "ammo");
powerUps.spawn(x, y, "ammo");
}
} }
}, },
chooseRandomPowerUp(x, y) { //100% chance to drop a random power up //used in spawn.debris chooseRandomPowerUp(x, y) { //100% chance to drop a random power up //used in spawn.debris

View File

@@ -53,6 +53,13 @@ summary {
background-color: #efeff5; background-color: #efeff5;
} }
#draft-button {
position: absolute;
top: 3px;
left: 3px;
z-index: 12;
}
#build-button { #build-button {
position: absolute; position: absolute;
top: 3px; top: 3px;
@@ -60,36 +67,40 @@ summary {
z-index: 12; z-index: 12;
} }
#choose-background {
position: absolute;
z-index: 2;
width: 100%;
height: 100%;
display: none;
background-color: #fff;
opacity: 0.5;
/* transition: display 0.5s; */
}
#choose-grid { #choose-grid {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 10px; padding: 10px;
margin: 0px; margin: 0px;
border-radius: 7px; border-radius: 8px;
position: absolute;
bottom: 0px;
left: 0px;
z-index: 12; z-index: 12;
background-color: #444; background-color: #444;
/* background-color: rgba(68, 68, 68, 0.5); */ display: none;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
grid-auto-rows: minmax(auto, auto); grid-auto-rows: minmax(auto, auto);
grid-gap: 10px; grid-gap: 10px;
z-index: 12;
font-size: 1.3em; font-size: 1.3em;
cursor: auto;
} }
.choose-grid-module { .choose-grid-module {
/* box-shadow: 0px 1px 4px #234; */
padding: 10px; padding: 10px;
/* margin: 4px; */
line-height: 170%; line-height: 170%;
border-radius: 6px; border-radius: 6px;
background-color: #fff; background-color: #fff;
/* background-color: rgba(255, 255, 255, 0.5); */
font-size: 0.8em; font-size: 0.8em;
/* display: flex; */
} }
.choose-grid-module:hover { .choose-grid-module:hover {
@@ -100,32 +111,25 @@ summary {
padding: 16px; padding: 16px;
margin: 0px; margin: 0px;
border: 0px; border: 0px;
/* border-radius: 8px; */
background-color: #c4ccd8; background-color: #c4ccd8;
/* #b6bfca; */
display: none; display: none;
/* display: grid; */
grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
grid-auto-rows: minmax(auto, auto); grid-auto-rows: minmax(auto, auto);
grid-gap: 16px; grid-gap: 16px;
position: relative; position: relative;
bottom: 0px; bottom: 0px;
/* left: 0px; */ z-index: 10;
z-index: 12;
font-size: 1.3em; font-size: 1.3em;
} }
.build-grid-module { .build-grid-module {
/* box-shadow: 0px 1px 4px #234; */
padding: 10px; padding: 10px;
/* margin: 4px; */
line-height: 170%; line-height: 170%;
border-radius: 6px; border-radius: 6px;
background: #fff; background: #fff;
font-size: 0.65em; font-size: 0.65em;
/* display: flex; */
} }
.grid-title { .grid-title {
@@ -138,26 +142,6 @@ summary {
background-color: #efeff5; background-color: #efeff5;
} }
.gun-module {
background: #d5dde5;
}
.field-module {
background: #bde;
}
.mod-module {
background: #fdf;
}
/* #build {
position: absolute;
bottom: 0px;
right: 1px;
z-index: 12;
font-size: 1.3em;
} */
#settings { #settings {
position: absolute; position: absolute;
bottom: 0px; bottom: 0px;