Konstantinos-infogeek
3/22/2012 - 6:25 PM

javascript

javascript

/*

Created by:   Konstantinos Tsatsarounos
Title:        Simple Game

Created for:  infogeek.gr Tutorials 

Description : Click and it generates a winged falling 'O'. if O falls to the center of the page it changes into a dot and adds 50points to the boarder at the top-right of the page!!!

*/


window.addEventListener('click', showEvent, false);
var centerX = window.innerWidth/2, centerY= window.innerHeight;

var scoreL = document.createElement('label'), score=0; scoreL.innerHTML = score; scoreL.style.position = 'absolute'; scoreL.style.top = '10px'; scoreL.style.right = '10px';
document.body.appendChild(scoreL);

function showEvent(e){

	var div = document.createElement('div'), x =e.clientX, y=e.clientY, i=1;
	div.innerHTML = '\/-O-\/';
	div.style.color = '#ffffff';
	div.style.fontWeight = 'bold';
	div.style.position = 'absolute';
	div.style.left = x+'px';
	div.style.top = y+'px';
	document.body.appendChild(div);
    
	var moveHandler = setInterval(function(){
		if(y<centerY){		div.style.top = y+'px'; y++,i++;
				if(y==centerY/2 && x<=centerX+50 && x>=centerX-50){ 
							clearInterval(moveHandler);
							div.innerHTML='.'; score+=50;scoreL.innerHTML=score;}

		 }
		else{ clearInterval(moveHandler);


		}

	},10)

	}