	var time = 0;
	var now = 0;
	var dt = 0;
	
	var next_time = 0;
	var initial_time = 0;
	var elapsed_time = 0;
	
	var time_initial;
	var time_final;
	
	var girlanimationtime;
	var girlcurrenttime;
	var girlelapsedtime;
	
	var canvas;
	var ctx;
	
	var width = width;
	var height = height;
	
	var _whichscreen;
	
	var SPLASHSCREEN = 0;
	var POSTERSCREEN = 1;
	var MENUSCREEN = 2;
	var ABOUTSCREEN = 3;
	var HELPSCREEN = 4;
	var GAMESCREEN = 5;
	var PAUSESCREEN = 6;
	
	var backgroundimg;
	var crosslineimg;
	var splash;
	var poster;
	var menu;
	var about;
	var help;
	var gameoverimg;
	var stage2start;
	var stage3start;
	var endframeimg;
	var failtoprotectimg;
	
	var isgameover = false;
	
	var playmenu;
	var aboutmenu;
	var helpmenu;
	
	var nexticon;
	var backicon;
	
	var menustrip;
	var leftpunch;
	var rightpunch;

	var leftarrow;
	var rightarrow;
	var uparrow;
	var downarrow;
	
	var marker;
	var markerarray;
	
	var lifeimg;
	var lifearray;

	var pausebtn;
	var ispausebtnvisible = true;
	
	var gamebackground;
	
	var girlleft;
	var girlright;
	var girl;
	var girlrightdir = true;
	var girlleftdir = false;
	
	var girlanim = new Array();

	var isgirlvisible = true;
	
	
	var mainmenuicon;
	var resumeicon;
	var replayicon;
	
	var rect;
	var pointerx;
	var pointery;
	
	var girlcoordx = width/2 - 32;
	var girlcoordy = height-64;
	var girlcounter = 0;
	
	///hero images
	
	var heroimage;
	var heroanimcounter;
	
	var heroupwalkimg;
	var heroupleftpunchimg;
	var herouprightpunchimg;
	var heroupfaintedimg;
	
	var heroupwalkarray = new Array();
	var herouppunchleftarray = new Array();
	var herouppunchrightarray = new Array();
	var heroupfaintedarray = new Array();
	
	var heroupwalkcounter = 0;
	var herouppunchcounter = 0;
	var heroupfaintedcounter = 0;

////////////////////
	var herodownwalkimg;
	var herodownleftpunchimg;
	var herodownrightpunchimg;
	var herodownfaintedimg;
	
	var herodownwalkarray = new Array();
	var herodownpunchleftarray = new Array();
	var herodownpunchrightarray = new Array();
	var herodownfaintedarray = new Array();
	
	var herodownwalkcounter = 0;
	var herodownpunchcounter = 0;
	var herodownfaintedcounter = 0;

//////////////////////
	var heroleftwalkimg;
	var heroleftleftpunchimg;
	var heroleftrightpunchimg;
	var heroleftfaintedimg;
	
	var heroleftwalkarray = new Array();
	var heroleftpunchleftarray = new Array();
	var heroleftpunchrightarray = new Array();
	var heroleftfaintedarray = new Array();
	
	var heroleftwalkcounter = 0;
	var heroleftpunchcounter = 0;
	var heroleftfaintedcounter = 0;


/////////////////////////
	var herorightwalkimg;
	var herorightleftpunchimg;
	var herorightrightpunchimg;
	var herorightfaintedimg;
	
	var herorightwalkarray = new Array();
	var herorightpunchleftarray = new Array();
	var herorightpunchrightarray = new Array();
	var herorightfaintedarray = new Array();
	
	var herorightwalkcounter = 0;
	var herorightpunchcounter = 0;
	var herorightfaintedcounter = 0;

//////////////////////////
	
    var heroxcoord;
    var heroycoord;
	var isherovisible = true;
	
	var ispointerpressed;
    
    var leftwalk = false;
    var rightwalk = false;
    var upwalk = false;
    var downwalk = false;

    var heroupleftpunch = false;
    var herouprightpunch = false;

    var herodownleftpunch = false;
    var herodownrightpunch = false;

    var heroleftleftpunch = false;
    var heroleftrightpunch = false;

    var herorightleftpunch = false;
    var herorightrightpunch = false;
	
    var heroleftdir = false;
    var herorightdir = false;
    var heroupdir = true;
    var herodowndir = false;
	
	var isherofainted = false;
	var isherofaintanimate = false;
	
	var leftarrowx = 0;
	var leftarrowy = 0;

	var rightarrowx = 0;
	var rightarrowy = 0;

	var uparrowx = 0;
	var uparrowy = 0;

	var downarrowx = 0;
	var downarrowy = 0;
	
	var leftpunchx = 0;
	var leftpunchy = 0;

	var rightpunchx = 0;
	var rightpunchy = 0;
	
	var isuivisible = true;
	
	var isreplaygame = false;
	
	
	var punchsound;
	var punchsoundhowler;
	
////////////////////////////////////
/////////////////sikdi	
///////////////////////////////////
	var sikdiuppunch;
	var sikdiupfainted;

	var sikdidownwalk;
	var sikdidownpunch;
	var sikdidownfainted;


	var sikdileftpunch;
	var sikdileftfainted;

	var sikdirightpunch;
	var sikdirightfainted;
	
	var sikdimotion = new Array();
	var sikdimotionfainted = new Array();
	
///////takla
	var taklauppunch;
	var taklaupfainted;

	var takladownwalk;
	var takladownpunch;
	var takladownfainted;


	var taklaleftpunch;
	var taklaleftfainted;

	var taklarightpunch;
	var taklarightfainted;
	
	var taklamotion = new Array();
	var taklamotionfainted = new Array();

//////////////	
///////fatty
	var fattyuppunch;
	var fattyupfainted;

	var fattydownwalk;
	var fattydownpunch;
	var fattydownfainted;


	var fattyleftpunch;
	var fattyleftfainted;

	var fattyrightpunch;
	var fattyrightfainted;
	
	var fattymotion = new Array();
	var fattymotionfainted = new Array();

//////////////	
	
	var isvillainvisible = new Array();

	var sikdiarray = new Array();
	var taklaarray = new Array();
	var fattyarray = new Array();
	
	var stage;
	var STAGE_ONE;
	var STAGE_TWO;
	var STAGE_THREE;
	
	
	/////////////// game variable
    var sikdiindex = 0;
    var sikdifainted = 0;
	var	issikdishown = true;

	
    var taklaindex = 0;
	var taklafainted = 0;
	var	istaklashown = false;
	
    var fattyindex = 0;
    var fattyfainted = 0;
	var	isfattyshown = false;

    var herohealth = 200;
    var isherodisabled = false;
    var LIFE = 3;

    var showfailedmessage = false;
    var failtoprotect = false;

    var messageshown = false;
    var messagestarttime;
    var messageendtime;

    var lifetemp;
    var isnextstagemsgvisble = false;

	
    var isgamescreenimagescreated;

	var randomxcoord;

    var coordx = new Array();
    var coordy = new Array();
    var dirleft = new Array();
    var dirright = new Array();
    var dirup = new Array();
    var dirdown = new Array();
    var inrange = new Array();
    var villainhealth = new Array();
    var ishero_outofrange = new Array();
    var faintedcounter = new Array();
    var faintedcounted = new Array();
	
	///////////////////////////
	var sikdi = new Array();
	var takla = new Array();
	var fatty = new Array();
	
	var isengageinfight = new Array();
	
	
	var sikdicounter;
	var sikdihit = 1;

	var taklacounter;
	var taklahit = 2;

	var fattycounter;
	var fattyhit = 4;
	
	var isvillainfainted;
	
    var SIKDIHURT = 15;
    var TAKLAHURT = 5;
    var FATTYHURT = 3;
	
	////////////////////////////
	var ANIMATIONCOUNTERLIMIT;
	
	var isendgame;
	
	var screenwidth;
	var screenheight;

	localStorage.counters = "1";
	
	
	
(function() {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
    }
 
    if (!window.requestAnimationFrame)
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); },
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };
 
    if (!window.cancelAnimationFrame)
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
}());

window.oncontextmenu = function(event) {
	event.preventDefault();
	event.stopPropagation();
	return false;
};

/*function preventLongPressMenu(nodes) {
	for(var i=0; i<nodes.length; i++){
		nodes[i].ontouchstart = absorbEvent_;
		nodes[i].ontouchmove = absorbEvent_;
		nodes[i].ontouchend = absorbEvent_;
		nodes[i].ontouchcancel = absorbEvent_;
	}
}

function absorbEvent_(event) {
	var e = event || window.event;
	e.preventDefault && e.preventDefault();
	e.stopPropagation && e.stopPropagation();
	e.cancelBubble = true;
	e.returnValue = false;
	return false;
}
*/

var hyperlink = document.getElementById("vservadvt1").querySelector("a");
if(hyperlink == null)
{
	alert("No internet connection or advertisment is not display. \nPlz check your Internet connection and restart game.");
}
else
{
	function init()
	{

//		preventLongPressMenu(document.getElementsByTagName('canvas'));
	
		screenwidth = window.innerWidth;

		if(screenwidth >= 640)
			screenwidth = (window.innerWidth - 30)/3;

		screenheight = window.innerHeight - 30;

		width = screenwidth;
		height = screenheight;


		time = 0;
		now = 0;
		dt = 0;

		initial_time = parseInt(new Date().getTime()/1000);
		
		time_initial = new Array();
		time_final = new Array();
		
		for(i=0;i<20;i++)
		{
			time_initial[i] = parseInt(new Date().getTime());
			time_final[i] = 0;
		}
		
		next_time = 0;
		elapsed_time = 0;
		
		crosslineimg = document.getElementById("crosslineimg");
		splash = document.getElementById("splash");
		poster = document.getElementById("poster");
		menu = document.getElementById("menu");
		about = document.getElementById("about");
		help = document.getElementById("help");
		gameoverimg = document.getElementById("gameoverimg");
		stage2start = document.getElementById("stage2start");
		stage3start = document.getElementById("stage3start");
		endframeimg = document.getElementById("endframeimg");
		failtoprotectimg = document.getElementById("failtoprotectimg");
		
		isgameover = false;
		
		
		playmenu = document.getElementById("playmenu");
		aboutmenu = document.getElementById("aboutmenu");
		helpmenu = document.getElementById("helpmenu");
		
		backicon = document.getElementById("backbtn");
		nexticon = document.getElementById("nextbtn");
		
		menustrip = document.getElementById("menustrip");
		leftpunch = document.getElementById("leftpunch");
		rightpunch = document.getElementById("rightpunch");

		leftarrow = document.getElementById("leftarrow");
		rightarrow = document.getElementById("rightarrow");
		uparrow = document.getElementById("uparrow");
		downarrow = document.getElementById("downarrow");
		
		marker = document.getElementById("marker");
		lifeimg = document.getElementById("life");
		
		markerarray = 0;
		lifearray = [0, 32, 64, 96];
		
		pausebtn = document.getElementById("pausebtn");
		ispausebtnvisible = true;
		
		
		gamebackground = document.getElementById("gamebackground");

		mainmenuicon = document.getElementById("mainmenuicon");
		resumeicon = document.getElementById("resumeicon");
		replayicon = document.getElementById("replayicon");

		girlleft = document.getElementById("girlleft");
		girlright = document.getElementById("girlright");
		
		girlcounter = 0;
		girlanim = [0, 64, 128, 192];
		girl = girlright;
		girl.className = "girlright";
		
		girlanimationtime = 0;
		girlcurrenttime = 0;
		girlelapsedtime = 0;
	
		girlcoordx = width/2 - 32;
		girlcoordy = height-64;

		
		//hero images
		heroanimcounter = 0;

		
		
		heroupwalkimg = document.getElementById("heroupwalk");
		heroupleftpunchimg = document.getElementById("heroupleftpunch");
		herouprightpunchimg = document.getElementById("herouprightpunch");
		heroupfaintedimg = document.getElementById("heroupfainted");
		
		heroimage = heroupwalkimg;
		
		heroupwalkarray = [0, 64, 128, 192];
		herouppunchleftarray = [0, 64];
		herouppunchrightarray = [0, 64];
		heroupfaintedarray = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896];

		heroupwalkcounter = 0;
		herouppunchcounter = 0;
		heroupfaintedcounter = 0;
/////////////////////////////////////////
		herodownwalkimg = document.getElementById("herodownwalk");
		herodownleftpunchimg = document.getElementById("herodownleftpunch");
		herodownrightpunchimg = document.getElementById("herodownrightpunch");
		herodownfaintedimg = document.getElementById("herodownfainted");
		
		herodownwalkarray = [0, 64, 128, 192];
		herodownpunchleftarray = [0, 64];
		herodownpunchrightarray = [0, 64];
		herodownfaintedarray = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896];

		herodownwalkcounter = 0;
		herodownpunchcounter = 0;
		herodownfaintedcounter = 0;


////////////////////////////////////////
		heroleftwalkimg = document.getElementById("heroleftwalk");
		heroleftleftpunchimg = document.getElementById("heroleftleftpunch");
		heroleftrightpunchimg = document.getElementById("heroleftrightpunch");
		heroleftfaintedimg = document.getElementById("heroleftfainted");
		
		heroleftwalkarray = [0, 64, 128, 192];
		heroleftpunchleftarray = [0, 64];
		heroleftpunchrightarray = [0, 64];
		heroleftfaintedarray = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896];

		heroleftwalkcounter = 0;
		heroleftpunchcounter = 0;
		heroleftfaintedcounter = 0;


////////////////////////////////////////
		herorightwalkimg = document.getElementById("herorightwalk");
		herorightleftpunchimg = document.getElementById("herorightleftpunch");
		herorightrightpunchimg = document.getElementById("herorightrightpunch");
		herorightfaintedimg = document.getElementById("herorightfainted");
		
		herorightwalkarray = [0, 64, 128, 192];
		herorightpunchleftarray = [0, 64];
		herorightpunchrightarray = [0, 64];
		herorightfaintedarray = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896];

		herorightwalkcounter = 0;
		herorightpunchcounter = 0;
		herorightfaintedcounter = 0;



//////////////////////////////////////////

		punchsound = document.getElementById("punchsound");
		
		punchsoundhowler = new Howl({
							urls:[punchsound.src]
							});
		
		heroxcoord = width/2 - 32;
		heroycoord = height - 128-64+18;
		
		isherovisible = true;
		
		isgirlvisible = true;
		
		ispointerpressed = false;
    
		leftwalk = false;
		rightwalk = false;
		upwalk = true;
		downwalk = false;

		heroleftpunch = false;
		herorightpunch = false;
		herouppunch = false;
		herodownpunch = false;

		heroleftdir = false;
		herorightdir = false;
		heroupdir = true;
		herodowndir = false;
		
		isherofainted = false;
		isherofaintanimate = false;
		
		leftarrowx = 32+24;
		leftarrowy = height-32;
		
		rightarrowx = 32+24+32;
		rightarrowy = height-32;
		
		uparrowx = 32+24+32+32;
		uparrowy = height-32;

		downarrowx = 32+24+32+32+32;
		downarrowy = height-32;
	
		leftpunchx = 0;
		leftpunchy = height-32;
		
		rightpunchx = width-(32+16);
		rightpunchy = height-32;
		
		isuivisible = true;
		
		isreplaygame = false;
		
////////////////////////////////////////

		sikdiuppunch = document.getElementById("sikdiuppunch");
		sikdiupfainted = document.getElementById("sikdiupfainted");

		sikdidownwalk = document.getElementById("sikdidownwalk");
		sikdidownpunch = document.getElementById("sikdidownpunch");
		sikdidownfainted = document.getElementById("sikdidownfainted");


		sikdileftpunch = document.getElementById("sikdileftpunch");
		sikdileftfainted = document.getElementById("sikdileftfainted");

		sikdirightpunch = document.getElementById("sikdirightpunch");
		sikdirightfainted = document.getElementById("sikdirightfainted");
		
		sikdimotion = [0, 64, 128, 192];
		sikdimotionfainted = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024];
		sikdiarray = new Array();
		
//////////////////takla
		taklauppunch = document.getElementById("taklauppunch");
		taklaupfainted = document.getElementById("taklaupfainted");

		takladownwalk = document.getElementById("takladownwalk");
		takladownpunch = document.getElementById("takladownpunch");
		takladownfainted = document.getElementById("takladownfainted");


		taklaleftpunch = document.getElementById("taklaleftpunch");
		taklaleftfainted = document.getElementById("taklaleftfainted");

		taklarightpunch = document.getElementById("taklarightpunch");
		taklarightfainted = document.getElementById("taklarightfainted");
		
		taklamotion = [0, 64, 128, 192];
		taklamotionfainted = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088];
		taklaarray = new Array();


//////////////////////////		
//////////////////fatty
		fattyuppunch = document.getElementById("fattyuppunch");
		fattyupfainted = document.getElementById("fattyupfainted");

		fattydownwalk = document.getElementById("fattydownwalk");
		fattydownpunch = document.getElementById("fattydownpunch");
		fattydownfainted = document.getElementById("fattydownfainted");


		fattyleftpunch = document.getElementById("fattyleftpunch");
		fattyleftfainted = document.getElementById("fattyleftfainted");

		fattyrightpunch = document.getElementById("fattyrightpunch");
		fattyrightfainted = document.getElementById("fattyrightfainted");
		
		fattymotion = [0, 64, 128, 192];
		fattymotionfainted = [0, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088];
		fattyarray = new Array();


//////////////////////////		
		
		isvillainvisible = new Array();

////////////////////////////////////////		
    sikdiindex = 0;
    sikdifainted = 0;
    failtoprotect = false;

    taklaindex = 0;
    taklafainted = 0;

    fattyindex = 0;
    fattyfainted = 0;
	
	faintedcounter = new Array();
	faintedcounted = new Array();
	
	for(i=0;i<20;i++)
	{
		faintedcounter[i] = false;
		faintedcounted[i] = false;
	}
	
	ANIMATIONCOUNTERLIMIT = new Array();
	
	isendgame = false;
	
	isvillainfainted = new Array();
	

    herohealth = 200;
    isherodisabled = false;
    LIFE = 3;

    showfailedmessage = false;

    messageshown = false;
    messagestarttime = 0;
    messageendtime = 0;

    lifetemp;
    isnextstagemsgvisble = false;

	
	isgamescreenimagescreated = false;

	randomxcoord;

    coordx = new Array();
    coordy = new Array();
    dirleft = new Array();
    dirright = new Array();
    dirup = new Array();
    dirdown = new Array();
    inrange = new Array();
    villainhealth = new Array();
    ishero_outofrange = new Array();
    faintedcounter = new Array();
    faintedcounted = new Array();
	
	sikdi = new Array();
	takla = new Array();
	fatty = new Array();
	
	isengageinfight = new Array();

	
	sikdicounter = new Array();
	taklacounter = new Array();
	fattycounter = new Array();0
	
	for(i=0;i<20;i++)
	{
		sikdicounter[i] = 0;
		taklacounter[i] = 0;
		fattycounter[i] = 0;
	}
		
		
////////////////////////////////////////////////		
		canvas = document.getElementById("can");

		var hammertime = new Hammer(canvas);

		hammertime.add(new Hammer.Press({
			event: 'press',
			pointer: 1,
			threshold: 5,
			time:1
		}));

		hammertime.add(new Hammer.Tap({
			event: 'tap',
			pointer: 1,
			threshold: 5,
			time:1
		}));
		
		hammertime.on('tap', function(event) {
			mouseDown(event);
		});
		hammertime.on('press', function(event) {
			mouseDown(event);
		});
		hammertime.on('pressup', function(event) {
			mouseUp(event);
		});
		
/*		canvas.addEventListener("mousedown", mouseDown, false);
		canvas.addEventListener("touchstart", mouseDown,
		false); */
		canvas.addEventListener("mouseup", mouseUp, false);
		canvas.addEventListener("touchup", mouseUp, false);
		canvas.addEventListener("touchleave", mouseUp, false);

		ctx = canvas.getContext("2d");
		ctx.canvas.width = screenwidth;
		ctx.canvas.height = screenheight;
		
		
		STAGE_ONE = 1;
		STAGE_TWO = 2;
		STAGE_THREE = 3;
		
		stage = STAGE_ONE;

		issikdishown = true;
		istaklashown = false;
		isfattyshown = false;
	
		
		sikdihit = 1;
		taklahit = 2;
		fattyhit = 4;

		SIKDIHURT = 15;
		TAKLAHURT = 5;
		FATTYHURT = 3;
		

		backgroundimg = splash;
		_whichscreen = SPLASHSCREEN;
		
		drawsplashscreen();
		
		var t = setTimeout(function(){
				requestAnimationFrame(update);
				}, 1000/30);
	}
	
	function mouseDown(event)
	{
		
		if(_whichscreen == SPLASHSCREEN)
			_whichscreen = POSTERSCREEN;

		else if(_whichscreen == POSTERSCREEN)
			_whichscreen = MENUSCREEN;

		else if(_whichscreen == MENUSCREEN)
		{
			var rect = canvas.getBoundingClientRect();
			var pointerx = event.center.x - rect.left;
			var pointery = event.center.y - rect.top;

//			alert("rect:" + rect);

			
			if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20 && pointery <= (height/10)+20+40))
			{
				if(counter != 1)
					counter = Number(localStorage.counters);
					
				if(isNaN(counter))
					counter = 0;

				if(counter == 0)
				{
					alert("Plz click above advertisement to unlock game.\nYou can play game unlimited times.\nIf advertisement are not shown plz check you internet connection.");
				}
				else
				{
					counter = 1;
					localStorage.counters = 0;
					
					document.getElementById("vservadvt1").style.display = "none";
				
					_whichscreen = GAMESCREEN;
				}
			}
			
			else if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20+40+20 && pointery <= (height/10)+20+40+20+40))
			{
				_whichscreen = ABOUTSCREEN;
			}

			else if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20+40+20+40+20 && pointery <= (height/10)+20+40+20+40+20+40))
			{
				_whichscreen = HELPSCREEN;
			}
		}

		else if(_whichscreen == ABOUTSCREEN)
		{
			var rect = canvas.getBoundingClientRect();
			var pointerx = event.center.x - rect.left;
			var pointery = event.center.y - rect.top;
			
			if((pointerx >= 0 && pointerx <= 32) && (pointery >= 0 && pointery <= 32))
			{
				document.getElementById("vservadvt1").style.display = "block";
				_whichscreen = MENUSCREEN;
			}
		}

		else if(_whichscreen == HELPSCREEN)
		{
			var rect = canvas.getBoundingClientRect();
			var pointerx = event.center.x - rect.left;
			var pointery = event.center.y - rect.top;
			
			if((pointerx >= 0 && pointerx <= 32) && (pointery >= 0 && pointery <= 32))
			{
				document.getElementById("vservadvt1").style.display = "block";
				_whichscreen = MENUSCREEN;
			}
		}
		
//////////////////
		else if(_whichscreen == GAMESCREEN)
		{
			var rect = canvas.getBoundingClientRect();
			var pointerx = event.center.x - rect.left;
			var pointery = event.center.y - rect.top;

			if(isgameover == false)
			{
				
				//pausescreen
				if((pointerx >= 0 && pointerx <= 32) && (pointery >= 0 && pointery <= 32))
				{
					_whichscreen = PAUSESCREEN;
				}
			
				if(isherodisabled == false)
				{
					if((pointerx >= uparrowx && pointerx <= (uparrowx + 32)) && (pointery >= uparrowy && pointery <= (uparrowy + 32)))
					{
						ispointerpressed = true;
						
						heromoveup();
						
						upwalk = true;
						downwalk = false;
						leftwalk = false;
						rightwalk = false;
						
						heroupleftpunch = false;
						herouprightpunch = false;

						herodownleftpunch = false;
						herodownrightpunch = false;

						heroleftleftpunch = false;
						heroleftrightpunch = false;

						herorightleftpunch = false;
						herorightrightpunch = false;

						heroleftdir = false;
						herorightdir = false;
						heroupdir = true;
						herodowndir = false;
					}
				
					if((pointerx >= downarrowx && pointerx <= (downarrowx + 32)) && (pointery >= downarrowy && pointery <= (downarrowy + 32)))
					{
						ispointerpressed = true;
						
						heromovedown();
						
						downwalk = true;
						upwalk = false;
						leftwalk = false;
						rightwalk = false;

						heroupleftpunch = false;
						herouprightpunch = false;

						herodownleftpunch = false;
						herodownrightpunch = false;

						heroleftleftpunch = false;
						heroleftrightpunch = false;

						herorightleftpunch = false;
						herorightrightpunch = false;

						heroleftdir = false;
						herorightdir = false;
						heroupdir = false;
						herodowndir = true;
					}

					if((pointerx >= leftarrowx && pointerx <= (leftarrowx + 32)) && (pointery >= leftarrowy && pointery <= (leftarrowy + 32)))
					{
						ispointerpressed = true;
						
						heromoveleft();
						
						leftwalk = true;
						upwalk = false;
						downwalk = false;
						rightwalk = false;
						
						heroupleftpunch = false;
						herouprightpunch = false;

						herodownleftpunch = false;
						herodownrightpunch = false;

						heroleftleftpunch = false;
						heroleftrightpunch = false;

						herorightleftpunch = false;
						herorightrightpunch = false;

						heroleftdir = true;
						herorightdir = false;
						heroupdir = false;
						herodowndir = false;
					}

					if((pointerx >= rightarrowx && pointerx <= (rightarrowx + 32)) && (pointery >= rightarrowy && pointery <= (rightarrowy + 32)))
					{
						ispointerpressed = true;
						
						heromoveright();
						
						rightwalk = true;
						upwalk = false;
						leftwalk = false;
						downwalk = false;
						
						heroupleftpunch = false;
						herouprightpunch = false;

						herodownleftpunch = false;
						herodownrightpunch = false;

						heroleftleftpunch = false;
						heroleftrightpunch = false;

						herorightleftpunch = false;
						herorightrightpunch = false;

						heroleftdir = false;
						herorightdir = true;
						heroupdir = false;
						herodowndir = false;
					}

					if((pointerx >= leftpunchx && pointerx <= (leftpunchx + 32)) && (pointery >= leftpunchy && pointery <= (leftpunchy + 32)))
					{
						ispointerpressed = true;

						if(upwalk == true && heroupdir == true)
						{
							heroupleftpunchchange();
							
							heroupleftpunch = true;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
						else if(downwalk == true && herodowndir == true)
						{
							herodownleftpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = true;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
		///////////////////////////
						else if(leftwalk == true && heroleftdir == true)
						{
							heroleftleftpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = true;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
						else if(rightwalk == true && herorightdir == true)
						{
							herorightleftpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = true;
							herorightrightpunch = false;
						}
					
						for(i=0;i<20;i++)
						{
							if(inrange[i] == true && ((heroleftdir == true && dirright[i] == true) || (heroupdir == true && dirdown[i] == true) || (herorightdir == true && dirleft[i] == true) || (herodowndir == true && dirup[i] == true)))
							{
								if(stage == STAGE_ONE)
								{
									villainhealth[i] -= SIKDIHURT;
								}
								else if(stage == STAGE_TWO)
								{
									villainhealth[i] -= TAKLAHURT;
								}
								else if(stage == STAGE_THREE)
								{
									villainhealth[i] -= FATTYHURT;
								}
							}
						}
					}

					if((pointerx >= rightpunchx && pointerx <= (rightpunchx + 32)) && (pointery >= rightpunchy && pointery <= (rightpunchy + 32)))
					{
						ispointerpressed = true;

						if(upwalk == true && heroupdir == true)
						{
							herouprightpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = true;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
						else if(downwalk == true && herodowndir == true)
						{
							herodownrightpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = true;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
		////////////////////////////
						else if(leftwalk == true && heroleftdir == true)
						{
							heroleftrightpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = true;

							herorightleftpunch = false;
							herorightrightpunch = false;
						}
						else if(rightwalk == true && herorightdir == true)
						{
							herorightrightpunchchange();
							
							heroupleftpunch = false;
							herouprightpunch = false;

							herodownleftpunch = false;
							herodownrightpunch = false;

							heroleftleftpunch = false;
							heroleftrightpunch = false;

							herorightleftpunch = false;
							herorightrightpunch = true;
						}
						
						for(i=0;i<20;i++)
						{
							if(inrange[i] == true && ((heroleftdir == true && dirright[i] == true) || (heroupdir == true && dirdown[i] == true) || (herorightdir == true && dirleft[i] == true) || (herodowndir == true && dirup[i] == true)))
							{
								if(stage == STAGE_ONE)
								{
									villainhealth[i] -= SIKDIHURT;
								}
								else if(stage == STAGE_TWO)
								{
									villainhealth[i] -= TAKLAHURT;
								}
								else if(stage == STAGE_THREE)
								{
									villainhealth[i] -= FATTYHURT;
								}
							}
						}
					}
				}
			}
			
			if(isgameover == true || isendgame == true)
			{
				if((pointerx >= width-(32+16) && pointerx <= width) && (pointery >= 0 && pointery <= 32))
				{
					isgameover = false;
					isendgame = false;
					
					isgamescreenimagescreated = false;
					
					resetcommonvar();
					
					heroxcoord = width/2 - 32;
					heroycoord = height - 128-64+18;
					
					upwalk = true;
					downwalk = false;
					leftwalk = false;
					rightwalk = false;
						
					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;

					heroleftdir = false;
					herorightdir = false;
					heroupdir = true;
					herodowndir = false;
			
				
					isherovisible = true;
					isgirlvisible = true;
					
					ispausebtnvisible = true;
					
					herohealth = 200;
					markerarray = 0;
					LIFE = 3;
					lifeseq = lifearray[3-LIFE];

					isherodisabled = false;
				
					isherofainted = false;
		
					stage = STAGE_ONE;

					document.getElementById("vservadvt1").style.display = "block";
					_whichscreen = MENUSCREEN;
				}
			}
		}
		
////////pausescreen
		else if(_whichscreen == PAUSESCREEN)
		{
			var rect = canvas.getBoundingClientRect();
			var pointerx = event.center.x - rect.left;
			var pointery = event.center.y - rect.top;
			
			if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20 && pointery <= (height/10)+20+40))
			{
				_whichscreen = GAMESCREEN;
			}

			if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20+40+20 && pointery <= (height/10)+20+40+20+40))
			{
				isreplaygame = true;
				isgamescreenimagescreated = false;
				
				_whichscreen = GAMESCREEN;
			}

			if((pointerx >= (width-(150+16)) && pointerx <= width) && (pointery >= (height/10)+20+40+20+40+20 && pointery <= (height/10)+20+40+20+40+20+40))
			{
				isgameover = false;
					
				isgamescreenimagescreated = false;
					
				resetcommonvar();
					
				heroxcoord = width/2 - 32;
				heroycoord = height - 128-64+18;
				
				isherovisible = true;
				isgirlvisible = true;
					
				ispausebtnvisible = true;
					
					
				herohealth = 200;
				markerarray = 0;
				LIFE = 3;
				lifeseq = lifearray[3-LIFE];


				isherodisabled = false;
				
				isherofainted = false;

				stage = STAGE_ONE;
				
				heroimage = heroupwalkimg;

				document.getElementById("vservadvt1").style.display = "block";
				_whichscreen = MENUSCREEN;
			}
		}
	}
	
	function heromoveup()
	{
		heroimage = heroupwalkimg;
	}

	function heromovedown()
	{
		heroimage = herodownwalkimg;
	}

	function heromoveleft()
	{
		heroimage = heroleftwalkimg;
	}

	function heromoveright()
	{
		heroimage = herorightwalkimg;
	}
//////////////////////////
	function heroupleftpunchchange()
	{
		heroimage = heroupleftpunchimg;
	}
	function herouprightpunchchange()
	{
		heroimage = herouprightpunchimg;
	}

	function herodownleftpunchchange()
	{
		heroimage = herodownleftpunchimg;
	}
	function herodownrightpunchchange()
	{
		heroimage = herodownrightpunchimg;
	}
	
	function heroleftleftpunchchange()
	{
		heroimage = heroleftleftpunchimg;
	}
	function heroleftrightpunchchange()
	{
		heroimage = heroleftrightpunchimg;
	}

	function herorightleftpunchchange()
	{
		heroimage = herorightleftpunchimg;
	}
	function herorightrightpunchchange()
	{
		heroimage = herorightrightpunchimg;
	}
	
	function heroupfainting()
	{
		heroimage = heroupfaintedimg;
	}

	function herodownfainting()
	{
		heroimage = herodownfaintedimg;
	}
	
	function heroleftfainting()
	{
		heroimage = heroleftfaintedimg;
	}

	function herorightfainting()
	{
		heroimage = herorightfaintedimg;
	}
	
///////////////////////////////	
	function mouseUp(event)
	{
		event.preventDefault();
		ispointerpressed = false;
	}
	
	function update()
	{
		setTimeout(function(){
				requestAnimationFrame(update);
				}, 1000/30);

		if(_whichscreen == POSTERSCREEN)
			drawposterscreen();
		else if(_whichscreen == MENUSCREEN)
			drawmainmenuscreen();
		else if(_whichscreen == ABOUTSCREEN)
		{
			drawaboutscreen();
		}
		else if(_whichscreen == HELPSCREEN)
			drawhelpscreen();
		else if(_whichscreen == GAMESCREEN)
			drawgamescreen();
		else if(_whichscreen == PAUSESCREEN)
			drawpausescreen();
		
	}

function drawsplashscreen()
{
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
}
	
function drawposterscreen()
{
	backgroundimg = poster;
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
}

function drawmainmenuscreen()
{
	backgroundimg = menu;
	
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
	ctx.drawImage(playmenu, width-(150+16), (height/10)+20, 150, 40);
	ctx.drawImage(aboutmenu, width-(150+16), (height/10)+20+40+20, 150, 40);
	ctx.drawImage(helpmenu, width-(150+16), (height/10)+20+40+20+40+20, 150, 40);
				
}

function drawaboutscreen()
{
	backgroundimg = about;
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
	ctx.drawImage(backicon, 0, 0, 32, 32);
}

function drawhelpscreen()
{
	backgroundimg = help;
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
	ctx.drawImage(backicon, 0, 0, 32, 32);
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$
function drawgamescreen()
{
	backgroundimg = gamebackground;

	girlanimationtime = new Date().getTime();
	
	var heroarray = 0;
	var lifeseq = 0;
	
	lifeseq = lifearray[3-LIFE];
	
	if(LIFE >= 1)
	{
		if(herohealth > 0)
		{
			if(ispointerpressed == true)
			{
				if(upwalk == true && heroupleftpunch == false && herouprightpunch == false)
				{
					heroarray = heroupwalkarray[heroanimcounter];
					
					var herocoordy = heroycoord;
					
					if(stage == STAGE_ONE)
						herocoordy -= 5;
					else if(stage == STAGE_TWO)
						herocoordy -= 8;
					else if(stage == STAGE_THREE)
						herocoordy -= 8;
						
					if(herocoordy <= -16)
						herocoordy = -16;
						
					heroycoord = herocoordy;

				}
				else if(downwalk == true && herodownleftpunch == false && herodownrightpunch == false)
				{
					heroarray = herodownwalkarray[heroanimcounter];
					
					var herocoordy = heroycoord;
					
					if(stage == STAGE_ONE)
						herocoordy += 5;
					else if(stage == STAGE_TWO)
						herocoordy += 8;
					else if(stage == STAGE_THREE)
						herocoordy += 8;
						
					if(herocoordy >= height-32-16)
						herocoordy = height-32-16;
						
					heroycoord = herocoordy;
				}
				else if(leftwalk == true && heroleftleftpunch == false && heroleftrightpunch == false)
				{
					heroarray = heroleftwalkarray[heroanimcounter];
					
					var herocoordx = heroxcoord;
					if(stage == STAGE_ONE)
						herocoordx -= 5;
					else if(stage == STAGE_TWO)
						herocoordx -= 8;
					else if(stage == STAGE_THREE)
						herocoordx -= 8;
						
					if(herocoordx <= -16)
						herocoordx = -16;
						
					heroxcoord = herocoordx;
				}
				else if(rightwalk == true && herorightleftpunch == false && herorightrightpunch == false)
				{
					heroarray = herorightwalkarray[heroanimcounter];
					
					var herocoordx = heroxcoord;
					if(stage == STAGE_ONE)
						herocoordx += 5;
					else if(stage == STAGE_TWO)
						herocoordx += 8;
					else if(stage == STAGE_THREE)
						herocoordx += 8;
						
					if(herocoordx >= width-32-16)
						herocoordx = width-32-16;
						
					heroxcoord = herocoordx;
				}
				else if(heroupleftpunch == true && heroupdir == true)
				{
					heroarray = herouppunchleftarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(herouprightpunch == true && heroupdir == true)
				{
					heroarray = herouppunchrightarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(herodownleftpunch == true && herodowndir == true)
				{
					heroarray = herodownpunchleftarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(herodownrightpunch == true && herodowndir == true)
				{
					heroarray = herodownpunchrightarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
		/////////////////////
				else if(heroleftleftpunch == true && heroleftdir == true)
				{
					heroarray = heroleftpunchleftarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(heroleftrightpunch == true && heroleftdir == true)
				{
					heroarray = heroleftpunchrightarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(herorightleftpunch == true && herorightdir == true)
				{
					heroarray = herorightpunchleftarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
				else if(herorightrightpunch == true && herorightdir == true)
				{
					heroarray = herorightpunchrightarray[1];
					ispointerpressed = false;
					punchsoundhowler.play();
				}
		///////////////////////
			}
			else
			{
				if(heroupleftpunch == true)
				{
					heroupleftpunch = false;
				}
				if(herouprightpunch == true)
				{
					herouprightpunch = false;
				}
				if(herodownleftpunch == true)
				{
					herodownleftpunch = false;
				}
				if(herodownrightpunch == true)
				{
					herodownrightpunch = false;
				}
				if(heroleftleftpunch == true)
				{
					heroleftleftpunch = false;
				}
				if(heroleftrightpunch == true)
				{
					heroleftrightpunch = false;
				}
				if(herorightleftpunch == true)
				{
					herorightleftpunch = false;
				}
				if(herorightrightpunch == true)
				{
					herorightrightpunch = false;
				}

				punchsoundhowler.stop();

				heroarray = heroupwalkarray[0];
			}
		}
		else
		{
			isherodisabled = true;
			
				if(heroupdir == true)
				{
					heroimage = heroupfaintedimg;
					heroarray = heroupfaintedarray[heroanimcounter];
				}
				if(herodowndir == true)
				{
					heroimage = herodownfaintedimg;
					heroarray = herodownfaintedarray[heroanimcounter];
				}
				if(heroleftdir == true)
				{
					heroimage = heroleftfaintedimg;
					heroarray = heroleftfaintedarray[heroanimcounter];
				}
				if(herorightdir == true)
				{
					heroimage = herorightfaintedimg;
					heroarray = herorightfaintedarray[heroanimcounter];
				}

			isherofainted = true;
		}
	}
	else
	{
		heroxcoord = 0;
		heroycoord = -164;
		
		isherovisible = false;
		isgirlvisible = false;
		
		if(stage == STAGE_ONE)
			issikdishown = false;
		else if(stage == STAGE_TWO)
			istaklashown = false;
		else if(stage == STAGE_THREE)
			isfattyshown = false;
		
		ispausebtnvisible = false;
		
		isgameover = true;
		
		herohealth = 0;

		for(i=0;i<20;i++)
		{
		    ishero_outofrange[i] = false;
		}

		isherodisabled = true;
	
		isherofainted = true;
	}
	
//////
	    if(((girlcoordy+64-23) >= heroycoord) && (girlcoordy < heroycoord) && (heroxcoord >= (girlcoordx-23)) && (heroxcoord+64) <=(girlcoordx+64+23))
	    {
			if(heroupdir == true)
			{
				if(heroycoord <= girlcoordy + (64/2))
					heroycoord = girlcoordy + (64/2);
			}
	    }

	    else if(((girlcoordx+64-23)  >= heroxcoord) && (girlcoordx < heroxcoord) && (heroycoord >= (girlcoordy-23)) && (heroycoord+64) <= (girlcoordy+64+23))
	    {
			if(heroleftdir == true)
			{
				if(heroxcoord <= girlcoordx + (64/2))
				{
					heroxcoord = girlcoordx + (64/2);
				}
			}
	    }

	    else if(((heroxcoord+64-23) >= girlcoordx) && (heroxcoord < girlcoordx) && (heroycoord >= (girlcoordy-23)) && (heroycoord+64) <=(girlcoordy+64+23))
	    {
			if(herorightdir == true)
			{
				if(heroxcoord >= girlcoordx - (64/2))
				{
					heroxcoord = girlcoordx - (64/2);
				}
			}
	    }

	    else if(((heroycoord+64-23) >= girlcoordy) && (heroycoord < girlcoordy) && (heroxcoord >= (girlcoordx-23)) && (heroxcoord+64) <=(girlcoordx+64+23))
	    {
			if(herodowndir == true)
			{
				if(heroycoord >= girlcoordy - (64/2))
					heroycoord = girlcoordy - (64/2);
			}
	    }

		else if(girlrightdir == true)
		{
			girlcoordx += 5;
			if(girlcoordx >= (width - (64 - 25)))
			{
				girlleftdir = true;
				girlrightdir = false;
				
				girl = girlleft;
			}
		}
		else if(girlleftdir == true)
		{
			girlcoordx -= 5;
			if(girlcoordx < - 25)
			{
				girlleftdir = false;
				girlrightdir = true;
				
				girl = girlright;
			}
		}

//////////	
	
	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);
	ctx.drawImage(crosslineimg, 0, height - 128, width, 4);
	
	drawgirlsprite();
	
	drawvillaini();
	
	if(isherovisible == true)
	{
		if(upwalk == true || downwalk == true)
		{
			ctx.drawImage(heroimage, heroarray, 0, 64, 64, heroxcoord, heroycoord, 64, 64);
		}
		else if(leftwalk == true || rightwalk == true)
		{
			ctx.drawImage(heroimage, 0, heroarray, 64, 64, heroxcoord, heroycoord, 64, 64);
		}
		else if(heroupdir == true && isherofainted == true)
		{
			ctx.drawImage(heroimage, heroarray, 0, 64, 64, heroxcoord, heroycoord, 64, 64);
		}
	}
	
	ctx.drawImage(lifeimg, 0, lifeseq, 120, 32, width-(120+16), 0, 120, 32);

	if(isuivisible == true)
	{
//		ctx.drawImage(menustrip, 0, height-64, width, 32);
		ctx.drawImage(leftpunch, leftpunchx, leftpunchy, 32, 32);
		ctx.drawImage(rightpunch, rightpunchx, rightpunchy, 32, 32);
		ctx.drawImage(leftarrow, (32+24), (height-32), 32, 32);
		ctx.drawImage(rightarrow, (32+24+32), (height-32), 32, 32);
		ctx.drawImage(uparrow, (32+24+32+32), (height-32), 32, 32);
		ctx.drawImage(downarrow, (32+24+32+32+32), height-32, 32, 32);
	}

	if(isgameover == true)
	{
		ctx.drawImage(gameoverimg, 0, 0, width, height);
		ctx.drawImage(nexticon, width-(32+16), 0, 32, 32);
	}
	
	else if(isendgame == true)
	{
		ctx.drawImage(endframeimg, 0, 0, width, height);
		ctx.drawImage(nexticon, width-(32+16), 0, 32, 32);
	}
	
	else if(ispausebtnvisible == true)
	{
		ctx.drawImage(pausebtn, 0, 0, 32, 32);
	}
	
	heroanimcounter++;
	
	if((upwalk == true && heroupleftpunch == false) || downwalk == true || leftwalk == true || rightwalk == true)
	{
		if(isherofainted == true)
		{
			if(heroanimcounter > 14)
			{
				heroanimcounter = 0;
				isherofainted = false;
				
				heroxcoord = (width/2) - 32;
				heroycoord = height - 128-64+18;

				LIFE -= 1;
				lifeseq = lifearray[3-LIFE];


				herohealth = 200;
				
				if(LIFE > 0)
					markerarray = 0;
				
				if(stage == STAGE_ONE)
				{
					sikdiindex = sikdifainted - 1;
				
					if(sikdiindex < 0)
						sikdiindex = 0;

					for(i=sikdiindex;i<20;i++)
					{
						coordy[i] = -64;
						isvillainvisible[i] = false;
						inrange[i] = false;
					}
				}

				else if(stage == STAGE_TWO)
				{
					taklaindex = taklafainted - 1;
				
					if(taklaindex < 0)
						taklaindex = 0;

					for(i=taklaindex;i<20;i++)
					{
						coordy[i] = -64;
						isvillainvisible[i] = false;
						inrange[i] = false;
					}
				}

				else if(stage == STAGE_THREE)
				{
					fattyindex = fattyfainted - 1;
				
					if(fattyindex < 0)
						fattyindex = 0;

					for(i=fattyindex;i<20;i++)
					{
						coordy[i] = -64;
						isvillainvisible[i] = false;
						inrange[i] = false;
					}
				}
				
				elapsed_time = 0;
				initial_time = parseInt(new Date().getTime()/1000);
					
				isherodisabled = false;
				
				heroimage = heroupwalkimg;

				heroupdir = true;
				herodowndir = false;
				heroleftdir = false;
				herorightdir = false;
				heroleftpunch = false;
				herorightpunch = false;
				
				heroarray = heroupwalkarray[heroanimcounter];
				upwalk = true;
				downwalk = false;
				leftwalk = false;
				rightwalk = false;
			}
		}
		else
		{
			if(heroanimcounter > 3)
				heroanimcounter = 0;
		}
	}
}

function drawgirlsprite()
{
		var girlarray = girlanim[girlcounter];
		
		if(isgirlvisible == true)
		{
			ctx.drawImage(girl, 0, girlarray, 64, 64, girlcoordx, girlcoordy, 64, 64);
		}
		
//		 time = now;
		girlcounter++;

		if(girlcounter > 3)
		{
			girlcounter = 0;
		}
}


function drawvillaini()
{
	if(isgamescreenimagescreated == false)
	{
	    resetcommonvar();

		if(stage == STAGE_ONE)
		{
			sikdiindex = 0;

			sikdifainted = 0;
			
			issikdishown = true;

			failtoprotect = false;
		}

		else if(stage == STAGE_TWO)
		{
			taklaindex = 0;

			taklafainted = 0;
			
			istaklashown = true;

			failtoprotect = false;
		}

		else if(stage == STAGE_THREE)
		{
			fattyindex = 0;

			fattyfainted = 0;
			
			isfattyshown = true;

			failtoprotect = false;
		}
		
		showfailedmessage = false;
		
		for(i=0;i<20;i++)
		{
			if(stage == STAGE_ONE)
			{
				isvillainvisible[i] = false;
				sikdiarray[i] = 0;
				sikdi[i] = sikdidownwalk;
			}
			else if(stage == STAGE_TWO)
			{
				isvillainvisible[i] = false;
				taklaarray[i] = 0;
				takla[i] = takladownwalk;
			}
			else if(stage == STAGE_THREE)
			{
				isvillainvisible[i] = false;
				fattyarray[i] = 0;
				fatty[i] = fattydownwalk;
			}

			isvillainfainted[i] = false;
			ANIMATIONCOUNTERLIMIT[i] = 3;

			ishero_outofrange[i] = true;
			isengageinfight[i] = false;

			coordx[i] = Math.floor((Math.random() * (width - 64)));  // + 32;
			coordy[i] = -64;
			villainhealth[i] = 100;
			faintedcounted[i] = false;
		}

		isgamescreenimagescreated = true;	
		
	}
	
////////////////////////////////////////////////////////////////

	    if(isreplaygame == true)
	    {
			heroxcoord = (width/2) - 32;
			heroycoord = (height - 128-64+18);

			upwalk = true;
			downwalk = false;
			leftwalk = false;
			rightwalk = false;
						
			heroupleftpunch = false;
			herouprightpunch = false;

			herodownleftpunch = false;
			herodownrightpunch = false;

			heroleftleftpunch = false;
			heroleftrightpunch = false;

			herorightleftpunch = false;
			herorightrightpunch = false;

			heroleftdir = false;
			herorightdir = false;
			heroupdir = true;
			herodowndir = false;
			
			isgameover = false;
					
			isherovisible = true;
			isgirlvisible = true;
					
			ispausebtnvisible = true;
					
					
			herohealth = 200;
			markerarray = 0;
			lifeseq = lifearray[3-LIFE];
			isherodisabled = false;
			isherofainted = false;
			heroimage = heroupwalkimg;

			
			isreplaygame = false;
	    }

////////////////////////////////////////////////////////////////	

	if(isnextstagemsgvisble == true)
	{
		messageendtime = parseInt(new Date().getTime()/1000);
		
		if(stage == STAGE_TWO)
		{
			if((messageendtime - messagestarttime) < 3)
			{
				ctx.drawImage(stage2start, 0, 0, width, height);
			}
			else
			{
				isnextstagemsgvisble = false;
			}
		}
		else if(stage == STAGE_THREE)
		{
			if((messageendtime - messagestarttime) < 3)
			{
				ctx.drawImage(stage3start, 0, 0, width, height);
			}
			else
			{
				isnextstagemsgvisble = false;
			}
		}
	}

	if(failtoprotect == true)
	{
		messageendtime = parseInt(new Date().getTime()/1000);
		
		if((messageendtime - messagestarttime) < 3)
		{
			ctx.drawImage(failtoprotectimg, 0, 0, width, height);
		}
		else
		{
			failtoprotect = false;
		}
	}
	
	next_time = parseInt(new Date().getTime()/1000);
	elapsed_time = next_time - initial_time;
	
	if(stage == STAGE_ONE)
	{
		if(elapsed_time >= 3)
		{
			if(sikdiindex > 19)
				sikdiindex = 19;

			if(!(sikdiindex > 19))
			{
			
				if(isvillainfainted[sikdiindex] == false)
				{
					isvillainvisible[sikdiindex] = true;
				}
				
				initial_time = parseInt(new Date().getTime()/1000);
				elapsed_time = 0;
			}

			sikdiindex++;
		}
	}	
	
	else if(stage == STAGE_TWO)
	{
		if(elapsed_time >= 5)
		{
			if(taklaindex > 19)
				taklaindex = 19;

			if(!(taklaindex > 19))
			{
			
				if(isvillainfainted[taklaindex] == false)
				{
					isvillainvisible[taklaindex] = true;
				}
				
				initial_time = parseInt(new Date().getTime()/1000);
				elapsed_time = 0;
			}

			taklaindex++;
		}
	}
	
	else if(stage == STAGE_THREE)
	{
		if(elapsed_time >= 7)
		{
			if(fattyindex > 19)
				fattyindex = 19;

			if(!(fattyindex > 19))
			{
			
				if(isvillainfainted[fattyindex] == false)
				{
					isvillainvisible[fattyindex] = true;
				}
				
				initial_time = parseInt(new Date().getTime()/1000);
				elapsed_time = 0;
			}

			fattyindex++;
		}
	}

///////////////////sikdi hero clash coords
	for(i=0;i<20;i++)
	{
	    if(isvillainvisible[i] == true && !(villainhealth[i] <= 0))
	    {
			if(((coordy[i]+64-23) >= heroycoord) && (coordy[i] < heroycoord) && (heroxcoord >= (coordx[i]-30)) && (heroxcoord+64) <=(coordx[i]+64+23))
			{
				inrange[i] = true;
				ishero_outofrange[i] = false;

				if(heroupdir == true)
				{
					if(heroycoord <= coordy[i] + (64/2))
						heroycoord = coordy[i] + (64/2);
				}
				
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdidownpunch;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = takladownpunch;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattydownpunch;
				}
				
				isengageinfight[i] = true;

				if(herohealth > 0)
				{
					if(stage == STAGE_ONE)
						herohealth = herohealth - sikdihit;
					else if(stage == STAGE_TWO)
						herohealth = herohealth - taklahit;
					else if(stage == STAGE_THREE)
						herohealth = herohealth - fattyhit;
				}

				if(herohealth%2 == 0)
				{
					if(herohealth == 0)
					{
						markerarray = 1600;
					}
					else if(herohealth > 0)
					{
						markerarray = 1600 - (herohealth*8);
					}
				}


				dirright[i] = false;
				dirleft[i] = false;
				dirdown[i] = true;
				dirup[i] = false;
			}

			else if(((coordx[i]+64-23)  >= heroxcoord) && (coordx[i] < heroxcoord) && (heroycoord >= (coordy[i]-30)) && (heroycoord+64) <= (coordy[i]+64+23))
			{

				inrange[i] = true;
				ishero_outofrange[i] = false;

				if(heroleftdir == true)
				{
					if(heroxcoord <= coordx[i] + (64/2))
						heroxcoord = coordx[i] + (64/2);
				}

				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdirightpunch;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklarightpunch;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyrightpunch;
				}
				
				isengageinfight[i] = true;

				if(herohealth > 0)
				{
					if(stage == STAGE_ONE)
						herohealth = herohealth - sikdihit;
					else if(stage == STAGE_TWO)
						herohealth = herohealth - taklahit;
					else if(stage == STAGE_THREE)
						herohealth = herohealth - fattyhit;
				}

				if(herohealth%2 == 0)
				{
					if(herohealth == 0)
					{
						markerarray = 1600;
					}
					else if(herohealth > 0)
					{
						markerarray = 1600 - (herohealth*8);
					}
				}

				dirright[i] = true;
				dirleft[i] = false;
				dirdown[i] = false;
				dirup[i] = false;
			} 

			else if(((heroxcoord+64-23) >= coordx[i]) && (heroxcoord < coordx[i]) && (heroycoord >= (coordy[i]-30)) && (heroycoord+64) <=(coordy[i]+64+23))
			{
				inrange[i] = true;
				ishero_outofrange[i] = false;


				if(herorightdir == true)
				{
					if(heroxcoord >= coordx[i] - (64/2))
						heroxcoord = coordx[i] - (64/2);
				}

				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdileftpunch;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklaleftpunch;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyleftpunch;
				}
				
				isengageinfight[i] = true;

				if(herohealth > 0)
				{
					if(stage == STAGE_ONE)
						herohealth = herohealth - sikdihit;
					else if(stage == STAGE_TWO)
						herohealth = herohealth - taklahit;
					else if(stage == STAGE_THREE)
						herohealth = herohealth - fattyhit;
				}

				if(herohealth%2 == 0)
				{
					if(herohealth == 0)
					{
						markerarray = 1600;
					}
					else if(herohealth > 0)
					{
						markerarray = 1600 - (herohealth*8);
					}
				}


				dirleft[i] = true;
				dirright[i] = false;
				dirdown[i] = false;
				dirup[i] = false;
			} 

			else if(((heroycoord+64-23) >= coordy[i]) && (heroycoord < coordy[i]) && (heroxcoord >= (coordx[i]-30)) && (heroxcoord+64) <=(coordx[i]+64+23))
			{
				inrange[i] = true;
				ishero_outofrange[i] = false;


				if(herodowndir == true)
				{
					if(heroycoord >= coordy[i] - (64/2))
						heroycoord = coordy[i] - (64/2);
				}

				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdiuppunch;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklauppunch;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyuppunch;
				}
				
				isengageinfight[i] = true;

				if(herohealth > 0)
				{
					if(stage == STAGE_ONE)
						herohealth = herohealth - sikdihit;
					else if(stage == STAGE_TWO)
						herohealth = herohealth - taklahit;
					else if(stage == STAGE_THREE)
						herohealth = herohealth - fattyhit;
				}

				if(herohealth%2 == 0)
				{
					if(herohealth == 0)
					{
						markerarray = 1600;
					}
					else if(herohealth > 0)
					{
						markerarray = 1600 - (herohealth*8);
					}
				}


				dirleft[i] = false;
				dirright[i] = false;
				dirdown[i] = false;
				dirup[i] = true;
			}

			else
			{
			
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdidownwalk;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = takladownwalk;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattydownwalk;
				}
				
				isengageinfight[i] = false;

				inrange[i] = false;
				ishero_outofrange[i] = true;

				dirdown[i] = true;
				dirright[i] = false;
				dirleft[i] = false;
				dirup[i] = false;

			}
	    }
	}



///////////////////////////////////////////
	var isalltrue = false;

	for(i=0;i<20;i++)
	{
	    if(ishero_outofrange[i] == true)
			isalltrue = true;
	    else
	    {
			isalltrue = false;
			break;
	    }
	}
	
	if(isalltrue == true)
	{
	    if(herohealth < 200)
	    {
			if(stage == STAGE_ONE)
				herohealth += 1;
			else if(stage == STAGE_TWO)
				herohealth += 2;
			else if(stage == STAGE_THREE)
				herohealth += 4;

			if(herohealth > 200)
				herohealth = 200;

			if(herohealth%2 == 0)
			{
				markerarray = 1600 - (herohealth*8);
			}
	    }
	}

////???????
	for(i=0;i<20;i++)
	{
	    if(villainhealth[i] <= 0)
	    {
			if(dirdown[i] == true)
			{
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdidownfainted;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = takladownfainted;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattydownfainted;
				}
			}						
			
			else if(dirright[i] == true)
			{
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdirightfainted;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklarightfainted;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyrightfainted;
				}
			}

			else if(dirleft[i] == true)
			{
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdileftfainted;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklaleftfainted;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyleftfainted;
				}
			}
			else if(dirup[i] == true)
			{
				if(stage == STAGE_ONE)
				{
					sikdi[i] = sikdiupfainted;
				}
				else if(stage == STAGE_TWO)
				{
					takla[i] = taklaupfainted;
				}
				else if(stage == STAGE_THREE)
				{
					fatty[i] = fattyupfainted;
				}
			}

			ishero_outofrange[i] = true;
			faintedcounter[i] = true;
			
			isvillainfainted[i] = true;
			
			faintedcounter[i] = true;
	    }
	}
	
	for(k=0;k<20;k++)
	{
	    if(faintedcounter[k] == true && faintedcounted[k] == false)
	    {
			if(stage == STAGE_ONE)
			{
				sikdifainted = sikdifainted + 1;
				console.log("sikdifainted: " + sikdifainted);
			}
			else if(stage == STAGE_TWO)
			{
				taklafainted = taklafainted + 1;
				console.log("taklafainted: " + taklafainted);
			}
			else if(stage == STAGE_THREE)
			{
				fattyfainted = fattyfainted + 1;
				console.log("fattyfainted: " + fattyfainted);
			}
			
			faintedcounted[k] = true;
	    }
	}
	
	
////////////////////////	
	if(stage == STAGE_ONE)
	{
		if(faintedcounter[0] == true && faintedcounter[1] == true && faintedcounter[2] == true && faintedcounter[3] == true && faintedcounter[4] == true && faintedcounter[5] == true && faintedcounter[6] == true && faintedcounter[7] == true && faintedcounter[8] == true && faintedcounter[9] == true && faintedcounter[10] == true && faintedcounter[11] == true && faintedcounter[12] == true && faintedcounter[13] == true && faintedcounter[14] == true && faintedcounter[15] == true && faintedcounter[16] == true && faintedcounter[17] == true && faintedcounter[18] == true && faintedcounter[19] == true)
		{
			herohealth = 200;
			markerarray = 0

			messagestarttime = parseInt(new Date().getTime()/1000);
			
			initial_time = parseInt(new Date().getTime()/1000);

			stage = STAGE_TWO;
				
			issikdishown = false;

			istaklashown = true;

			isfattyshown = false;
				
			for(i=0;i<20;i++)
			{
				isvillainvisible[i] = false;
			}

			if(herohealth <= 0)
			{
				herohealth = 200;
				LIFE = LIFE - 1;
					
				lifeseq = lifearray[3-LIFE]; 
			}
				
			isgamescreenimagescreated = false;
			isnextstagemsgvisble = true;
		}
	}

/////////////////////////////
////////////////////////	
	else if(stage == STAGE_TWO)
	{
		if(faintedcounter[0] == true && faintedcounter[1] == true && faintedcounter[2] == true && faintedcounter[3] == true && faintedcounter[4] == true && faintedcounter[5] == true && faintedcounter[6] == true && faintedcounter[7] == true && faintedcounter[8] == true && faintedcounter[9] == true && faintedcounter[10] == true && faintedcounter[11] == true && faintedcounter[12] == true && faintedcounter[13] == true && faintedcounter[14] == true && faintedcounter[15] == true && faintedcounter[16] == true && faintedcounter[17] == true && faintedcounter[18] == true && faintedcounter[19] == true)
		{
			herohealth = 200;
			markerarray = 0

			messagestarttime = parseInt(new Date().getTime()/1000);
			
			initial_time = parseInt(new Date().getTime()/1000);

			stage = STAGE_THREE;
				
			issikdishown = false;
			istaklashown = false;

			isfattyshown = true;
				
			for(i=0;i<20;i++)
			{
				isvillainvisible[i] = false;
			}

			if(herohealth <= 0)
			{
				herohealth = 200;
				LIFE = LIFE - 1;
					
				lifeseq = lifearray[3-LIFE]; 
			}
				
			isgamescreenimagescreated = false;
			isnextstagemsgvisble = true;
		}
	}
/////////////////////////////
	else if(stage == STAGE_THREE)
	{
		if(faintedcounter[0] == true && faintedcounter[1] == true && faintedcounter[2] == true && faintedcounter[3] == true && faintedcounter[4] == true && faintedcounter[5] == true && faintedcounter[6] == true && faintedcounter[7] == true && faintedcounter[8] == true && faintedcounter[9] == true && faintedcounter[10] == true && faintedcounter[11] == true && faintedcounter[12] == true && faintedcounter[13] == true && faintedcounter[14] == true && faintedcounter[15] == true && faintedcounter[16] == true && faintedcounter[17] == true && faintedcounter[18] == true && faintedcounter[19] == true)
		{
			herohealth = 200;
			markerarray = 0

			messagestarttime = parseInt(new Date().getTime()/1000);
			
			initial_time = parseInt(new Date().getTime()/1000);

			issikdishown = false;
			istaklashown = false;
			isfattyshown = false;
			isherovisible = false;
			isgirlvisible = false;
			ispausebtnvisible = false;

			
			for(i=0;i<20;i++)
			{
				isvillainvisible[i] = false;
			}

			if(herohealth <= 0)
			{
				herohealth = 200;
				LIFE = LIFE - 1;
					
				lifeseq = lifearray[3-LIFE]; 
			}
				
			isgamescreenimagescreated = false;
			isnextstagemsgvisble = false;
			
			isendgame = true;
		}
	}

/////////////////////////////	

	for(i=0;i<20;i++)
	{
		if(isvillainvisible[i] == true)
		{
			if(herohealth > 0)
			{
				if(failtoprotect == false)
				{
					if(coordy[i] >= (height - 128-64+18))
					{
						failtoprotect = true;

						if(stage == STAGE_ONE)
						{
							sikdiindex = sikdifainted - 1;
							issikdishown = true;
								
							for(j=sikdiindex;j<20;j++)
							{
								coordy[j] = -64;
								inrange[j] = false;
								ishero_outofrange[j] = true;
								isvillainvisible[j] = false;
							}
						}
						else if(stage == STAGE_TWO)
						{
							taklaindex = taklafainted - 1;
							istaklashown = true;
								
							for(j=taklaindex;j<20;j++)
							{
								coordy[j] = -64;
								inrange[j] = false;
								ishero_outofrange[j] = true;
								isvillainvisible[j] = false;
							}
						}
						else if(stage == STAGE_THREE)
						{
							fattyindex = fattyfainted - 1;
							isfattyshown = true;
								
							for(j=fattyindex;j<20;j++)
							{
								coordy[j] = -64;
								inrange[j] = false;
								ishero_outofrange[j] = true;
								isvillainvisible[j] = false;
							}
						}
		
						messagestarttime = parseInt(new Date().getTime()/1000);
								
						break;
					}
				}
			}
		}
	}
	
/////////////////////////////	
//////////////////////////////////////////	
	
	for(i=0;i<20;i++)
	{
		if(isvillainvisible[i] == true)
		{
		
			if(isvillainfainted[i] == true)
			{
				if(stage == STAGE_ONE)
				{
					var count = sikdicounter[i];
					sikdiarray[i] = sikdimotionfainted[count];
					ANIMATIONCOUNTERLIMIT[i] = 16;
				}
				else if(stage == STAGE_TWO)
				{
					var count = taklacounter[i];
					taklaarray[i] = taklamotionfainted[count];
					ANIMATIONCOUNTERLIMIT[i] = 17;
				}
				else if(stage == STAGE_THREE)
				{
					var count = fattycounter[i];
					fattyarray[i] = fattymotionfainted[count];
					ANIMATIONCOUNTERLIMIT[i] = 17;
				}
			}
			else
			{
				if(stage == STAGE_ONE)
				{
					var count = sikdicounter[i];
					sikdiarray[i] = sikdimotion[count];
				}
				else if(stage == STAGE_TWO)
				{
					var count = taklacounter[i];
					taklaarray[i] = taklamotion[count];
				}
				else if(stage == STAGE_THREE)
				{
					var count = fattycounter[i];
					fattyarray[i] = fattymotion[count];
				}

				ANIMATIONCOUNTERLIMIT[i] = 3;
			}
			
			if(issikdishown == true)
			{
				if((dirleft[i] == true || dirright[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(sikdi[i], 0, sikdiarray[i], 64, 64, coordx[i], coordy[i], 64, 64);
				}
				else if((dirup[i] == true || dirdown[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(sikdi[i], sikdiarray[i], 0, 64, 64, coordx[i], coordy[i], 64, 64);
				}
			}

			else if(istaklashown == true)
			{
				if((dirleft[i] == true || dirright[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(takla[i], 0, taklaarray[i], 64, 64, coordx[i], coordy[i], 64, 64);
				}
				else if((dirup[i] == true || dirdown[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(takla[i], taklaarray[i], 0, 64, 64, coordx[i], coordy[i], 64, 64);
				}
			}

			else if(isfattyshown == true)
			{
				if((dirleft[i] == true || dirright[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(fatty[i], 0, fattyarray[i], 64, 64, coordx[i], coordy[i], 64, 64);
				}
				else if((dirup[i] == true || dirdown[i] == true) && isvillainvisible[i] == true)
				{
					ctx.drawImage(fatty[i], fattyarray[i], 0, 64, 64, coordx[i], coordy[i], 64, 64);
				}
			}
			
			if(isengageinfight[i] == false)
				coordy[i] += 1; 
		}
	}
	
	ctx.drawImage(marker, 0, markerarray, 100, 16, width-(120+16), 28, 100, 16);

	
//////////////////////////////////////////
//////////////////////////////////////////	


	for(i=0;i<20;i++)
	{
		if(stage == STAGE_ONE)
		{
			time_final[i] = parseInt(new Date().getTime());
			
			if((time_final[i] - time_initial[i]) > 80)
			{
				sikdicounter[i]++;
				time_initial[i] = time_final[i];
			}
		}
		else if(stage == STAGE_TWO)
		{
			time_final[i] = parseInt(new Date().getTime());
			
			if((time_final[i] - time_initial[i]) > 100)
			{
				taklacounter[i]++;
				time_initial[i] = time_final[i];
			}
		}
		else if(stage == STAGE_THREE)
		{
			time_final[i] = parseInt(new Date().getTime());
			
			if((time_final[i] - time_initial[i]) > 120)
			{
				fattycounter[i]++;
				time_initial[i] = time_final[i];
			}
		}
	}
	
	for(i=0;i<20;i++)
	{
		if(stage == STAGE_ONE)
		{
			if(sikdicounter[i] > 16)
			{
				isvillainvisible[i] = false;
			}
		}
		else if(stage == STAGE_TWO)
		{
			if(taklacounter[i] > 17)
			{
				isvillainvisible[i] = false;
			}
		}
		else if(stage == STAGE_THREE)
		{
			if(fattycounter[i] > 17)
			{
				isvillainvisible[i] = false;
			}
		}
	}
	
	for(i=0;i<20;i++)
	{
		if(stage == STAGE_ONE)
		{
			if(sikdicounter[i] > ANIMATIONCOUNTERLIMIT[i])
				sikdicounter[i] = 0;
		}
		else if(stage == STAGE_TWO)
		{
			if(taklacounter[i] > ANIMATIONCOUNTERLIMIT[i])
				taklacounter[i] = 0;
		}
		else if(stage == STAGE_THREE)
		{
			if(fattycounter[i] > ANIMATIONCOUNTERLIMIT[i])
				fattycounter[i] = 0;
		}
	}
}

function resetcommonvar()
{
	for(j=0;j<20;j++)
	{
	    coordy[j] = -64;
	    villainhealth[j] = 100;
	    faintedcounter[j] = false;
	    faintedcounted[j] = false;
	    inrange[j] = false;
	    ishero_outofrange[j] = true;

	    dirleft[j] = false;
	    dirright[j] = false;
	    dirup[j] = false;
	    dirdown[j] = false;
	}
}

function drawpausescreen()
{
	backgroundimg = menu;
	

	ctx.clearRect(0, 0, width, height);
	ctx.drawImage(backgroundimg, 0, 0, width, height);

	ctx.drawImage(resumeicon, width-(150+16), (height/10)+20, 150, 32);
	ctx.drawImage(replayicon, width-(150+16), (height/10)+20+40+20, 150, 32);
	ctx.drawImage(mainmenuicon, width-(150+16), (height/10)+20+40+20+40+20, 150, 32);
	
}

window[ addEventListener ? 'addEventListener' : 'attachEvent' ]( addEventListener ? 'load' : 'onload', init );
}
//****************************

var ctrlctr = 0;

document.onkeydown = function(e) {
	ispointerpressed = true;

	switch (e.keyCode) {
		case 37:
						//event.preventDefault();
			ispointerpressed = true;

			heromoveleft();

			leftwalk = true;
			upwalk = false;
			downwalk = false;
			rightwalk = false;

			heroupleftpunch = false;
			herouprightpunch = false;

			herodownleftpunch = false;
			herodownrightpunch = false;

			heroleftleftpunch = false;
			heroleftrightpunch = false;

			herorightleftpunch = false;
			herorightrightpunch = false;

			heroleftdir = true;
			herorightdir = false;
			heroupdir = false;
			herodowndir = false;

			break;
		case 38:
						//event.preventDefault();
			ispointerpressed = true;

			heromoveup();

			upwalk = true;
			downwalk = false;
			leftwalk = false;
			rightwalk = false;

			heroupleftpunch = false;
			herouprightpunch = false;

			herodownleftpunch = false;
			herodownrightpunch = false;

			heroleftleftpunch = false;
			heroleftrightpunch = false;

			herorightleftpunch = false;
			herorightrightpunch = false;

			heroleftdir = false;
			herorightdir = false;
			heroupdir = true;
			herodowndir = false;
			break;
		case 39:
						//event.preventDefault();
			ispointerpressed = true;

			heromoveright();

			rightwalk = true;
			upwalk = false;
			leftwalk = false;
			downwalk = false;

			heroupleftpunch = false;
			herouprightpunch = false;

			herodownleftpunch = false;
			herodownrightpunch = false;

			heroleftleftpunch = false;
			heroleftrightpunch = false;

			herorightleftpunch = false;
			herorightrightpunch = false;

			heroleftdir = false;
			herorightdir = true;
			heroupdir = false;
			herodowndir = false;
			break;
		case 40:
						//event.preventDefault();
			ispointerpressed = true;

			heromovedown();

			downwalk = true;
			upwalk = false;
			leftwalk = false;
			rightwalk = false;

			heroupleftpunch = false;
			herouprightpunch = false;

			herodownleftpunch = false;
			herodownrightpunch = false;

			heroleftleftpunch = false;
			heroleftrightpunch = false;

			herorightleftpunch = false;
			herorightrightpunch = false;

			heroleftdir = false;
			herorightdir = false;
			heroupdir = false;
			herodowndir = true;
			break;

		case 32:
			ctrlctr++;
			if(ctrlctr%2 == 0)
			{
							//event.preventDefault();
				ispointerpressed = true;

				if(upwalk == true && heroupdir == true)
				{
					heroupleftpunchchange();

					heroupleftpunch = true;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
				else if(downwalk == true && herodowndir == true)
				{
					herodownleftpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = true;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
			///////////////////////////
				else if(leftwalk == true && heroleftdir == true)
				{
					heroleftleftpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = true;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
				else if(rightwalk == true && herorightdir == true)
				{
					herorightleftpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = true;
					herorightrightpunch = false;
				}

				for(i=0;i<20;i++)
				{
					if(inrange[i] == true && ((heroleftdir == true && dirright[i] == true) || (heroupdir == true && dirdown[i] == true) || (herorightdir == true && dirleft[i] == true) || (herodowndir == true && dirup[i] == true)))
					{
						if(stage == STAGE_ONE)
						{
							villainhealth[i] -= SIKDIHURT;
						}
						else if(stage == STAGE_TWO)
						{
							villainhealth[i] -= TAKLAHURT;
						}
						else if(stage == STAGE_THREE)
						{
							villainhealth[i] -= FATTYHURT;
						}
					}
				}

			}
			else
			{
							//event.preventDefault();
				ispointerpressed = true;

				if(upwalk == true && heroupdir == true)
				{
					herouprightpunchchange();

					heroupleftpunch = false;
					herouprightpunch = true;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
				else if(downwalk == true && herodowndir == true)
				{
					herodownrightpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = true;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
			////////////////////////////
				else if(leftwalk == true && heroleftdir == true)
				{
					heroleftrightpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = true;

					herorightleftpunch = false;
					herorightrightpunch = false;
				}
				else if(rightwalk == true && herorightdir == true)
				{
					herorightrightpunchchange();

					heroupleftpunch = false;
					herouprightpunch = false;

					herodownleftpunch = false;
					herodownrightpunch = false;

					heroleftleftpunch = false;
					heroleftrightpunch = false;

					herorightleftpunch = false;
					herorightrightpunch = true;
				}

				for(i=0;i<20;i++)
				{
					if(inrange[i] == true && ((heroleftdir == true && dirright[i] == true) || (heroupdir == true && dirdown[i] == true) || (herorightdir == true && dirleft[i] == true) || (herodowndir == true && dirup[i] == true)))
					{
						if(stage == STAGE_ONE)
						{
							villainhealth[i] -= SIKDIHURT;
						}
						else if(stage == STAGE_TWO)
						{
							villainhealth[i] -= TAKLAHURT;
						}
						else if(stage == STAGE_THREE)
						{
							villainhealth[i] -= FATTYHURT;
						}
					}
				}
			}
			break;

		case 27:
			if(isgameover == false)
				_whichscreen = PAUSESCREEN;
	}
};


document.onkeyup = function(e) {
	ispointerpressed = false;
}