i was bored and wanted to make a joke
I was bored and I wanted to make a game for my friend
by Nathan Piper
HTML
<canvas id='cool' width=500 height=400 style='border: 1px solid black'/>
CSS
canvas{
}
JavaScript
var width = 500;
var height = 400;
var FPS = 60;
var bullets = [];
var shootTimer = 0;
var maxShootTimer = 0;
var g = document.getElementById('cool').getContext('2d');
var top = {
x: width/2 - 15,
y: height/2 - 90,
width: 15,
canShoot: true,
speed: 4,
height: 90,
render: function () {
g.fillStyle = 'black';
g.fillRect(this.x, this.y, this.width, this.height);
},
tick: function () {
if(Key.up && this.y > -80 && collision(top, leftV) == false &&
collision(top, rightV) == false) this.y -= this.speed;
if(Key.down && this.y < height-110) this.y += this.speed;
if(Key.left && this.x > 30 && collision(leftB, leftV) == false &&
collision(top, leftV) == false) this.x -= this.speed;
if(Key.right && this.x < width-45 && collision(rightB, rightV) == false && collision(top, rightV) == false) this.x += this.speed;
if(Key.space && this.canShoot) {
this.canShoot = false;
bullets.push(new Bullet(this.x + this.width/2, this.y - 4));
shootTimer = maxShootTimer;
}
}
}
var rightB = {
x: width/2 + 0,
y: height/2 - 10,
width: 30,
speed: 4,
height: 30,
render: function () {
g.fillStyle = 'black';
g.fillRect(this.x, this.y, this.width, this.height);
},
tick: function () {
if(Key.up && this.y > 0 && collision(top, leftV) == false &&
collision(top, rightV) == false) this.y -= this.speed;
if(Key.down && this.y < height-30) this.y += this.speed;
if(Key.left && this.x > 45 && collision(leftB, leftV) == false &&
collision(top, leftV) == false) this.x -= this.speed;
if(Key.right && this.x < width-30 && collision(rightB, rightV) == false &&
collision(top, rightV) == false) this.x += this.speed;
}
}
var leftB = {
x: width/2 -45,
...