c = document.getElementById('c'),
ctx = c.getContext('2d');
ctx.fillStyle = '#d0e7f9';
ctx.clearRect(0, 0, width, height);
ctx.rect(0, 0, width, height);
var howManyCircles = 10, circles = [];
for (var i = 0; i < howManyCircles; i++)
circles.push([Math.random() * width, Math.random() * height, Math.random() * 100, Math.random() / 2]);
var DrawCircles = function(){
for (var i = 0; i < howManyCircles; i++) {
ctx.fillStyle = 'rgba(255, 255, 255, ' + circles[i][3] + ')';
ctx.arc(circles[i][0], circles[i][1], circles[i][2], 0, Math.PI * 2, true);
var MoveCircles = function(e){
for (var i = 0; i < howManyCircles; i++) {
if (circles[i][1] - circles[i][2] > height) {
circles[i][0] = Math.random() * width;
circles[i][2] = Math.random() * 100;
circles[i][1] = 0 - circles[i][2];
circles[i][3] = Math.random() / 2;
var player = new (function(){
that.image = new Image();
that.image.src = "http://images.virtualdesign.pl/images/99444maluszek.png"
if (!that.isJumping && !that.isFalling) {
that.checkJump = function() {
if (that.Y > height*0.4) {
that.setPosition(that.X, that.Y - that.jumpSpeed);
MoveCircles(that.jumpSpeed * 0.5);
platforms.forEach(function(platform, ind){
platform.y += that.jumpSpeed;
if (platform.y > height) {
var type = ~~(Math.random() * 5);
platforms[ind] = new Platform(Math.random() * (width - platformWidth), platform.y - height, type);
if (that.jumpSpeed == 0) {
that.fallStop = function(){
that.checkFall = function(){
if (that.Y < height - that.height) {
that.setPosition(that.X, that.Y + that.fallSpeed);
that.moveLeft = function(){
that.setPosition(that.X - 5, that.Y);
that.moveRight = function(){
if (that.X + that.width < width) {
that.setPosition(that.X + 5, that.Y);
that.setPosition = function(x, y){
ctx.drawImage(that.image, 0, that.height * that.actualFrame, that.width, that.height, that.X, that.Y, that.width, that.height);
if (that.interval == 4 ) {
if (that.actualFrame == that.frames) {
player.setPosition(~~((width-player.width)/2), height - player.height);
document.onmousemove = function(e){
if (player.X + c.offsetLeft > e.pageX) {
} else if (player.X + c.offsetLeft < e.pageX) {
var Platform = function(x, y, type){
that.firstColor = '#FF8C00';
that.secondColor = '#EEEE00';
that.onCollide = function(){
that.firstColor = '#AADD00';
that.secondColor = '#698B22';
that.onCollide = function(){
that.isMoving = ~~(Math.random() * 2);
that.direction= ~~(Math.random() * 2) ? -1 : 1;
ctx.fillStyle = 'rgba(255, 255, 255, 1)';
var gradient = ctx.createRadialGradient(that.x + (platformWidth/2), that.y + (platformHeight/2), 5, that.x + (platformWidth/2), that.y + (platformHeight/2), 45);
gradient.addColorStop(0, that.firstColor);
gradient.addColorStop(1, that.secondColor);
ctx.fillStyle = gradient;
ctx.fillRect(that.x, that.y, platformWidth, platformHeight);
var generatePlatforms = function(){
for (var i = 0; i < nrOfPlatforms; i++) {
type = ~~(Math.random()*5);
platforms[i] = new Platform(Math.random() * (width - platformWidth), position, type);
if (position < height - platformHeight)
position += ~~(height / nrOfPlatforms);
var checkCollision = function(){
platforms.forEach(function(e, ind){
(player.X < e.x + platformWidth) &&
(player.X + player.width > e.x) &&
(player.Y + player.height > e.y) &&
(player.Y + player.height < e.y + platformHeight)
var GameLoop = function(){
if (player.isJumping) player.checkJump();
if (player.isFalling) player.checkFall();
platforms.forEach(function(platform, index){
} else if (platform.x > width - platformWidth) {
platform.x += platform.direction * (index / 2) * ~~(points / 100);
ctx.fillText("POINTS:" + points, 10, height-10);
gLoop = setTimeout(GameLoop, 1000 / 50);
var GameOver = function(){
ctx.fillText("GAME OVER", width / 2 - 60, height / 2 - 50);
ctx.fillText("YOUR RESULT:" + points, width / 2 - 60, height / 2 - 30);