diff --git a/index.html b/index.html
index 74b186c..9d38afe 100644
--- a/index.html
+++ b/index.html
@@ -13,6 +13,7 @@
+
@@ -25,9 +26,10 @@
-
-
-
+
+
+
+
diff --git a/js/Lib/Enemy.js b/js/Lib/Enemy.js
index 5cd11cb..7027e30 100644
--- a/js/Lib/Enemy.js
+++ b/js/Lib/Enemy.js
@@ -12,6 +12,7 @@ class Enemy extends Tank{
this.angle = (Direction[a].getAngle() + PI/2)%(2*PI);
this.counter = 0;
this.fireBullet();
+
}
if(this.position.x + this.width >= WIDTH || this.position.x <= 0){
@@ -21,6 +22,9 @@ class Enemy extends Tank{
if(this.position.y + this.height >=HEIGHT || this.position.y <= 0){
this.velocity.y = -this.velocity.y;
}
+
+
+
this.move(this.velocity);
}
}
\ No newline at end of file
diff --git a/js/Lib/ReactangleCollision.js b/js/Lib/ReactangleCollision.js
new file mode 100644
index 0000000..92c7e6c
--- /dev/null
+++ b/js/Lib/ReactangleCollision.js
@@ -0,0 +1,8 @@
+function RectangleCollision(rect1, rect2){
+ let nearToOrigin = rect1.position.x < rect2.position.x ? rect1:rect2 ;
+ let farToOrigin = rect1.position.x < rect2.position.x ? rect2 :rect1 ;
+ if(farToOrigin.position.x - nearToOrigin.position.x <= nearToOrigin.width &&farToOrigin.position.y - nearToOrigin.position.y<= nearToOrigin.height)
+ return true
+ else return false
+}
+alert();
\ No newline at end of file
diff --git a/js/Lib/RectangleCollision.js b/js/Lib/RectangleCollision.js
new file mode 100644
index 0000000..5a1b77a
--- /dev/null
+++ b/js/Lib/RectangleCollision.js
@@ -0,0 +1,36 @@
+function RectangleCollision(rect1, rect2){
+ let x1 = rect1.position.x;
+ let x2 = rect2.position.x;
+ let y1 = rect1.position.y;
+ let y2 = rect2.position.y;
+ let w1 = rect1.width;
+ let w2 = rect2.width;
+ let h1 = rect1.height;
+ let h2 = rect2.height;
+ let collisionData = {
+ collided : false,
+ collisionDistance : new Vec2(),
+ };
+
+
+ if(x2 + w2 > x1 && x2 < x1 + w1){
+ if(y2 + h2 > y1 && y2 < y1 + h1){
+ if(x1 < x2){
+ collisionData.collisionDistance.x = x1 + w1 - x2;
+ }
+ else{
+ collisionData.collisionDistance.x = x2 + w2 - x1;
+ }
+ if(y1 < y2){
+ collisionData.collisionDistance.y = y1 + h1 - y2;
+ }
+ else{
+ collisionData.collisionDistance.y = y2 + h2 - y1;
+ }
+ collisionData.collided = true;
+ }
+ }
+ return collisionData;
+}
+
+
diff --git a/js/Lib/TankCollision.js b/js/Lib/TankCollision.js
new file mode 100644
index 0000000..e9c6308
--- /dev/null
+++ b/js/Lib/TankCollision.js
@@ -0,0 +1,7 @@
+function RectangleCollision(rect1, rect2){
+ let nearToOrigin = rect1.position.x < rect2.position.x ? rect1:rect2 ;
+ let farToOrigin = rect1.position.x < rect2.position.x ? rect2 :rect1 ;
+ if(farToOrigin.position.x - nearToOrigin.position.x <= nearToOrigin.width &&farToOrigin.position.y - nearToOrigin.position.y<= nearToOrigin.height)
+ return true
+ else return false
+}
\ No newline at end of file
diff --git a/js/init.js b/js/init.js
index 3860388..70e251d 100644
--- a/js/init.js
+++ b/js/init.js
@@ -34,7 +34,7 @@ let WorldSpace = {
const ImageLoader = new ImageLoaderClass();
const audioloader = new AudioLoader();
-const blastSound = audioloader.load('res/sounds/blast.mp3');
+//const destroySound = audioloader.load('res/sounds/destroy.mp3');
const fireSound = audioloader.load('res/sounds/fire.wav');
let playerIsAlive = true;
diff --git a/js/main.js b/js/main.js
index 72e0468..06ed4d3 100644
--- a/js/main.js
+++ b/js/main.js
@@ -8,17 +8,32 @@ Game.update = ()=>{
}
//Check for collisions
+
for(let i = 0; i{
}
//Ending the game
+
if(!playerIsAlive)
Game.pause();
}
@@ -67,3 +83,4 @@ grassGrid.cell[Math.floor(Math.random()*7)][Math.floor(Math.random()*16)].value
}
grassGrid.drawGrid(grassCtx);
+
diff --git a/js/players.js b/js/players.js
index 12a2b12..5509b80 100644
--- a/js/players.js
+++ b/js/players.js
@@ -21,6 +21,26 @@ ImageLoader.onEveryImageLoaded = () => {
enemies[i].loadBullet(bulletImage);
}
+ for(let i = 0; i
+
+
+
+
+
+
+
+
\ No newline at end of file