diff --git a/js/bullet.js b/js/bullet.js
index 10c8851..9a41cf9 100644
--- a/js/bullet.js
+++ b/js/bullet.js
@@ -7,7 +7,7 @@ const b = {
inventoryGun: 0,
inventory: [], //list of what guns player has // 0 starts with basic gun
fire() {
- if (game.mouseDown && mech.fireCDcycle < mech.cycle && (!(keys[32] || game.mouseDownRight) || mech.fieldFire) && b.inventory.length) {
+ if (input.fire && mech.fireCDcycle < mech.cycle && (!(input.space || input.fireRight) || mech.fieldFire) && b.inventory.length) {
if (b.guns[b.activeGun].ammo > 0) {
b.guns[b.activeGun].fire();
if (mod.isCrouchAmmo && mech.crouch) {
@@ -2412,9 +2412,9 @@ const b = {
this.force.y += this.mass * 0.0022;
//set armed and sucking status
- if (!this.isArmed && !game.mouseDown) {
+ if (!this.isArmed && !input.fire) {
this.isArmed = true
- } else if (this.isArmed && game.mouseDown && !this.isSucking) {
+ } else if (this.isArmed && input.fire && !this.isSucking) {
this.isSucking = true;
this.endCycle = game.cycle + 50;
}
@@ -3013,7 +3013,7 @@ const b = {
return
}
- if ((!game.mouseDown && this.charge > 0.6)) { //fire on mouse release or on low energy
+ if ((!input.fire && this.charge > 0.6)) { //fire on mouse release or on low energy
mech.fireCDcycle = mech.cycle + 2; // set fire cool down
//normal bullet behavior occurs after firing, overwrites this function
this.do = function () {
diff --git a/js/game.js b/js/game.js
index b2c3597..8e54d81 100644
--- a/js/game.js
+++ b/js/game.js
@@ -136,7 +136,6 @@ const game = {
accelScale: null, //set in levels.setDifficulty
CDScale: null, //set in levels.setDifficulty
lookFreqScale: null, //set in levels.setDifficulty
- mouseDown: false,
// dropFPS(cap = 40, time = 15) {
// game.fpsCap = cap
// game.fpsInterval = 1000 / game.fpsCap;
@@ -367,167 +366,6 @@ const game = {
game.boldActiveGunHUD();
// mech.drop();
},
- isPauseKeyReady: true,
- keyPress() { //runs on key down event
- //full screen toggle
- // if (keys[13]) {
- // //enter key
- // var doc = window.document;
- // var docEl = doc.documentElement;
-
- // var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
- // var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
-
- // if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
- // requestFullScreen.call(docEl);
- // } else {
- // cancelFullScreen.call(doc);
- // }
- // setupCanvas();
- // }
-
- //color testing
- // if (keys[49]) {
- // mech.color.hue--
- // mech.setFillColors();
- // } else if (keys[50]) {
- // mech.color.hue++
- // mech.setFillColors();
- // } else if (keys[51]) {
- // mech.color.sat--
- // mech.setFillColors();
- // } else if (keys[52]) {
- // mech.color.sat++
- // mech.setFillColors();
- // } else if (keys[53]) {
- // mech.color.light--
- // mech.setFillColors();
- // } else if (keys[54]) {
- // mech.color.light++
- // mech.setFillColors();
- // }
-
- if (keys[69]) { // e swap to next active gun
- game.nextGun();
- } else if (keys[81]) { //q swap to previous active gun
- game.previousGun();
- }
- if (keys[80] && !game.isChoosing && game.isPauseKeyReady) { //p for pause
-
- game.isPauseKeyReady = false
- setTimeout(function () {
- game.isPauseKeyReady = true
- }, 300);
-
- if (game.paused) {
- build.unPauseGrid()
- game.paused = false;
- level.levelAnnounce();
- document.body.style.cursor = "none";
- requestAnimationFrame(cycle);
- } else {
- game.paused = true;
- game.replaceTextLog = true;
- // game.makeTextLog("
PAUSED
", 1);
- //display grid
- // document.title = "PAUSED: press P to resume";
- build.pauseGrid()
- document.body.style.cursor = "auto";
- }
- }
-
- //toggle testing mode
- if (keys[84]) {
- // 84 = t
- if (game.testing) {
- game.testing = false;
- game.loop = game.normalLoop
- if (game.isConstructionMode) {
- document.getElementById("construct").style.display = 'none'
- }
- } else { //if (keys[191])
- game.testing = true;
- game.isCheating = true;
- if (game.isConstructionMode) {
- document.getElementById("construct").style.display = 'inline'
- }
- game.loop = game.testingLoop
- }
- }
- //in testing mode
- if (game.testing) {
-
- if (keys[79]) {
- // - key
- game.isAutoZoom = false;
- game.zoomScale /= 0.9;
- game.setZoom();
- } else if (keys[73]) {
- // = key
- game.isAutoZoom = false;
- game.zoomScale *= 0.9;
- game.setZoom();
- }
-
- if (keys[192]) { // `
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "reroll");
- } else if (keys[49]) { // give power ups with 1
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
- } else if (keys[50]) { // 2
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "ammo");
- } else if (keys[51]) { // 3
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
- } else if (keys[52]) { // 4
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "field");
- } else if (keys[53]) { // 5
- powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
- } else if (keys[54]) { // 6 spawn mob
- const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)];
- spawn[pick](game.mouseInGame.x, game.mouseInGame.y);
- } else if (keys[55]) { // 7 spawn body
- index = body.length
- spawn.bodyRect(game.mouseInGame.x, game.mouseInGame.y, 50, 50);
- body[index].collisionFilter.category = cat.body;
- body[index].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet
- body[index].classType = "body";
- World.add(engine.world, body[index]); //add to world
- } else if (keys[70]) { //cycle fields with F
- const mode = (mech.fieldMode === mech.fieldUpgrades.length - 1) ? 0 : mech.fieldMode + 1
- mech.setField(mode)
- } else if (keys[71]) { // give all guns with G
- b.giveGuns("all", 1000)
- } else if (keys[72]) { // heal with H
- mech.addHealth(Infinity)
- mech.energy = mech.maxEnergy;
- } else if (keys[89]) { //add mods with y
- mod.giveMod()
- } else if (keys[82]) { // teleport to mouse with R
- Matter.Body.setPosition(player, game.mouseInGame);
- Matter.Body.setVelocity(player, {
- x: 0,
- y: 0
- });
- // move bots to follow player
- for (let i = 0; i < bullet.length; i++) {
- if (bullet[i].botType) {
- Matter.Body.setPosition(bullet[i], Vector.add(player.position, {
- x: 250 * (Math.random() - 0.5),
- y: 250 * (Math.random() - 0.5)
- }));
- Matter.Body.setVelocity(bullet[i], {
- x: 0,
- y: 0
- });
- }
- }
- // game.noCameraScroll()
- } else if (keys[85]) { // next level with U
- level.nextLevel();
- } else if (keys[88] && keys[90]) {
- mech.death();
- }
- }
- },
zoom: null,
zoomScale: 1000,
isAutoZoom: true,
@@ -811,35 +649,35 @@ const game = {
game.fpsCap = game.fpsCapDefault
game.fpsInterval = 1000 / game.fpsCap;
},
- getCoords: {
- //used when building maps, outputs a draw rect command to console, only works in testing mode
- pos1: {
- x: 0,
- y: 0
- },
- pos2: {
- x: 0,
- y: 0
- },
- out() {
- if (keys[49]) {
- game.getCoords.pos1.x = Math.round(game.mouseInGame.x / 25) * 25;
- game.getCoords.pos1.y = Math.round(game.mouseInGame.y / 25) * 25;
- }
- if (keys[50]) {
- //press 1 in the top left; press 2 in the bottom right;copy command from console
- game.getCoords.pos2.x = Math.round(game.mouseInGame.x / 25) * 25;
- game.getCoords.pos2.y = Math.round(game.mouseInGame.y / 25) * 25;
- window.getSelection().removeAllRanges();
- var range = document.createRange();
- range.selectNode(document.getElementById("test"));
- window.getSelection().addRange(range);
- document.execCommand("copy");
- window.getSelection().removeAllRanges();
- console.log(`spawn.mapRect(${game.getCoords.pos1.x}, ${game.getCoords.pos1.y}, ${game.getCoords.pos2.x - game.getCoords.pos1.x}, ${game.getCoords.pos2.y - game.getCoords.pos1.y}); //`);
- }
- }
- },
+ // getCoords: {
+ // //used when building maps, outputs a draw rect command to console, only works in testing mode
+ // pos1: {
+ // x: 0,
+ // y: 0
+ // },
+ // pos2: {
+ // x: 0,
+ // y: 0
+ // },
+ // out() {
+ // if (keys[49]) {
+ // game.getCoords.pos1.x = Math.round(game.mouseInGame.x / 25) * 25;
+ // game.getCoords.pos1.y = Math.round(game.mouseInGame.y / 25) * 25;
+ // }
+ // if (keys[50]) {
+ // //press 1 in the top left; press 2 in the bottom right;copy command from console
+ // game.getCoords.pos2.x = Math.round(game.mouseInGame.x / 25) * 25;
+ // game.getCoords.pos2.y = Math.round(game.mouseInGame.y / 25) * 25;
+ // window.getSelection().removeAllRanges();
+ // var range = document.createRange();
+ // range.selectNode(document.getElementById("test"));
+ // window.getSelection().addRange(range);
+ // document.execCommand("copy");
+ // window.getSelection().removeAllRanges();
+ // console.log(`spawn.mapRect(${game.getCoords.pos1.x}, ${game.getCoords.pos1.y}, ${game.getCoords.pos2.x - game.getCoords.pos1.x}, ${game.getCoords.pos2.y - game.getCoords.pos1.y}); //`);
+ // }
+ // }
+ // },
checks() {
if (!(mech.cycle % 60)) { //once a second
diff --git a/js/index.js b/js/index.js
index b3f4f2b..021cddb 100644
--- a/js/index.js
+++ b/js/index.js
@@ -110,6 +110,39 @@ window.addEventListener('load', (event) => {
}
});
+
+
+//set up canvas
+var canvas = document.getElementById("canvas");
+//using "const" causes problems in safari when an ID shares the same name.
+const ctx = canvas.getContext("2d");
+document.body.style.backgroundColor = "#fff";
+
+//disable pop up menu on right click
+document.oncontextmenu = function () {
+ return false;
+}
+
+function setupCanvas() {
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+ canvas.width2 = canvas.width / 2; //precalculated because I use this often (in mouse look)
+ canvas.height2 = canvas.height / 2;
+ canvas.diagonal = Math.sqrt(canvas.width2 * canvas.width2 + canvas.height2 * canvas.height2);
+ // ctx.font = "18px Arial";
+ // ctx.textAlign = "center";
+ ctx.font = "25px Arial";
+ ctx.lineJoin = "round";
+ ctx.lineCap = "round";
+ // ctx.lineCap='square';
+ game.setZoom();
+}
+setupCanvas();
+window.onresize = () => {
+ setupCanvas();
+};
+
+
//build build grid display
const build = {
onLoadPowerUps() {
@@ -493,117 +526,9 @@ if (localSettings) {
document.getElementById("fps-select").value = localSettings.fpsCapDefault
}
-//set up canvas
-var canvas = document.getElementById("canvas");
-//using "const" causes problems in safari when an ID shares the same name.
-const ctx = canvas.getContext("2d");
-document.body.style.backgroundColor = "#fff";
-
-//disable pop up menu on right click
-document.oncontextmenu = function () {
- return false;
-}
-
-function setupCanvas() {
- canvas.width = window.innerWidth;
- canvas.height = window.innerHeight;
- canvas.width2 = canvas.width / 2; //precalculated because I use this often (in mouse look)
- canvas.height2 = canvas.height / 2;
- canvas.diagonal = Math.sqrt(canvas.width2 * canvas.width2 + canvas.height2 * canvas.height2);
- // ctx.font = "18px Arial";
- // ctx.textAlign = "center";
- ctx.font = "25px Arial";
- ctx.lineJoin = "round";
- ctx.lineCap = "round";
- // ctx.lineCap='square';
- game.setZoom();
-}
-setupCanvas();
-window.onresize = () => {
- setupCanvas();
-};
-
-//mouse move input
-document.body.addEventListener("mousemove", (e) => {
- game.mouse.x = e.clientX;
- game.mouse.y = e.clientY;
-});
-
-document.body.addEventListener("mouseup", (e) => {
- // game.buildingUp(e); //uncomment when building levels
- // game.mouseDown = false;
- // console.log(e)
- if (e.which === 3) {
- game.mouseDownRight = false;
- } else {
- game.mouseDown = false;
- }
-});
-
-document.body.addEventListener("mousedown", (e) => {
- if (e.which === 3) {
- game.mouseDownRight = true;
- } else {
- game.mouseDown = true;
- }
-});
-
-document.body.addEventListener("mouseenter", (e) => { //prevents mouse getting stuck when leaving the window
- // game.mouseDown = false;
- // game.mouseDownRight = false;
-
- if (e.button === 1) {
- game.mouseDown = true;
- } else {
- game.mouseDown = false;
- }
-
- if (e.button === 3) {
- game.mouseDownRight = true;
- } else {
- game.mouseDownRight = false;
- }
-});
-document.body.addEventListener("mouseleave", (e) => { //prevents mouse getting stuck when leaving the window
- // game.mouseDown = false;
- // game.mouseDownRight = false;
- // console.log(e)
- if (e.button === 1) {
- game.mouseDown = true;
- } else {
- game.mouseDown = false;
- }
-
- if (e.button === 3) {
- game.mouseDownRight = true;
- } else {
- game.mouseDownRight = false;
- }
-});
-
-//keyboard input
-const keys = [];
-document.body.addEventListener("keydown", (e) => {
- console.log(e.keyCode)
- keys[e.keyCode] = true;
- if (mech.alive) game.keyPress();
-});
-
-document.body.addEventListener("keyup", (e) => {
- keys[e.keyCode] = false;
-});
-
-document.body.addEventListener("wheel", (e) => {
- if (!game.paused) {
- if (e.deltaY > 0) {
- game.nextGun();
- } else {
- game.previousGun();
- }
- }
-}, {
- passive: true
-});
+//**********************************************************************
+// settings
+//**********************************************************************
document.getElementById("fps-select").addEventListener("input", () => {
let value = document.getElementById("fps-select").value
@@ -630,7 +555,262 @@ document.getElementById("difficulty-select").addEventListener("input", () => {
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
});
-//main loop ************************************************************
+// ************************************************************************************************
+// ************************************************************************************************
+// inputs
+// ************************************************************************************************
+// ************************************************************************************************
+
+const input = {
+ up: false, // jump
+ down: false, // crouch
+ left: false,
+ right: false,
+ field: false, // right mouse
+ fire: false, // left mouse
+ isPauseKeyReady: true,
+}
+//mouse move input
+document.body.addEventListener("mousemove", (e) => {
+ game.mouse.x = e.clientX;
+ game.mouse.y = e.clientY;
+});
+
+document.body.addEventListener("mouseup", (e) => {
+ // input.fire = false;
+ // console.log(e)
+ if (e.which === 3) {
+ input.field = false;
+ } else {
+ input.fire = false;
+ }
+});
+
+document.body.addEventListener("mousedown", (e) => {
+ if (e.which === 3) {
+ input.field = true;
+ } else {
+ input.fire = true;
+ }
+});
+
+document.body.addEventListener("mouseenter", (e) => { //prevents mouse getting stuck when leaving the window
+ if (e.button === 1) {
+ input.fire = true;
+ } else {
+ input.fire = false;
+ }
+
+ if (e.button === 3) {
+ input.field = true;
+ } else {
+ input.field = false;
+ }
+});
+document.body.addEventListener("mouseleave", (e) => { //prevents mouse getting stuck when leaving the window
+ if (e.button === 1) {
+ input.fire = true;
+ } else {
+ input.fire = false;
+ }
+
+ if (e.button === 3) {
+ input.field = true;
+ } else {
+ input.field = false;
+ }
+});
+
+document.body.addEventListener("wheel", (e) => {
+ if (!game.paused) {
+ if (e.deltaY > 0) {
+ game.nextGun();
+ } else {
+ game.previousGun();
+ }
+ }
+}, {
+ passive: true
+});
+
+window.addEventListener("keydown", function (event) {
+ // if (event.defaultPrevented) {
+ // return; // Do nothing if the event was already processed
+ // }
+ switch (event.key) {
+ case "d":
+ case "ArrowRight":
+ input.right = true
+ break;
+ case "a":
+ case "ArrowLeft":
+ input.left = true
+ break;
+ case "w":
+ case "ArrowUp":
+ input.up = true
+ break;
+ case "s":
+ case "ArrowDown":
+ input.down = true
+ break;
+ case "e":
+ game.nextGun();
+ break
+ case "q":
+ game.previousGun();
+ break
+ case "p":
+ if (!game.isChoosing && input.isPauseKeyReady) {
+ input.isPauseKeyReady = false
+ setTimeout(function () {
+ input.isPauseKeyReady = true
+ }, 300);
+ if (game.paused) {
+ build.unPauseGrid()
+ game.paused = false;
+ level.levelAnnounce();
+ document.body.style.cursor = "none";
+ requestAnimationFrame(cycle);
+ } else {
+ game.paused = true;
+ game.replaceTextLog = true;
+ build.pauseGrid()
+ document.body.style.cursor = "auto";
+ }
+ }
+ break
+ case "t":
+ if (game.testing) {
+ game.testing = false;
+ game.loop = game.normalLoop
+ if (game.isConstructionMode) {
+ document.getElementById("construct").style.display = 'none'
+ }
+ } else { //if (keys[191])
+ game.testing = true;
+ game.isCheating = true;
+ if (game.isConstructionMode) {
+ document.getElementById("construct").style.display = 'inline'
+ }
+ game.loop = game.testingLoop
+ }
+ break
+ }
+ if (game.testing) {
+ switch (event.key) {
+ case "o":
+ game.isAutoZoom = false;
+ game.zoomScale /= 0.9;
+ game.setZoom();
+ break;
+ case "i":
+ game.isAutoZoom = false;
+ game.zoomScale *= 0.9;
+ game.setZoom();
+ break
+ case "`":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "reroll");
+ break
+ case "1":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
+ break
+ case "2":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "ammo");
+ break
+ case "3":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
+ break
+ case "4":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "field");
+ break
+ case "5":
+ powerUps.directSpawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
+ break
+ case "6":
+ const pick = spawn.fullPickList[Math.floor(Math.random() * spawn.fullPickList.length)];
+ spawn[pick](game.mouseInGame.x, game.mouseInGame.y);
+ break
+ case "7":
+ const index = body.length
+ spawn.bodyRect(game.mouseInGame.x, game.mouseInGame.y, 50, 50);
+ body[index].collisionFilter.category = cat.body;
+ body[index].collisionFilter.mask = cat.player | cat.map | cat.body | cat.bullet | cat.mob | cat.mobBullet
+ body[index].classType = "body";
+ World.add(engine.world, body[index]); //add to world
+ break
+ case "f":
+ const mode = (mech.fieldMode === mech.fieldUpgrades.length - 1) ? 0 : mech.fieldMode + 1
+ mech.setField(mode)
+ break
+ case "g":
+ b.giveGuns("all", 1000)
+ break
+ case "h":
+ mech.addHealth(Infinity)
+ mech.energy = mech.maxEnergy;
+ break
+ case "y":
+ mod.giveMod()
+ break
+ case "r":
+ Matter.Body.setPosition(player, game.mouseInGame);
+ Matter.Body.setVelocity(player, {
+ x: 0,
+ y: 0
+ });
+ // move bots to follow player
+ for (let i = 0; i < bullet.length; i++) {
+ if (bullet[i].botType) {
+ Matter.Body.setPosition(bullet[i], Vector.add(player.position, {
+ x: 250 * (Math.random() - 0.5),
+ y: 250 * (Math.random() - 0.5)
+ }));
+ Matter.Body.setVelocity(bullet[i], {
+ x: 0,
+ y: 0
+ });
+ }
+ }
+ break
+ case "u":
+ level.nextLevel();
+ break
+ case "X": //capital X to make it hard to die
+ mech.death();
+ break
+ }
+ }
+ // event.preventDefault(); // Cancel the default action to avoid it being handled twice
+}, true);
+
+window.addEventListener("keyup", function (event) {
+ // if (event.defaultPrevented) {
+ // return; // Do nothing if the event was already processed
+ // }
+ switch (event.key) {
+ case "d":
+ case "ArrowRight":
+ input.right = false
+ break;
+ case "a":
+ case "ArrowLeft":
+ input.left = false
+ break;
+ case "w":
+ case "ArrowUp":
+ input.up = false
+ break;
+ case "s":
+ case "ArrowDown":
+ input.down = false
+ break;
+ }
+ // event.preventDefault(); // Cancel the default action to avoid it being handled twice
+}, true);
+
+//**********************************************************************
+// main loop
//**********************************************************************
game.loop = game.normalLoop;
diff --git a/js/level.js b/js/level.js
index 6a4d32a..8ea014a 100644
--- a/js/level.js
+++ b/js/level.js
@@ -20,7 +20,7 @@ const level = {
// for (let i = 0; i < 10; i++) {
// mod.giveMod("laser-bot");
// }
- // mod.giveMod("eddy current brake")
+ // mod.giveMod("bot fabrication")
level.intro(); //starting level
diff --git a/js/player.js b/js/player.js
index 96c2d62..a93332e 100644
--- a/js/player.js
+++ b/js/player.js
@@ -223,10 +223,10 @@ const mech = {
buttonCD_jump: 0, //cool down for player buttons
groundControl() {
if (mech.crouch) {
- if (!(keys[83] || keys[40]) && mech.checkHeadClear() && mech.hardLandCD < mech.cycle) mech.undoCrouch();
- } else if (keys[83] || keys[40] || mech.hardLandCD > mech.cycle) {
+ if (!(input.down) && mech.checkHeadClear() && mech.hardLandCD < mech.cycle) mech.undoCrouch();
+ } else if (input.down || mech.hardLandCD > mech.cycle) {
mech.doCrouch(); //on ground && not crouched and pressing s or down
- } else if ((keys[87] || keys[38]) && mech.buttonCD_jump + 20 < mech.cycle && mech.yOffWhen.stand > 23) {
+ } else if ((input.up) && mech.buttonCD_jump + 20 < mech.cycle && mech.yOffWhen.stand > 23) {
mech.buttonCD_jump = mech.cycle; //can't jump again until 20 cycles pass
//apply a fraction of the jump force to the body the player is jumping off of
@@ -242,7 +242,7 @@ const mech = {
});
}
- if (keys[65] || keys[37]) { //left / a
+ if (input.left) {
// if (game.mouseDownRight && mech.fieldCDcycle < mech.cycle && !mech.crouch) {
// blink(-1)
// } else {
@@ -252,7 +252,7 @@ const mech = {
player.force.x -= mech.Fx
}
// }
- } else if (keys[68] || keys[39]) { //right / d
+ } else if (input.right) {
// if (game.mouseDownRight && mech.fieldCDcycle < mech.cycle && !mech.crouch) {
// blink(1)
// } else {
@@ -280,7 +280,7 @@ const mech = {
},
airControl() {
//check for short jumps //moving up //recently pressed jump //but not pressing jump key now
- if (mech.buttonCD_jump + 60 > mech.cycle && !(keys[87] || keys[38]) && mech.Vy < 0) {
+ if (mech.buttonCD_jump + 60 > mech.cycle && !(input.up) && mech.Vy < 0) {
Matter.Body.setVelocity(player, {
//reduce player y-velocity every cycle
x: player.velocity.x,
@@ -288,9 +288,9 @@ const mech = {
});
}
- if (keys[65] || keys[37]) {
+ if (input.left) {
if (player.velocity.x > -mech.airSpeedLimit / player.mass / player.mass) player.force.x -= mech.FxAir; // move player left / a
- } else if (keys[68] || keys[39]) {
+ } else if (input.right) {
if (player.velocity.x < mech.airSpeedLimit / player.mass / player.mass) player.force.x += mech.FxAir; //move player right / d
}
},
@@ -860,7 +860,7 @@ const mech = {
},
throwBlock() {
if (mech.holdingTarget) {
- if (keys[32] || game.mouseDownRight) {
+ if (input.field) {
if (mech.energy > 0.001) {
if (mech.fireCDcycle < mech.cycle) mech.fireCDcycle = mech.cycle
mech.energy -= 0.001 / mod.throwChargeRate;
@@ -1234,7 +1234,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
+ } else if ((input.field && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
if (mech.energy > 0.05) {
@@ -1261,7 +1261,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //not hold but field button is pressed
+ } else if ((input.field) && mech.fieldCDcycle < mech.cycle) { //not hold but field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
} else if (mech.holdingTarget && mech.fieldCDcycle < mech.cycle) { //holding, but field button is released
@@ -1311,7 +1311,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
+ } else if ((input.field && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
if (mech.energy > 0.05) {
@@ -1405,7 +1405,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
+ } else if ((input.field && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
if (mech.energy > 0.05) {
@@ -1441,7 +1441,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //push away
+ } else if (input.field && mech.fieldCDcycle < mech.cycle) { //push away
mech.grabPowerUp();
mech.lookForPickUp();
const DRAIN = 0.00035
@@ -1474,12 +1474,12 @@ const mech = {
// zeroG(bullet); //works fine, but not that noticeable and maybe not worth the possible performance hit
// zeroG(mob); //mobs are too irregular to make this work?
- if (keys[83] || keys[40]) { //down
+ if (input.down) { //down
player.force.y -= 0.5 * player.mass * game.g;
this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 400 * 0.03;
zeroG(powerUp, this.fieldDrawRadius, 0.7);
zeroG(body, this.fieldDrawRadius, 0.7);
- } else if (keys[87] || keys[38]) { //up
+ } else if (input.up) { //up
mech.energy -= 5 * DRAIN;
this.fieldDrawRadius = this.fieldDrawRadius * 0.97 + 850 * 0.03;
player.force.y -= 1.45 * player.mass * game.g;
@@ -1497,7 +1497,7 @@ const mech = {
mech.energy = 0;
}
//add extra friction for horizontal motion
- if (keys[65] || keys[68] || keys[37] || keys[39]) {
+ if (input.down || input.up || input.left || input.right) {
Matter.Body.setVelocity(player, {
x: player.velocity.x * 0.99,
y: player.velocity.y * 0.98
@@ -1552,7 +1552,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //not hold but field button is pressed
+ } else if (input.field && mech.fieldCDcycle < mech.cycle) { //not hold but field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
const DRAIN = 0.002
@@ -1710,7 +1710,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
+ } else if (input.field && mech.fieldCDcycle < mech.cycle) {
mech.grabPowerUp();
mech.lookForPickUp(180);
@@ -1807,7 +1807,7 @@ const mech = {
mech.drawHold(mech.holdingTarget);
mech.holding();
mech.throwBlock();
- } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < mech.cycle)) { //not hold and field button is pressed
+ } else if (input.field && mech.fieldCDcycle < mech.cycle) { //not hold and field button is pressed
mech.grabPowerUp();
mech.lookForPickUp();
} else if (mech.holdingTarget && mech.fieldCDcycle < mech.cycle) { //holding target exists, and field button is not pressed
@@ -1869,7 +1869,7 @@ const mech = {
const wiggle = 0.15 * Math.sin(mech.fieldPhase * 0.5)
ctx.beginPath();
ctx.ellipse(mech.pos.x, mech.pos.y, mech.fieldDrawRadius * (1 - wiggle), mech.fieldDrawRadius * (1 + wiggle), mech.fieldPhase, 0, 2 * Math.PI);
- if (mech.fireCDcycle > mech.cycle && (keys[32] || game.mouseDownRight)) {
+ if (mech.fireCDcycle > mech.cycle && (input.field)) {
ctx.lineWidth = 5;
ctx.strokeStyle = `rgba(0, 204, 255,1)`
ctx.stroke()
@@ -1947,7 +1947,7 @@ const mech = {
// const off2 = 1 - 0.06 * Math.sin(mech.fieldPhase);
// ctx.beginPath();
// ctx.ellipse(mech.pos.x, mech.pos.y, radius * off1, radius * off2, rotate, 0, 2 * Math.PI);
- // if (mech.fireCDcycle > mech.cycle && (keys[32] || game.mouseDownRight)) {
+ // if (mech.fireCDcycle > mech.cycle && (input.field)) {
// ctx.lineWidth = 5;
// ctx.strokeStyle = `rgba(0, 204, 255,1)`
// ctx.stroke()
@@ -1969,7 +1969,7 @@ const mech = {
// mech.drawHold(mech.holdingTarget);
// mech.holding();
// mech.throwBlock();
- // } else if (keys[32] || game.mouseDownRight) {
+ // } else if (input.field) {
// mech.grabPowerUp();
// mech.lookForPickUp();
@@ -2083,7 +2083,7 @@ const mech = {
mech.fieldRadius = 0;
mech.drop();
mech.hold = function () {
- if (keys[32] || game.mouseDownRight) {
+ if (input.field) {
if (mech.fieldCDcycle < mech.cycle) {
const scale = 25
const bounds = {
diff --git a/todo.txt b/todo.txt
index 9ac30d1..6586ec5 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,12 +2,17 @@
ice IX thermoelectric energy 66% -> 100%, heal 3%->4%
+new key press detection system
+ I rewrote some fundamental systems so there may be some bugs
+ testing mode death is now shift X (was x+z)
************** TODO - n-gon **************
redo key press around e.key
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
+ mouse event e.which is deprecated
+
time dilation mod rework brain storm
take no damage
can fire