From c650e6b28325e7db0af1286dcd5b30ecde6cdd55 Mon Sep 17 00:00:00 2001 From: Nathan Blair Date: Sun, 8 Oct 2017 13:32:47 -0700 Subject: [PATCH] updated touching functions. Version 1.0 of game complete --- assets/JS/script.js | 17 ++++++++++------- index.html | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/assets/JS/script.js b/assets/JS/script.js index b895fca..52657cf 100644 --- a/assets/JS/script.js +++ b/assets/JS/script.js @@ -26,6 +26,7 @@ class Canvas { this.w = width; this.h = height; + this.context = canvas[0].getContext("2d"); this.context.imageSmoothingEnabled = true; this.fitToWindow(); @@ -98,7 +99,7 @@ class Canvas { } clear() { - this.context.clearRect(0, 0, this.h, this.w); + this.context.clearRect(0, 0, this.w, this.h); } } @@ -128,7 +129,7 @@ class Engine { //render this.render(); //update - setInterval(this.update.bind(this), 35); + setInterval(this.update.bind(this), 50); } update() { for (let element of this.elements) { @@ -171,7 +172,7 @@ class CanvasListener { data.set("type", "keypress"); data.set("code", keyState); chain.delegateJob(data); - setTimeout(broadcastKeyState, 30); + setTimeout(broadcastKeyState, 50); } broadcastKeyState(); @@ -537,6 +538,7 @@ class LandmineNetwork extends ArenaAbstraction { } + occupiedBlocks() { //iterates through this.walls and adds each of the walls occupied blocks var occupied = new Set(); @@ -749,12 +751,13 @@ class ArenaSquare extends ArenaElem { } super(size, colr, location, makeSquare); } - - distanceTo(that) { + isTouching(that) { if (that instanceof ArenaSquare) { - return this.location.distanceTo(that.location) - this.size - that.size; + //checks bounding boxes; + return Math.abs(this.location.x - that.location.x) < (this.size + that.size) && Math.abs(this.location.y - that.location.y) < (this.size + that.size) + } else { + return super.isTouching(that); } - return super.distanceTo(that); } } diff --git a/index.html b/index.html index d000c09..88f2acb 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,6 @@
-