Skip to content

Commit

Permalink
Prototype Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
VRamazing committed Dec 27, 2017
1 parent 70fe3be commit 30cb993
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 78 deletions.
3 changes: 0 additions & 3 deletions js/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class Bullet{

}

// collision(){
//
// }



Expand Down
6 changes: 0 additions & 6 deletions js/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ class Enemy{
if(this.pos.x > canvas.width || this.pos.x < 0 || this.pos.y < 0 || this.pos.y > canvas.height){
this.remove = true;
}



}

shoot(){
bullets.push(new Bullet(this.pos.x,this.pos.y,this.bulletSpeed,this.bulletWidth,this.bulletHeight,this.angle + Math.PI,this.bulletPic,this.bulletType ));

}



}
2 changes: 2 additions & 0 deletions js/graphicsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ function drawBall(centerX,centerY,radius,fillColor) {
}

function colorText(showWords,textX,textY,fillColor,fontface,textAlign = 'left' ) {
ctx.save();
ctx.textAlign = textAlign;
ctx.font = fontface;
ctx.fillStyle = fillColor;
ctx.fillText(showWords, textX, textY);
ctx.restore();
}
18 changes: 16 additions & 2 deletions js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var rightArrowButtonHold = false;

function addInputs(){
document.addEventListener('keydown', function(evt){

if(evt.code == "ArrowLeft"){
leftArrowButtonHold = true;

Expand All @@ -20,9 +20,23 @@ function addInputs(){
//shoot shoot
if(evt.code == "KeyX"){
// shootKeyHold = true;

if(gameOver){
gameReset();
}
else{
satelliteOne.shoot();
satelliteTwo.shoot();
}
}

if(evt.code == "KeyO"){
gameOver =!gameOver;
}

if(evt.code == "KeyD"){
// shootKeyHold = true;

debug = !debug;

}

Expand Down
179 changes: 112 additions & 67 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
satelliteOne,
satelliteTwo,
planetHealth,
score;
score,
gameOver,debug = false;

window.onload = function() {
canvas = document.getElementById('gameCanvas');
Expand All @@ -27,6 +28,7 @@
planetDia = 220;
planetHealth = 100;
score = 0;
gameOver = false;
loadImages();
addInputs();
satelliteOne = new Satellite(pic = blueSatellitePic, bulletPic = blueSatelliteShotPic, type='shield');
Expand All @@ -35,86 +37,116 @@

function drawEverything() {
ctx.drawImage(backgroundPic,0,0); // center, draw
planetAngle += PLANETANGLECHANGE;
drawBitmapCenteredAtLocationWithRotation(planetPic, centerX, centerY, planetAngle);
satelliteOne.move();
satelliteTwo.move();
satelliteOne.draw();
satelliteTwo.draw();


// if(shootKeyHold){
// if(satelliteOneSelected){
// satelliteOne.shoot();
// }
// else{
// satelliteTwo.shoot();
// }
// }
// console.log(bullets);
for(var i = 0; i < bullets.length; i++ ){
// console.log(bullets[i].satObject);

if(SAT.testPolygonPolygon(bullets[i].satObject, satelliteOne.satObject) &&
bullets[i].type == 'enemy'){
bullets[i].remove = true;
satelliteOne.remove = true;
if(!gameOver){
planetAngle += PLANETANGLECHANGE;
drawBitmapCenteredAtLocationWithRotation(planetPic, centerX, centerY, planetAngle);
satelliteOne.move();
satelliteTwo.move();
satelliteOne.draw();
satelliteTwo.draw();

}

if(SAT.testPolygonPolygon(bullets[i].satObject, satelliteTwo.satObject) &&
bullets[i].type == 'enemy'){
bullets[i].remove = true;
satelliteTwo.remove = true;
}
for(var i = 0; i < bullets.length; i++ ){
// console.log(bullets[i].satObject);

if(SAT.testPolygonPolygon(bullets[i].satObject, satelliteOne.satObject) &&
bullets[i].type == 'enemy'){
bullets[i].remove = true;
satelliteOne.lives--;
}

if(SAT.testPolygonPolygon(bullets[i].satObject, satelliteTwo.satObject) &&
bullets[i].type == 'enemy'){
bullets[i].remove = true;
satelliteTwo.lives--;

for(var j = 0; j < enemies.length; j++){
}

if(SAT.testPolygonPolygon(bullets[i].satObject, enemies[j].satObject) && bullets[i].type == 'satellite'){
bullets[i].remove = true;
enemies[j].remove = true;
for(var j = 0; j < enemies.length; j++){

if(SAT.testPolygonPolygon(bullets[i].satObject, enemies[j].satObject) && bullets[i].type == 'satellite'){
bullets[i].remove = true;
enemies[j].remove = true;
score += 20;
}
}
}

for(var j = 0; j < enemies.length; j++){

if(SAT.testPolygonPolygon(satelliteOne.satObject, enemies[j].satObject)){
satelliteOne.lives--;
enemies[j].remove = true;
score += 20;
}
if(SAT.testPolygonPolygon(satelliteTwo.satObject, enemies[j].satObject)){
satelliteTwo.lives--;
enemies[j].remove = true;
score += 20;
}
}

if(satelliteOne.lives<=0){
satelliteOne.remove = true;
}

}
if(satelliteTwo.lives<=0){
satelliteTwo.remove = true;
}

for(var i = 0; i < bullets.length; i++ ){
if(!bullets[i].remove){
bullets[i].draw();
if(satelliteTwo.lives<=0 && satelliteOne.lives<=0){
gameOver = true;
}

}

for(var i = 0; i < bullets.length; i++ ){
if(bullets[i].remove){
bullets.splice(i,1);
for(var i = 0; i < bullets.length; i++ ){
if(!bullets[i].remove){
bullets[i].draw();
}

}

}
for(var i = 0; i < bullets.length; i++ ){
if(bullets[i].remove){
bullets.splice(i,1);
}

for(var i = 0; i < enemies.length; i++){
if(!enemies[i].remove){
enemies[i].draw();
}

}
for(var i = 0; i < enemies.length; i++){
if(!enemies[i].remove){
enemies[i].draw();
}

for(var i = 0; i < enemies.length; i++ ){
if(enemies[i].remove){
enemies.splice(i,1);
}

}
for(var i = 0; i < enemies.length; i++ ){
if(enemies[i].remove){
enemies.splice(i,1);
}

colorText("Bullets: " + bullets.length,5,10,"white","Arial");
colorText("Enemies: " + enemies.length,5,20,"white","Arial");
colorText("Planet Health: " + planetHealth,5,30,"white","Arial");
colorText("Score: " + score,5,40,"white","Arial");
}

colorText("Planet Health: " + planetHealth,5,30,"white","30px Arial");
colorText("Score: " + score,5,60,"white","20px Arial",);
colorText("Satellite-1 Life: " + satelliteOne.lives,5,90,"white","20px Arial");
colorText("Satellite-2 Life: " + satelliteTwo.lives,5,120,"white","20px Arial");

if(debug){
colorText("Bullets: " + bullets.length,5,150,"white","Arial");
colorText("Enemies: " + enemies.length,5,180,"white","Arial");

}

if(planetHealth <= 0){
gameOver = true;
}

}
else{
colorText("Final Score - " + score, canvas.width/2 , canvas.height/2 - 60 ,"white"," 50px Arial","center");
colorText("Game Over . Press X to restart", canvas.width/2 , canvas.height/2,"white"," 40px Arial","center");
}


}
Expand All @@ -126,20 +158,33 @@ function loadingDoneSoStartGame(){

}, 1000/framesPerSecond);

setInterval(function() {
enemies.push(new Enemy());
if(!gameOver){
setInterval(function() {
enemies.push(new Enemy());

}, 3000); //2000
setInterval(function() {
for(var i = 0; i < enemies.length; i++ ){
enemies[i].shoot();
}, 3000); //2000
setInterval(function() {
for(var i = 0; i < enemies.length; i++ ){
enemies[i].shoot();

}
}

}, 2500); //2500
setInterval(function() {
score+=10;
}, 2500); //2500
// setInterval(function() {
// score+=10;
//
// }, 4000); //2500
}

}, 4000); //2500

}

function gameReset(){
planetHealth = 100;
score = 0;
gameOver = false;
satelliteOne = new Satellite(pic = blueSatellitePic, bulletPic = blueSatelliteShotPic, type='shield');
satelliteTwo = new Satellite(pic = yellowSatellitePic, bulletPic = yellowSatelliteShotPic, type='shooter');
bullets = [];
enemies = [];
}
1 change: 1 addition & 0 deletions js/satellite.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Satellite{
this.bulletHeight = 10;
this.bulletPic = bulletPic;
this.bulletType = 'satellite';
this.lives = 3;
//satObject need an initial minimum points //Drawn from bottom.
// this.initlalSatObject = new SAT.Box(new SAT.Vector(this.pos.x - this.width/2 , this.pos.y + this.height/2), this.width, this.height).toPolygon();
this.satObject;
Expand Down

0 comments on commit 30cb993

Please sign in to comment.