-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving things around and adding SOTB13 files
- Loading branch information
1 parent
65f78b6
commit b1e5f5a
Showing
26 changed files
with
1,606 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE HTML> | ||
<html lang="en"> | ||
<meta charset="utf-8"> | ||
<head> | ||
<title>Invaders</title> | ||
<style type="text/css"> | ||
body { | ||
background-color:black; | ||
margin:0px; | ||
overflow : hidden; | ||
text-align:center; | ||
} | ||
canvas { | ||
padding:auto; | ||
|
||
} | ||
</style> | ||
</head> | ||
|
||
|
||
<body> | ||
<script src="../libs/creativejs.js"></script> | ||
<script src="../libs/Vector2.js"></script> | ||
<script src="../libs/KeyTracker.js"></script> | ||
<script src="InvadersGame.js"></script> | ||
|
||
|
||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
|
||
var canvas, ctx, | ||
leftDown, rightDown; | ||
|
||
var playerShip, | ||
invaders, | ||
bullets, particles; | ||
|
||
var screenHeight, screenWidth; | ||
|
||
init(); | ||
|
||
function init() { | ||
|
||
screenWidth = window.innerWidth; | ||
screenHeight = window.innerHeight; | ||
|
||
canvas = document.createElement('canvas'); | ||
document.body.appendChild(canvas); | ||
canvas.width = screenWidth; | ||
canvas.height = screenHeight; | ||
ctx = canvas.getContext('2d'); | ||
|
||
window.addEventListener('keydown', keyDown); | ||
window.addEventListener('keyup', keyUp); | ||
|
||
playerShip = new PlayerShip(screenWidth/2,screenHeight-80); | ||
|
||
bullets = []; | ||
particles = []; | ||
resetInvaders(); | ||
|
||
setInterval(loop, 1000/50); | ||
|
||
} | ||
|
||
function loop() { | ||
ctx.clearRect(0,0,screenWidth, screenHeight); | ||
checkKeys(); | ||
|
||
updateBullets(); | ||
|
||
checkCollisions(); | ||
|
||
|
||
|
||
renderBullets(); | ||
renderInvaders(); | ||
updateParticles(); | ||
playerShip.render(ctx); | ||
} | ||
|
||
function checkCollisions() { | ||
|
||
|
||
for(var i = 0; i<bullets.length; i++) { | ||
var bullet = bullets[i]; | ||
|
||
for(var j = 0; j<invaders.length; j++) { | ||
var invader = invaders[j]; | ||
|
||
if( (bullet.x > invader.x) && (bullet.x < invader.x + invader.width) | ||
&& (bullet.y >invader.y) && (bullet.y < invader.y +invader.height)) { | ||
|
||
invaders.splice(j, 1); | ||
j--; | ||
bullets.splice(i,1); | ||
i--; | ||
|
||
makeExplosion(invader.x +invader.width/2, invader.y+invader.height/2) | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
function resetInvaders() { | ||
invaders = []; | ||
|
||
for(var col = 0; col <10; col++) { | ||
for(var row = 0; row<4; row++ ) { | ||
var invader = new Invader(col * 80, row*60); | ||
invaders.push(invader); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
function updateBullets() { | ||
for(var i =0; i<bullets.length; i++) { | ||
|
||
bullets[i].update(); | ||
} | ||
|
||
|
||
} | ||
function renderBullets() { | ||
for(var i =0; i<bullets.length; i++) { | ||
|
||
bullets[i].render(ctx); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
function updateParticles() { | ||
for(var i =0; i<particles.length; i++) { | ||
particles[i].update(); | ||
particles[i].render(ctx); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
function renderInvaders() { | ||
for(var i =0; i<invaders.length; i++) { | ||
|
||
invaders[i].render(ctx); | ||
} | ||
|
||
|
||
} | ||
|
||
function checkKeys() { | ||
|
||
if(leftDown) { | ||
playerShip.x -=10; | ||
} else if(rightDown) { | ||
playerShip.x +=10; | ||
} | ||
|
||
} | ||
|
||
function keyDown(e) { | ||
|
||
if(e.keyCode == 37) { | ||
leftDown = true; | ||
} else if (e.keyCode == 39) { | ||
rightDown = true; | ||
} | ||
|
||
if(e.keyCode == 32) { | ||
var bullet = new Bullet(playerShip.x + playerShip.width/2, playerShip.y); | ||
bullets.push(bullet); | ||
} | ||
} | ||
|
||
function keyUp(e) { | ||
|
||
if(e.keyCode == 37) { | ||
leftDown = false; | ||
} else if (e.keyCode == 39) { | ||
rightDown = false; | ||
} | ||
} | ||
|
||
|
||
function PlayerShip(x, y) { | ||
|
||
this.x = x; | ||
this.y = y; | ||
this.width = 60; | ||
this.height = 40; | ||
|
||
this.render = function (ctx) { | ||
ctx.fillStyle = 'white'; | ||
ctx.fillRect(this.x, this.y, this.width, this.height); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
function Bullet(x, y) { | ||
|
||
this.x = x; | ||
this.y = y; | ||
|
||
this.update = function () { | ||
this.y -=20; | ||
|
||
|
||
} | ||
this.render = function (ctx) { | ||
ctx.fillStyle = 'white'; | ||
ctx.fillRect(this.x, this.y, 4,10); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
function Invader(x, y) { | ||
|
||
this.x = x; | ||
this.y = y; | ||
this.width = 60; | ||
this.height = 40; | ||
|
||
this.render = function (ctx) { | ||
ctx.fillStyle = 'red'; | ||
ctx.fillRect(this.x, this.y, this.width, this.height); | ||
} | ||
|
||
} | ||
function Particle(x, y) { | ||
|
||
this.x = x; | ||
this.y = y; | ||
this.velX = Math.random()* 20 -10; | ||
this.velY = Math.random()* 20 -10; | ||
this.size = 10; | ||
this.update = function() { | ||
this.x += this.velX; | ||
this.y += this.velY; | ||
|
||
} | ||
this.render = function (ctx) { | ||
ctx.fillStyle = 'red'; | ||
ctx.fillRect(this.x, this.y, this.size, this.size); | ||
} | ||
|
||
} | ||
|
||
function makeExplosion(x, y) { | ||
for(var i = 0; i<100; i++ ) { | ||
|
||
var p = new Particle(x,y); | ||
particles.push(p); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE HTML> | ||
<html lang="en"> | ||
<meta charset="utf-8"> | ||
<head> | ||
<title>Invaders</title> | ||
<style type="text/css"> | ||
body { | ||
background-color:black; | ||
margin:0px; | ||
overflow : hidden; | ||
text-align:center; | ||
} | ||
canvas { | ||
padding:auto; | ||
|
||
} | ||
</style> | ||
</head> | ||
|
||
|
||
<body> | ||
<script src="../libs/creativejs.js"></script> | ||
<script src="../libs/Vector2.js"></script> | ||
<script src="../libs/KeyTracker.js"></script> | ||
<script src="InvadersGame.js"></script> | ||
|
||
|
||
</body> | ||
</html> | ||
|
Oops, something went wrong.