<Array>
<Array>
<Array>
<Array>Cool Game<Array>
<Array>
<Array>
<Array>
<Array>
<Array>
<Array>
<Array>
<Array>
<Array><Array>
<Array>
(function() {
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
width = 300,
height = 400,
score = 0,
highScore = 0,
dead = false,
player = {
colX : 10,
colY : 10,
width : 50,
height : 50,
centerX : 50/2,
centerY : 50/2,
x : width/2,
y : height - 5,
speed: 50,
accel : 1.5,
velX: 0,
velY: 0,
},
keys = [],
friction = 0.8,
gravity = 0.1;
var spike = {
x: width*Math.random(),
y: 0,
colX :10,
colY : 10,
width : 40,
height : 40,
centerX : 40/2,
centerY : 40/2,
speed: 4,
velY: 0,
}
canvas.width = width;
canvas.height = height;
// load sprites
var playerImg = document.getElementById("player_right");
var pokeBall = document.getElementById("pokeBall");
//create functions for the game
function collision(col1,col2){
if(Math.abs(col1.y-col2.y) <Array>= height){
spike.y = 0-spike.height;
spike.velY = 0;
spike.x = (width-spike.width)*Math.random()+spike.centerX;
score += 1
gravity += 0.01;
}
else{
spike.velY += gravity;
}
//player inputs
if(dead ==false){
// check keys
// if (keys[38]) {
// up arrow or space
// if(!player.jumping){
// player.jumping = true;
// player.velY = -player.jumpSpeed;
// }
// }
if (keys[39]) {
// right arrow
if (player.velX <Array> -player.speed) {
player.velX-=player.accel ;
}
}
}
player.velX *= friction;
player.velY += gravity;
player.x += player.velX;
player.y += player.velY;
spike.y += spike.velY;
if (player.x >= width-player.colX) {
player.x = width-player.colX;
} else if (player.x-player.colX <Array>= 310-player.colY){
player.y = 310-player.colY;
player.jumping = false;
}
//clear all stuff
ctx.clearRect(0,0,width,height);
//draw background
ctx.drawImage(background,0, 0, 600, height);
//draw spikes
ctx.drawImage(pokeBall,(spike.x-spike.centerX), (spike.y-spike.centerY), spike.width, spike.height);
//draw player
if(player.velX >0){
playerImg = document.getElementById("player_right");
}
if(player.velX<Array> highScore){
highScore = score;
}
}
if (keys[16] && dead==true){
score = 0;
dead = false;
}
requestAnimationFrame(update);
}
document.body.addEventListener("keydown", function(e) {
keys[e.keyCode] = true;
});
document.body.addEventListener("keyup", function(e) {
keys[e.keyCode] = false;
});
window.addEventListener("load",function(){
update();
});
<Array>
<Array>
<Array>