-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.min.js
102 lines (102 loc) · 22.9 KB
/
script.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var pfx=["webkit","moz","MS","o",""];function PrefixedEvent(a,b,d){for(var c=0;c<pfx.length;c++){if(!pfx[c]){b=b.toLowerCase();}a.addEventListener(pfx[c]+b,d,false);
}}window.requestAnimationFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b,a){window.setTimeout(b,1000/60);
};})();function setCookie(a,d,b){var e=new Date();e.setDate(e.getDate()+b);var c=escape(d)+((b===null)?"":"; expires="+e.toUTCString());document.cookie=a+"="+c;
}function getCookie(b){var c=document.cookie;var d=c.indexOf(" "+b+"=");if(d==-1){d=c.indexOf(b+"=");}if(d==-1){c=null;}else{d=c.indexOf("=",d)+1;var a=c.indexOf(";",d);
if(a==-1){a=c.length;}c=unescape(c.substring(d,a));}return c;}var User=function(){return{name:"Player 1",points:0,life:3,cont:{level:0,points:0,num:3,life:3}};
};var Bonus=function(b,a,d,c){this.status=false;this.canvas=b;this.ctx=a;this.r=("createTouch" in document)?15:20;this.cX=d;this.cY=c;this.strokeColor="rgb(255,255,255)";
this.fillStyle="#7F1313";this.counter=0;};Bonus.prototype.draw=function(){this.counter++;var a=this.ctx;a.beginPath();this.cX+=2;this.cY+=Math.sin(this.counter/10);
a.arc(this.cX,this.cY,this.r,0,2*Math.PI);a.fillStyle=this.fillStyle;a.fill();if(this.cX-this.r>this.canvas.width){return false;}else{return true;}};var Timer=function(b,a,c,e,d){this.canvas=b;
this.ctx=a;this.r=("createTouch" in document)?15:20;this.speed=c;this.cX=e;this.cY=d;this.strokeColor="rgb(255,255,255)";this.fillStyle="";this.fillStyle="rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
this.circ=0;this.counter=0;this.points=0;this.pointsFactor=1;this.lastClickTime=0;this.lastUpdate=0;this.clicked=0;this.animation=0;this.updateArc=function(g,h){if(this.circ<2){var f=new Date().getTime();
this.counter+=(60/g)*this.speed;this.points=Math.floor(this.counter/3.27)*this.pointsFactor;this.circ=this.counter*0.006;this.lastUpdate=f;return true;
}else{this.kill(h);return false;}};};Timer.prototype.isAnimation=function(){return this.animation;};Timer.prototype.isClicked=function(){return this.clicked;
};Timer.prototype.setClicked=function(){this.circ=99;this.clicked=true;};Timer.prototype.setAnimation=function(){this.circ=99;this.animation=true;};Timer.prototype.kill=function(a){if(typeof a!=="undefined"){if(typeof this.explosion==="undefined"){this.explosion=new TimerExplosion(this.ctx,this.r,this.cX,this.cY,(!this.isClicked())?1:2);
}this.explosion.run(a);}};Timer.prototype.draw=function(b,f,l){if(this.updateArc(f,l)){var m=this.ctx,h=this.canvas;var k=0,j=0;if(this.circ>1.5){k=Math.floor(Math.random()*10);
j=Math.floor(Math.random()*10);}else{if(this.circ>1){k=Math.floor(Math.random()*5);j=Math.floor(Math.random()*5);}else{if(this.circ>0.5){k=Math.floor(Math.random()*2);
j=Math.floor(Math.random()*2);}}}var d=(this.circ<0.25)?this.circ*4:1;var e=Math.floor(255-((Math.floor(1-this.circ)*-1)*(this.circ-1)*255));var a=Math.floor(255*this.circ)-(255-e)+1;
m.fillStyle="rgba("+a+","+e+",0,"+d+")";m.strokeStyle=(this.circ<0.25)?"rgb(0,255,0)":"rgb(0,0,0)";m.beginPath();m.arc(this.cX+k,this.cY+j,this.r,0,2*Math.PI);
m.stroke();m.fill();}};Timer.prototype.changeColor=function(a){this.strokeColor=a;};Timer.prototype.getPoints=function(){return this.points;};var TimerExplosion=function(b,d,a,e,c){this.ctx=b;
this.r=d;this.cx=a;this.cy=e;this.grown=1;this.animFrames=20;this.num=10;this.numSteps=30;this.type=c;};TimerExplosion.prototype.run=function(l){var h,c,j,d;
var e=1;var f=255-Math.round(this.num*2.55);d=(20-this.grown>0)?20-this.grown:0;this.ctx.beginPath();this.ctx.arc(this.cx,this.cy,d,0,2*Math.PI);this.ctx.fillStyle="rgba(255,"+f+",0,"+e+")";
this.ctx.fill();h=Math.floor(Math.random()-1)*Math.floor(Math.random()*(this.grown*2))+(this.cx+this.r/2);c=Math.floor(Math.random()-1)*Math.floor(Math.random()*(this.grown*2))+(this.cy+this.r/2);
this.ctx.beginPath();this.ctx.arc(h,c,d,0,2*Math.PI);this.ctx.fillStyle="rgba(255,"+f+",0,"+e+")";this.ctx.fill();for(var k=0,g=(2*Math.PI),b=(Math.PI/this.num);
k<g;k+=b){if(this.type===2){j=(Math.round(Math.random())-1)*(Math.floor(Math.random()*10)+1);rDyn=this.r+j;h=this.cx+Math.sin(k)*(rDyn);c=this.cy+Math.cos(k)*(rDyn);
}else{j=(Math.round(Math.random())-1)*(Math.floor(Math.random()*5)+1);rDyn=this.r+j;h=this.cx+Math.sin(k)*(rDyn);c=this.cy+Math.cos(k)*(rDyn);}this.ctx.beginPath();
this.ctx.moveTo(h,c);this.ctx.lineTo(h-1,c-1);this.ctx.strokeStyle="rgba(255,"+f+",0,"+e+")";this.ctx.stroke();}if(this.grown>=20){l();}else{this.grown++;
}};var App={debug:false,interval:false,timers:[],timersPos:[],level:0,r:20,levelLabel:function(){return this.level+1;},status:"stop",mode:"",countDownValue:-1,lastSecond:0,bonus:{},shakeCounter:0,shakeActive:false,actualFramerate:60,framerateCounter:0,logoInterval:true,continueOn:false,levelsDataArcade:[{level:1,timersMax:4,countDown:15,pointsNeeded:800,speed:[1,1.3,1.5],bonus:1},{level:2,timersMax:4,countDown:15,pointsNeeded:1000,speed:[1,1.3,1.5,1.7],bonus:1},{level:3,timersMax:5,countDown:15,pointsNeeded:1200,speed:[1,1.3,1.5,1.7,2],bonus:1},{level:4,timersMax:5,countDown:15,pointsNeeded:1400,speed:[1,1.5,1.7,2,2.5],bonus:1},{level:5,timersMax:6,countDown:15,pointsNeeded:2000,speed:[1,1.5,1.7,2,2.5,2.7],bonus:5},{level:6,timersMax:6,countDown:20,pointsNeeded:2200,speed:[1,1.5,1.7,2,2.5,2.7,3],bonus:5},{level:7,timersMax:7,countDown:20,pointsNeeded:2400,speed:[1,1.5,1.7,2,2.5,2.7,3],bonus:5},{level:8,timersMax:7,countDown:20,pointsNeeded:2600,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:9,timersMax:8,countDown:20,pointsNeeded:3000,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:10,timersMax:10,countDown:20,pointsNeeded:3200,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:11,timersMax:12,countDown:25,pointsNeeded:3400,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:12,timersMax:14,countDown:25,pointsNeeded:3800,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:13,timersMax:15,countDown:27,pointsNeeded:4500,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:14,timersMax:15,countDown:30,pointsNeeded:6000,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},{level:15,timersMax:15,countDown:30,pointsNeeded:8000,speed:[1,1.5,1.7,2,2.3,2.5,2.7,3],bonus:5},],levelsDataSurvivor:[{level:1,timersMax:3,countDown:15,pointsNeeded:0,speed:[1,1.5],bonus:1,},{level:2,timersMax:3,countDown:15,pointsNeeded:0,speed:[1,1.5,1.7],bonus:1,},{level:3,timersMax:4,countDown:15,pointsNeeded:0,speed:[1,1.5,1.7,1.9],bonus:2,},{level:4,timersMax:5,countDown:17,pointsNeeded:0,speed:[1,1.5,1.7,1.9],bonus:2,},{level:5,timersMax:5,countDown:20,pointsNeeded:0,speed:[1,1.5,1.7,1.9,2],bonus:3,},{level:6,timersMax:6,countDown:20,pointsNeeded:0,speed:[1.5,1.7,1.9,2],bonus:3,},{level:7,timersMax:6,countDown:20,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.2],bonus:4,},{level:8,timersMax:6,countDown:20,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.3,2.5],bonus:4,},{level:9,timersMax:7,countDown:20,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.3,2.5],bonus:6,},{level:10,timersMax:7,countDown:20,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.3,2.5,2.7],bonus:6,},{level:11,timersMax:8,countDown:25,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.3,2.5,2.7],bonus:8,},{level:12,timersMax:8,countDown:25,pointsNeeded:0,speed:[1.5,1.7,1.9,2,2.3,2.5,2.7,2.9],bonus:9,},{level:13,timersMax:9,countDown:30,pointsNeeded:0,speed:[1.7,1.9,2,2.3,2.5,2.7,3],bonus:10,},{level:14,timersMax:10,countDown:30,pointsNeeded:0,speed:[1.7,1.9,2,2.3,2.5,2.7,3,3.1],bonus:10,},{level:15,timersMax:5,countDown:30,pointsNeeded:0,speed:[1.7,1.9,2,2.3,2.5,2.7,3,3.1,3.3],bonus:10,}],getSpeed:function(){return this.getLevelData().speed[Math.floor(Math.random()*this.getLevelData().speed.length)];
},getLevelData:function(){if(this.mode==="survivor"){return this.levelsDataSurvivor[this.level];}else{return this.levelsDataArcade[this.level];}},init:function(){setTimeout(function(){window.scrollTo(0,0);
},10);var m=this;var d="createTouch" in document;this.user=new User();this.menuContainer=document.getElementById("menu-container");this.gameContainer=document.getElementById("game-container");
this.hud=document.getElementById("hud");this.endGameContainer=document.getElementById("endgame-container");this.canvas=document.getElementById("game-stage");
this.ctx=this.canvas.getContext("2d");var l=function(u){if(window.innerWidth<1024){u.width=window.innerWidth-2;}else{document.getElementById("general-container").style.width=u.width-2;
document.getElementById("menu-container").style.width=u.width-2;document.getElementById("tutorial-container").style.width=u.width-2;}if(window.innerHeight<768){document.body.style.height=window.innerHeight+"px";
u.height=window.innerHeight-2;document.getElementById("tutorial-container").style.height=(window.innerHeight-32)+"px";document.getElementById("general-container").style.width=u.width-2;
document.getElementById("menu-container").style.width=u.width-2;}};l(this.canvas);var g=getCookie("c_username");if(g!==null){document.getElementById("player-input").value=g;
}window.onresize=function(u){l(m.canvas);};document.getElementById("player-form").addEventListener("submit",function(u){u.preventDefault();if(document.getElementById("player-input").value!==""){m.user.name=document.getElementById("player-input").value;
m.startGame(u);}return false;});var q="";if(d){q="touchstart";this.canvas.addEventListener("touchstart",function(u){u.preventDefault();m.getTimerTouched(u);
return false;});this.canvas.addEventListener("touchmove",function(u){u.preventDefault();if("status" in m.bonus&&m.bonus.status===true){m.getTimerTouched(u);
}});}else{q="click";this.canvas.addEventListener("click",function(u){m.getTimerClicked(u);return false;});}document.getElementById("status").addEventListener(q,function(u){m.startPauseGame(u);
return false;});document.getElementById("change-level-start").addEventListener(q,function(u){m.startPauseGame(u);return false;});document.getElementById("how-to-play").addEventListener(q,function(u){document.getElementById("tutorial-container").className="";
document.getElementById("menu-container").className="hidden";return false;});document.getElementById("close-how-to-play").addEventListener(q,function(u){document.getElementById("tutorial-container").className="hidden";
document.getElementById("menu-container").className="";return false;});document.getElementById("start-game-arcade").addEventListener(q,function(u){m.mode="arcade";
m.showPreStartGraphics();return false;});document.getElementById("start-game-survivor").addEventListener(q,function(u){m.mode="survivor";m.showPreStartGraphics();
return false;});document.getElementById("start-game").addEventListener(q,function(u){u.preventDefault();if(document.getElementById("player-input").value!==""){m.user.name=document.getElementById("player-input").value;
}m.startGame(u);return false;});var n=document.getElementById("logo");n.width=300;n.height=300;var p=n.getContext("2d");var s,r;var f=document.getElementById("show-timer-2");
f.width=30;f.height=30;var t=f.getContext("2d");var j,h;var b=document.getElementById("show-timer-madness");b.width=this.canvas.width-2;b.height=60;var e=b.getContext("2d");
var c=-20;var a;var k=document.getElementById("show-timer-swipe");function o(){p.clearRect(0,0,n.width,n.height);t.clearRect(0,0,f.width,f.height);e.clearRect(0,0,b.width,b.height);
s=Math.floor(Math.random()*40)-20;r=Math.floor(Math.random()*40)-20;p.beginPath();p.arc(150+s,150+r,100,0,2*Math.PI);p.fillStyle="rgb(255,0,0)";p.fill();
j=Math.floor(Math.random()*2)-1;canvas2aRndY=Math.floor(Math.random()*2)-1;t.beginPath();t.arc(15+j,15+canvas2aRndY,10,0,2*Math.PI);t.fillStyle="rgb(180,255,0)";
t.fill();c=(c>b.width+50)?-20:c+2;a=Math.sin(c/10)*5+15;e.beginPath();e.arc(c,a,10,0,2*Math.PI);e.fillStyle="#7F1313";e.fill();if(m.logoInterval===true){requestAnimationFrame(o);
}}requestAnimationFrame(o);},showPreStartGraphics:function(){this.menuContainer.className="hidden";document.getElementById("player-container").className="";
},startPauseGame:function(b){b.preventDefault();if(this.status==="play"){this.status="pause";this.updateHUD();this.interval=false;}else{var a=this;document.getElementById("change-level-start").className="hidden";
document.getElementById("change-level").className="hidden";a.runGameInterval();}return false;},runGameInterval:function(){this.status="play";this.interval=true;
var b=this;this.lastSecond=new Date().getTime();var d=0;var c=new Date().getTime();function a(){b.gameLoop();if(new Date().getTime()-c>=1000){b.framerate=d;
d=0;c=new Date().getTime();}else{d++;}if(b.interval===true){requestAnimationFrame(a);}}requestAnimationFrame(a);},startGame:function(b){b.preventDefault();
setCookie("c_username",this.user.name,365);this.logoInterval=false;document.getElementById("player-container").className="hidden";document.getElementById("player-input").blur();
this.hud.className="";this.updateHUD();var a=this;setTimeout(function(){a.startLevel();a.runGameInterval();},1000);return false;},restartGame:function(a){window.location.reload(true);
return false;},startLevel:function(){this.countDownValue=this.getLevelData().countDown;},countDownLoop:function(){var d=new Date().getTime();var b=this.r,g=this.canvas.width-this.r,h=50+this.r,f=this.canvas.height-this.r;
this.framerateCounter++;if(d-this.lastSecond>=1000){this.lastSecond=d;this.actualFramerate=this.framerateCounter;this.framerateCounter=0;this.countDownValue--;
if(this.countDownValue<=0){this.changeLevel();}else{if(typeof this.bonus.status==="undefined"){var e=Math.floor(Math.random()*100);if(e<=this.getLevelData().bonus){var c=0;
var a=Math.floor(Math.random()*(f-h+1))+h;this.bonus=new Bonus(this.canvas,this.ctx,c,a);}}}}},changeLevel:function(){if((this.user.points>=this.getLevelData().pointsNeeded&&this.mode==="arcade")||this.mode==="survivor"){console.log(this.getLevelData().level+" -> "+this.user.points);
this.status="changing-level";this.level++;this.bonus={};this.canvas.style.backgroundColor="";this.user.cont.level=this.level;this.user.cont.points=this.user.points;
this.user.cont.life=this.user.life;var a=this;if(typeof this.getLevelData()==="undefined"){if(this.shakeActive!==true){this.gameOver();}}else{for(var b in a.timers){a.timers[b].setAnimation();
}this.changeLevelAnimation();if(this.mode==="arcade"){this.user.points=0;}}}else{if(this.shakeActive!==true){this.gameOver();}}},changeLevelAnimation:function(){var a=this;
this.shakeActive=true;setTimeout(function(){a.canvas.style.backgroundColor="rgb(0,0,0)";a.interval=false;a.timers=[];a.timersPos=[];a.startLevel();a.shakeCounter=0;
a.shakeActive=false;document.getElementById("change-level-value").innerHTML=a.levelLabel();document.getElementById("change-level").className="level-animation";
a.ctx.clearRect(0,0,a.canvas.width,a.canvas.height);PrefixedEvent(document.getElementById("change-level"),"AnimationEnd",function(){document.getElementById("change-level").className="show-level";
document.getElementById("change-level-start").className="show-level-start";a.status="pause";},false);},2000);},setBonusActive:function(){this.bonus.activationTime=new Date().getTime();
this.bonus.status=true;this.canvas.style.backgroundColor="#7F1313";},setBonusInActive:function(){this.bonus={};this.canvas.style.backgroundColor="";},gameLoop:function(){var p=this;
var m,r=false,h=this.r,d=this.canvas.width-this.r,g=50+this.r,b=this.canvas.height-this.r-50;if(this.status!=="changing-level"){var e=new Date().getTime();
if(typeof this.bonus.activationTime!=="undefined"&&e-this.bonus.activationTime>=3000){this.setBonusInActive();}this.countDownLoop();if(typeof this.getLevelData()!=="undefined"){if(this.timers.length<this.getLevelData().timersMax){var a=Math.floor(Math.random()*(d-h+1))+h;
var q=Math.floor(Math.random()*(b-g+1))+g;var o={x:a,y:q};for(m=0;m<this.timersPos.length;m++){if((a>=this.timersPos[m].x-this.r&&a<=this.timersPos[m].x+this.r)||(q>=this.timersPos[m].y-this.r&&q<=this.timersPos[m].y+this.r)){r=true;
}}if(!r){var l=new Timer(this.canvas,this.ctx,this.getSpeed(),a,q);this.timers.push(l);this.timersPos.push(o);}}}}else{p.ctx.clearRect(0,0,p.canvas.width,p.canvas.height);
}if(this.shakeActive===true){this.shakeCounter++;var n=(6*this.shakeCounter);this.canvas.style.backgroundColor="rgb("+n+","+n+","+n+")";}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
this.updateHUD();if(this.bonus.status===false){if(!this.bonus.draw()){this.bonus={};}}var f=function(){if(p.mode==="survivor"&&!p.timers[k].isClicked()&&!p.timers[k].isAnimation()){p.user.life--;
}p.removeTimer(k);p.updateHUD();if(p.user.life<=0&&p.shakeActive!==true){p.gameOver();}};if(this.shakeCounter<=10){for(var k in this.timers){this.timers[k].draw((this.bonus.status===true),this.actualFramerate,f);
}}},getTimerTouched:function(d){var e=d.changedTouches;if(this.status==="play"){for(var c=0;c<e.length;c++){var a=e[c].pageX-this.canvas.offsetLeft,f=e[c].pageY-this.canvas.offsetTop;
if(false){this.ctx.beginPath();this.ctx.arc(a,f,20,0,2*Math.PI);this.ctx.strokeStyle="red";this.ctx.fillStyle="red";this.ctx.fill();}for(c=0;c<this.timersPos.length;
c++){var b=10;if((a>=this.timersPos[c].x-(this.r+b)&&a<=this.timersPos[c].x+(this.r+b))&&(f>=this.timersPos[c].y-(this.r+b)&&f<=this.timersPos[c].y+(this.r+b))){this.timers[c].changeColor("red");
this.user.points+=this.timers[c].getPoints();this.timers[c].setClicked();}}if(this.bonus.status===false){if((a>=this.bonus.cX-this.bonus.r&&a<=this.bonus.cX+this.bonus.r)&&(f>=this.bonus.cY-this.bonus.r&&f<=this.bonus.cY+this.bonus.r)){this.setBonusActive();
}}}}},getTimerClicked:function(b){var a=b.pageX-this.canvas.offsetLeft,c=b.pageY-this.canvas.offsetTop;if(false){this.ctx.beginPath();this.ctx.arc(a,c,20,0,2*Math.PI);
this.ctx.strokeStyle="red";this.ctx.fillStyle="red";this.ctx.fill();}if(this.status==="play"){for(i=0;i<this.timersPos.length;i++){if((a>=this.timersPos[i].x-this.r&&a<=this.timersPos[i].x+this.r)&&(c>=this.timersPos[i].y-this.r&&c<=this.timersPos[i].y+this.r)){this.timers[i].changeColor("red");
this.user.points+=this.timers[i].getPoints();this.timers[i].setClicked();}}if(this.bonus.status===false){if((a>=this.bonus.cX-this.bonus.r&&a<=this.bonus.cX+this.bonus.r)&&(c>=this.bonus.cY-this.bonus.r&&c<=this.bonus.cY+this.bonus.r)){this.setBonusActive();
}}}},removeTimer:function(a){this.timers.splice(a,1);this.timersPos.splice(a,1);},gameOver:function(){this.shakeActive=true;var a=this;setTimeout(function(){this.shakeActive=false;
a.ctx.clearRect(0,0,a.canvas.width,a.canvas.height);a.endGameContainer.className="";a.gameContainer.className="hidden";a.hud.className="hidden";var e="createTouch" in document;
a.status="stop";a.interval=false;if(a.user.cont.num>0&&a.level>0&&typeof a.getLevelData()!=="undefined"){document.getElementById("endgame-container").innerHTML='<center> <p id="continue-timer" class="num-timer" >30</p><br> <span class="try-left">'+a.user.cont.num+' try left </span><br><center><a class="arcade-mode" href="#" id="continue">Continue</a></center><center><a class="survivor-mode" href="#" id="surrender">No, I surrender</a> </center></center>';
var d=30;var c=document.getElementById("continue-timer");var b=function(){setTimeout(function(){if(a.continueOn===true){d--;c.innerHTML=d;if(d>0){b();}else{a.surrender();
}}},1000);};a.continueOn=true;b();document.getElementById("continue").addEventListener((e)?"touchstart":"click",function(){a.continueMeth();});document.getElementById("surrender").addEventListener((e)?"touchstart":"click",function(){a.surrender();
});}else{a.surrender();}},1000);},continueMeth:function(){this.continueOn=false;this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);this.level=this.user.cont.level;
if(this.mode==="survivor"){this.user.points=0;}else{this.user.points=this.user.cont.points;}this.user.life=this.user.cont.life;this.user.cont.num--;this.startLevel();
this.endGameContainer.className="hidden";this.gameContainer.className="";this.hud.className="";this.changeLevelAnimation();},surrender:function(){this.continueOn=false;
if(typeof this.getLevelData()==="undefined"){alert("You WON!!!!");}else{alert("Game Over!!!!");}var a=getCookie(this.mode+"_record");var d=getCookie(this.mode+"_level_record");
if(typeof this.getLevelData()==="undefined"||a===null||d<this.getLevelData().level||(d==this.getLevelData().level&&a<this.user.points)){setCookie(this.mode+"_record",this.user.points,365);
setCookie(this.mode+"_level_record",this.getLevelData().level,365);document.getElementById("endgame-container").innerHTML='<center><p class="new-record">NEW RECORD!! </p><br> <span class="thank">Thank you '+this.user.name+' for playing </span><br> <span class="following">copy the following text and paste it into your favourite social network:</span><br><textarea class="text-fol" cols="50" rows="5">I played Timer Madness at '+window.location+" in "+this.mode.charAt(0).toUpperCase()+this.mode.substring(1)+" mode and I totalized "+this.user.points+" points at level "+this.levelLabel()+".</textarea><br><a class=\"arcade-mode\" href=\"#\" id=\"re-start-game\">Play again</a></center><center class='delete-rec' ><a href='#' id='delete-record'>Reset my record</a></center>";
}else{document.getElementById("endgame-container").innerHTML='<center><br><br><span class="thank">Thank you '+this.user.name+' for playing </span><br> <span class="following">copy the following text and paste it into your favourite social network:</span> <br><textarea class="text-fol" cols="50" rows="5">I played Timer Madness at '+window.location+" in "+this.mode.charAt(0).toUpperCase()+this.mode.substring(1)+" mode and I totalized "+this.user.points+" points at level "+this.levelLabel()+" </textarea><br><a class=\"arcade-mode\" href=\"#\" id=\"re-start-game\">Play again</a></center><center class='delete-rec' ><a href='#' id='delete-record'>Reset my record</a></center>";
}var c="createTouch" in document;var b=this;document.getElementById("re-start-game").addEventListener((c)?"touchstart":"click",this.restartGame);document.getElementById("delete-record").addEventListener((c)?"touchstart":"click",function(){setCookie(b.mode+"_record",b.user.points,-1);
setCookie(b.mode+"_level_record",b.user.points,-1);b.restartGame();});},updateHUD:function(){var f=document.getElementById("lives_pti_needed");var c=document.getElementById("lives_pti_needed_label");
var b=document.getElementById("timer");var l=document.getElementById("points");var a=document.getElementById("level");var d=document.getElementById("status");
var g,j;if(this.mode==="survivor"){c.innerHTML="Lives:";var h="";for(var e=0;e<this.user.life;e++){h+='<span class="heart"></span>';}f.innerHTML=h;}else{c.innerHTML="To go:";
var k=this.getLevelData().pointsNeeded;if(k-this.user.points>0){j=100*(k-this.user.points)/k;g=(k-this.user.points);if(j>50){f.className="redBar";}else{if(j>30){f.className="yellowBar";
}else{f.className="greenBar";}}}else{j=0;g="Ok";f.className="widthZero";}f.innerHTML=g;f.style.width=j+"px";}if(this.countDownValue<=0){j=100;g="";b.className="widthZero";
}else{j=100*this.countDownValue/this.getLevelData().countDown;g=this.countDownValue;if(j>50){b.className="greenBar";}else{if(j>30){b.className="yellowBar";
}else{b.className="redBar";}}}b.innerHTML=g;b.style.width=j+"px";l.innerHTML=this.user.points;a.innerHTML=this.levelLabel();if(this.status==="play"){d.innerHTML="<strong>X</strong> pause";
}else{if(this.status==="pause"){d.innerHTML="▶ play";}}}};