Skip to content

Commit

Permalink
updated touching functions. Version 1.0 of game complete
Browse files Browse the repository at this point in the history
  • Loading branch information
ncblair committed Oct 8, 2017
1 parent 3a1ffbf commit c650e6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 10 additions & 7 deletions assets/JS/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Canvas {

this.w = width;
this.h = height;

this.context = canvas[0].getContext("2d");
this.context.imageSmoothingEnabled = true;
this.fitToWindow();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -171,7 +172,7 @@ class CanvasListener {
data.set("type", "keypress");
data.set("code", keyState);
chain.delegateJob(data);
setTimeout(broadcastKeyState, 30);
setTimeout(broadcastKeyState, 50);
}
broadcastKeyState();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<div class = "canvas-container"><canvas width = "600" height = "600" id = "game-field"></canvas></div>



<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/JS/script.js"></script>
Expand Down

0 comments on commit c650e6b

Please sign in to comment.