39,118
社区成员




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="gb2312">
<title>俄罗斯扇块</title>
</head>
<body style="margin:0px;padding:0px;">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
<canvas id="c"></canvas>
<script>
var c=document.getElementById("c");
var ctx=c.getContext("2d");
var screenwidth=document.width,screenheight=document.height;
c.width=document.width;
c.height=document.height;
var r=~~(Math.min(screenwidth,screenheight)/2);
var rot=0.0,app=0,approaching=false;
var grid=false,inverse=true,shadow=true;
var lp=0;
var keys=[];
var frame=0,mode=0,str="";
var HOME=0,GAME=1,CONTROLS=2,SETTINGS=3,GAMEOVER=4,DEMO=5;
var squares=[];
var score=0,times=0;
var int=40;
var touchxsec=6,touchysec=8;
var jcur=0,typecur=0,poscur=0,typenext=0,posnext=0;
var button=[];
var shapes=
[
[ [-1,0],[0,0],[1,0],[2,0] ],
[ [0,2],[0,1],[0,0],[0,-1] ],
[ [-1,0],[0,0],[1,0],[2,0] ],
[ [0,2],[0,1],[0,0],[0,-1] ],
[ [0,0],[0,-1],[-1,0],[-1,-1] ],
[ [0,0],[0,-1],[-1,0],[-1,-1] ],
[ [0,0],[0,-1],[-1,0],[-1,-1] ],
[ [0,0],[0,-1],[-1,0],[-1,-1] ],
[ [-1,0],[0,0],[0,1],[1,0] ],
[ [0,1],[0,0],[0,-1],[1,0] ],
[ [-1,0],[0,0],[0,-1],[1,0] ],
[ [0,1],[0,0],[0,-1],[-1,0] ],
[ [-1,1],[-1,0],[0,0],[1,0] ],
[ [0,1],[0,0],[0,-1],[1,1] ],
[ [-1,0],[0,0],[1,0],[1,-1] ],
[ [0,1],[0,0],[0,-1],[-1,-1] ],
[ [1,1],[1,0],[0,0],[-1,0] ],
[ [0,1],[0,0],[0,-1],[1,-1] ],
[ [1,0],[0,0],[-1,0],[-1,-1] ],
[ [0,1],[0,0],[0,-1],[-1,1] ],
[ [0,-1],[0,0],[1,0],[1,1] ],
[ [-1,0],[0,0],[0,-1],[1,-1] ],
[ [0,-1],[0,0],[1,0],[1,1] ],
[ [-1,0],[0,0],[0,-1],[1,-1] ],
[ [0,-1],[0,0],[-1,0],[-1,1] ],
[ [1,0],[0,0],[0,-1],[-1,-1] ],
[ [0,-1],[0,0],[-1,0],[-1,1] ],
[ [1,0],[0,0],[0,-1],[-1,-1] ]
];
var color=["#000","#FF0000","#00FF00","#0000FF","#FFFF00","FF00FF","#00FFFF"];
var imgbg=new Image();
imgbg.src="background.jpg";
//buttons
var buttons=function()
{
var xp=0.0,yp=0.0,wp=0.0,hp=0.0;
var border=true,bordercolor="#FFFFFF";
var text="",txp=0.0,typ=0.0,fzp=0.0,fc="#FFFFFF";
this.setpos=function(sxp,syp,swp,shp,sborder,sbordercolor)
{
xp=sxp;
yp=syp;
wp=swp;
hp=shp;
if(sborder!==undefined){border=sborder;}
if(sbordercolor!==undefined){bordercolor=sbordercolor;}
}
this.settext=function(stext,stxp,styp,sfzp,sfc)
{
text=stext;
if(stxp!==undefined){txp=stxp;}
if(styp!==undefined){typ=styp;}
if(sfzp!==undefined){fzp=sfzp;}
if(sfc!==undefined){fc=sfc;}
}
this.clickevent=function(){}
this.onclick=function(x,y)
{
if(x>r*xp&&x<r*(xp+wp)&&y>r*yp&&y<r*(yp+hp))
{
this.clickevent();
return true;
}
return false;
}
this.draw=function()
{
ctx.fillStyle=fc;
ctx.strokeStyle=bordercolor;
if(border){ctx.strokeRect(r*xp,r*yp,r*wp,r*hp);}
ctx.font=~~(fzp*r)+"px Comic Sans MS";
ctx.fillText(text,r*(txp+xp),r*(typ+yp));
}
}
//loadhomepagebuttons
function loadhomepagebuttons()
{
button=[];
button[0]=new buttons();
with(button[0])
{
setpos(0.7,0.6,0.6,0.2,false);
settext("START",0.04,0.15,0.15);
clickevent=function(){newgame();}
}
button[1]=new buttons();
with(button[1])
{
setpos(0.7,0.85,0.6,0.2,false);
settext("Controls",0.0,0.15,0.15);
clickevent=function(){loadcontrolsbuttons();mode=CONTROLS;}
}
button[2]=new buttons();
with(button[2])
{
setpos(0.7,1.1,0.6,0.2,false);
settext("Settings",0.0,0.15,0.15);
clickevent=function(){loadsettingsbuttons();mode=SETTINGS;}
}
}
//loadcontrolsbuttons
function loadcontrolsbuttons()
{
button=[];
button[0]=new buttons();
with(button[0])
{
setpos(0.8,1.45,0.4,0.1);
settext("BACK",0.1,0.08,0.08);
clickevent=function(){loadhomepagebuttons();mode=HOME;}
}
}
//loadgameoverbuttons
function loadgameoverbuttons()
{
button=[];
button[0]=new buttons();
with(button[0])
{
setpos(0.4,1.4,0.4,0.1,true,"#000");
settext("MENU",0.08,0.08,0.08,"#000");
clickevent=function(){loadhomepagebuttons();mode=HOME;}
}
button[1]=new buttons();
with(button[1])
{
setpos(1.0,1.4,0.4,0.1,true,"#000");
settext("RESTART",0.02,0.08,0.08,"#000");
clickevent=function(){newgame();}
}
}
//loaddemobuttons
function loaddemobuttons()
{
button=[];
button[0]=new buttons();
with(button[0])
{
setpos(0.8,1.6,0.4,0.1);
settext("BACK",0.1,0.08,0.08);
clickevent=function(){loadhomepagebuttons();mode=HOME;}
}
}
//loadsettingsbuttons
function loadsettingsbuttons()
{
button=[];
button[0]=new buttons();
with(button[0])
{
setpos(1.3,0.7,0.3,0.1);
if(grid){settext("ON",0.08,0.08,0.08);}else{settext("OFF",0.08,0.08,0.08);}
clickevent=function(){
grid=!grid;
if(grid){settext("ON");}else{settext("OFF");}
}
}
button[1]=new buttons();
with(button[1])
{
setpos(1.3,0.9,0.3,0.1);
if(shadow){settext("ON",0.08,0.08,0.08);}else{settext("OFF",0.08,0.08,0.08);}
clickevent=function(){
shadow=!shadow;
if(shadow){settext("ON");}else{settext("OFF");}
}
}
button[2]=new buttons();
with(button[2])
{
setpos(1.3,1.1,0.3,0.1);
if(inverse){settext("ON",0.08,0.08,0.08);}else{settext("OFF",0.08,0.08,0.08);}
clickevent=function(){
inverse=!inverse;
if(inverse){settext("ON");}else{settext("OFF");}
}
}
button[3]=new buttons();
with(button[3])
{
setpos(0.8,1.5,0.4,0.1);
settext("BACK",0.1,0.08,0.08);
clickevent=function(){loadhomepagebuttons();mode=HOME;}
}
}
var clickx=0,clicky=0,clickevent=false;
//mouse
function mousedown(e)
{
}
function mouseup(e)
{
clickevent=true;
clickx=e.pageX;
clicky=e.pageY;
}
//touch
var touchstartx=0,touchstarty=0,touch=false,multitouch=false;
function touchmove(e)
{
var x=e.targetTouches[0].pageX,y=e.targetTouches[0].pageY;
e.preventDefault();
clickx=e.targetTouches[0].pageX;
clicky=e.targetTouches[0].pageY;
if(multitouch)
{
}else
{
if(x-touchstartx>c.width/touchxsec)
{
keys[39]=true;
touchstartx=x;
touchstarty=y;
}else if(touchstartx-x>c.width/touchxsec)
{
keys[37]=true;
touchstartx=x;
touchstarty=y;
}
if((y-touchstarty>c.height/touchysec)&&touch)
{
keys[40]=true;
touch=false
touchstartx=x;
touchstarty=y;
}else if(touchstarty-y>c.height/touchysec)
{
keys[38]=true;
touchstartx=x;
touchstarty=y;
}
}
}
function touchend(e)
{
touch=false;
multitouch=false;
clickevent=true;
}
function touchstart(e)
{
e.preventDefault();
touchstartx=e.targetTouches[0].pageX;
touchstarty=e.targetTouches[0].pageY;
clickx=e.targetTouches[0].pageX;
clicky=e.targetTouches[0].pageY;
touch=true;
if(e.targetTouches.length>1){multitouch=true;}else{multitouch=false;}
}
//clearevents
function clearevents()
{
clickx=0;
clicky=0;
clickevent=false;
touchstartx=0;
touchstarty=0;
touch=false;
multitouch=false;
keys=[];
}
//drawfalling
function drawfalling(j,type,pos,c)
{
drawsquare(12+shapes[4*type+pos%4][0][0],j+shapes[4*type+pos%4][0][1],c,0);
drawsquare(12+shapes[4*type+pos%4][1][0],j+shapes[4*type+pos%4][1][1],c,0);
drawsquare(12+shapes[4*type+pos%4][2][0],j+shapes[4*type+pos%4][2][1],c,0);
drawsquare(12+shapes[4*type+pos%4][3][0],j+shapes[4*type+pos%4][3][1],c,0);
}
//clear
function clear()
{
var i=0,j=0,ul=0;
var blankline=true;
for(j=1;j<16;j++)
{
for(i=0;i<16;i++)
{
if(squares[i][j]==""){break;}
}
if(i==16)
{
for(;j<16;j++)
{
for(i=0;i<16;i++)
{
if(squares[i][j+1]!="")
{
blankline=false;
}
squares[i][j]=squares[i][j+1];
}
if(blankline){break;}
blankline=true;
}
for(i=0;i<16;i++){squares[i][j]="";}
return clear()+1;
}
}
return 0;
}
//fastsettle
function fastsettle(type,pos)
{
var i=-1,j=-1,sj=-1,si=-1;
for(var s=0;s<4;s++)
{
i=(28+shapes[4*type+pos%4][s][0]-app%16)%16;
for(j=15;j>0;j--)
{
if(squares[i][j]!=""){break;}
}
if(j-shapes[4*type+pos%4][s][1]>sj)
{
sj=j-shapes[4*type+pos%4][s][1];
si=i-shapes[4*type+pos%4][s][0];
}
}
sj++;
squares[(16+si+shapes[4*type+pos%4][0][0])%16][sj+shapes[4*type+pos%4][0][1]]=color[type];
squares[(16+si+shapes[4*type+pos%4][1][0])%16][sj+shapes[4*type+pos%4][1][1]]=color[type];
squares[(16+si+shapes[4*type+pos%4][2][0])%16][sj+shapes[4*type+pos%4][2][1]]=color[type];
squares[(16+si+shapes[4*type+pos%4][3][0])%16][sj+shapes[4*type+pos%4][3][1]]=color[type];
generatefalling();
i=clear();
times+=i>0;
score+=i*(i+1)/2;
}
//settle
function settle(j,type,pos)
{
if(squares[(28+shapes[4*type+pos%4][0][0]-app%16)%16][j+shapes[4*type+pos%4][0][1]-1]!=""||
squares[(28+shapes[4*type+pos%4][1][0]-app%16)%16][j+shapes[4*type+pos%4][1][1]-1]!=""||
squares[(28+shapes[4*type+pos%4][2][0]-app%16)%16][j+shapes[4*type+pos%4][2][1]-1]!=""||
squares[(28+shapes[4*type+pos%4][3][0]-app%16)%16][j+shapes[4*type+pos%4][3][1]-1]!="")
{
squares[(28+shapes[4*type+pos%4][0][0]-app%16)%16][j+shapes[4*type+pos%4][0][1]]=color[type];
squares[(28+shapes[4*type+pos%4][1][0]-app%16)%16][j+shapes[4*type+pos%4][1][1]]=color[type];
squares[(28+shapes[4*type+pos%4][2][0]-app%16)%16][j+shapes[4*type+pos%4][2][1]]=color[type];
squares[(28+shapes[4*type+pos%4][3][0]-app%16)%16][j+shapes[4*type+pos%4][3][1]]=color[type];
generatefalling();
i=clear();
times+=i>0;
score+=i*(i+1)/2;
}
}
//newgame
function newgame()
{
for(var i=0;i<16;i++)
{
squares[i]=new Array(18);
squares[i][0]="#000";
for(var j=1;j<18;j++)
{
squares[i][j]="";
}
}
mode=GAME;
score=0;
times=0;
int=40;
frame=0;
rot=0.0;
app=0;
typenext=0;
posnext=0;
clearevents();
generatefalling();
}
//main
function main()
{
frame++;
ctx.clearRect(0,0,c.width,c.height);
if(mode==GAME)
{
draw();
}else if(mode==HOME)
{
homepage();
}else if(mode==CONTROLS)
{
controls();
}else if(mode==GAMEOVER)
{
gamaoverpage();
}else if(mode==DEMO)
{
touchscreendemo();
}else if(mode==SETTINGS)
{
settings();
}
}
//keydown
function keydown(e)
{
keys[e.keyCode]=true;
switch(e.keyCode)
{
}
// alert(e.keyCode);
}
c.addEventListener("touchmove",touchmove,false);
c.addEventListener("touchstart",touchstart,false);
c.addEventListener("touchend",touchend,false);
c.addEventListener("mousedown",mousedown,false);
c.addEventListener("mouseup",mouseup,false);
window.addEventListener("keydown",keydown,false);
window.addEventListener("keyup",function(e){keys[e.keyCode]=false;},false);
for(var i=0;i<16;i++)
{
squares[i]=new Array(18);
squares[i][0]="#000";
for(var j=1;j<18;j++)
{
squares[i][j]="";
}
}
loadhomepagebuttons();
generatefalling();
lp=setInterval(main,30);
</script>
</body>
</html>
//drawnext
function drawnext(type,pos)
{
var l=0.293*r;
ctx.beginPath();
ctx.moveTo(Math.round(l*(2+shapes[type*4+pos][0][0])*0.2),Math.round(l*(3-shapes[type*4+pos][0][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][0][0])*0.2),Math.round(l*(3-shapes[type*4+pos][0][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][0][0])*0.2),Math.round(l*(4-shapes[type*4+pos][0][1])*0.2));
ctx.lineTo(Math.round(l*(2+shapes[type*4+pos][0][0])*0.2),Math.round(l*(4-shapes[type*4+pos][0][1])*0.2));
ctx.moveTo(Math.round(l*(2+shapes[type*4+pos][1][0])*0.2),Math.round(l*(3-shapes[type*4+pos][1][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][1][0])*0.2),Math.round(l*(3-shapes[type*4+pos][1][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][1][0])*0.2),Math.round(l*(4-shapes[type*4+pos][1][1])*0.2));
ctx.lineTo(Math.round(l*(2+shapes[type*4+pos][1][0])*0.2),Math.round(l*(4-shapes[type*4+pos][1][1])*0.2));
ctx.moveTo(Math.round(l*(2+shapes[type*4+pos][2][0])*0.2),Math.round(l*(3-shapes[type*4+pos][2][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][2][0])*0.2),Math.round(l*(3-shapes[type*4+pos][2][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][2][0])*0.2),Math.round(l*(4-shapes[type*4+pos][2][1])*0.2));
ctx.lineTo(Math.round(l*(2+shapes[type*4+pos][2][0])*0.2),Math.round(l*(4-shapes[type*4+pos][2][1])*0.2));
ctx.moveTo(Math.round(l*(2+shapes[type*4+pos][3][0])*0.2),Math.round(l*(3-shapes[type*4+pos][3][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][3][0])*0.2),Math.round(l*(3-shapes[type*4+pos][3][1])*0.2));
ctx.lineTo(Math.round(l*(3+shapes[type*4+pos][3][0])*0.2),Math.round(l*(4-shapes[type*4+pos][3][1])*0.2));
ctx.lineTo(Math.round(l*(2+shapes[type*4+pos][3][0])*0.2),Math.round(l*(4-shapes[type*4+pos][3][1])*0.2));
ctx.closePath();
ctx.fillStyle=color[type];
ctx.fill();
}
//settings
function settings()
{
if(clickevent)
{
for(var i=0;i<button.length;i++)
{
if(button[i].onclick(clickx,clicky)){break;}
}
clickevent=false;
}
animation();
ctx.fillStyle="rgba(0,0,0,0.3)";
ctx.fillRect(0,0,c.width,c.height);
ctx.fillStyle="rgba(70,70,250,0.6)";
ctx.fillRect(r*0.293,r*0.293,r*1.414,r*1.414);
ctx.fillStyle="#FFFFFF";
ctx.font=~~(0.1*r)+"px Comic Sans MS";
ctx.fillText("Settings",r*0.8,r*0.45);
ctx.font=~~(0.08*r)+"px Comic Sans MS";
ctx.fillText("Grid",r*0.4,r*0.8);
ctx.fillText("Shadow",r*0.4,r*1.0);
ctx.fillText("Reverse",r*0.4,r*1.2);
for(var i=0;i<button.length;i++)
{
button[i].draw();
}
}
//drawsquare
function drawsquare(i,j,c,ra)
{
if(i<0||i>15||j<1||j>15){return;}
var r1=r*(16-j)/15,r2=r*(15-j)/15,a=(i+ra)*Math.PI/8-Math.PI/16;
ctx.beginPath();
ctx.moveTo(r+Math.round(r1*Math.cos(a)),r-Math.round(r1*Math.sin(a)));
ctx.arc(r,r,Math.round(r1),-a,-a-Math.PI/8,true);
ctx.lineTo(r+Math.round(r2*Math.cos(a+Math.PI/8)),r-Math.round(r2*Math.sin(a+Math.PI/8)));
ctx.arc(r,r,Math.round(r2),-a-Math.PI/8,-a,false);
ctx.closePath();
ctx.fillStyle=c;
ctx.strokeStyle="#FFFFFF";
ctx.fill();
ctx.stroke();
var shadowalpha=0.0;
if(shadow)
{
for(var i=Math.round(r2);i<Math.round(r2)+r/30;i++)
{
ctx.beginPath();
ctx.arc(r,r,i,-a-0.008,-a-0.383,true);
ctx.moveTo(r+Math.round(i*Math.cos(a+Math.PI/8)),r-Math.round(i*Math.sin(a+Math.PI/8)));
ctx.closePath();
shadowalpha=(Math.round(r1)-i)*15/r*0.4;
ctx.strokeStyle="rgba(250,250,250,"+shadowalpha+")";
ctx.stroke();
}
}
}
//animation
function animation()
{
ctx.drawImage(imgbg,0,0,c.width,c.height,0,0,c.width,c.height);
if(frame%20==0){jcur--;if(jcur<-1){generatefalling();}}
ctx.beginPath();
ctx.arc(r,r,r,0,Math.PI*2,true);
ctx.arc(r,r,r+1,0,Math.PI*2,true);
ctx.closePath();
ctx.strokeStyle="#666666";
ctx.stroke();
drawfalling(jcur,typecur,poscur,color[typecur]);
drawnext(typenext,posnext);
ctx.font=~~(0.06*r)+"px Comic Sans MS";
ctx.fillStyle="#FFFFFF";
ctx.fillText("NEXT",~~(0.06*r),~~(0.06*r));
}
//controls
function controls()
{
if(clickevent)
{
for(var i=0;i<button.length;i++)
{
if(button[i].onclick(clickx,clicky)){break;}
}
clickevent=false;
}
animation();
ctx.fillStyle="rgba(0,0,0,0.3)";
ctx.fillRect(0,0,c.width,c.height);
ctx.fillStyle="rgba(70,70,250,0.6)";
ctx.fillRect(r*0.25,r*0.4,r*1.5,r*1.2);
ctx.fillStyle="#FFFFFF";
ctx.font=~~(0.1*r)+"px Comic Sans MS";
ctx.fillText("Controls",r*0.4,r*0.55);
ctx.font=~~(0.07*r)+"px Comic Sans MS";
ctx.fillText("Left/Right Arrow - move left/right",r*0.4,r*0.8);
ctx.fillText("Up Arrow - rotate",r*0.4,r*0.9);
ctx.fillText("Down Arrow - drop",r*0.4,r*1.0);
for(var i=0;i<button.length;i++){button[i].draw();}
}
//homepage
function homepage()
{
animation();
if(clickevent)
{
for(var i=0;i<button.length;i++)
{
if(button[i].onclick(clickx,clicky)){break;}
}
clickevent=false;
}
ctx.fillStyle="rgba(0,0,0,0.3)";
ctx.fillRect(0,0,c.width,c.height);
ctx.fillStyle="rgba(70,70,250,0.6)";
ctx.fillRect(r*0.293,r*0.293,r*1.414,r*1.414);
ctx.fillStyle="#FFFFFF";
ctx.font=~~(0.1*r)+"px Comic Sans MS";
ctx.fillText("俄罗斯扇块 Tetris Ver4.1",r*0.35,r*0.45);
ctx.font=~~(0.06*r)+"px Comic Sans MS";
ctx.fillText("touchscreen supported",r,r*0.55);
ctx.fillText("宇平工作室 Yuping 4/1/13",r*0.9,r*1.6);
for(var i=0;i<button.length;i++){button[i].draw();}
}
//vacant
function vacant(j,type,pos,app)
{
return (squares[(28+shapes[4*type+pos%4][0][0]-app%16)%16][j+shapes[4*type+pos%4][0][1]]==""&&
squares[(28+shapes[4*type+pos%4][1][0]-app%16)%16][j+shapes[4*type+pos%4][1][1]]==""&&
squares[(28+shapes[4*type+pos%4][2][0]-app%16)%16][j+shapes[4*type+pos%4][2][1]]==""&&
squares[(28+shapes[4*type+pos%4][3][0]-app%16)%16][j+shapes[4*type+pos%4][3][1]]=="");
}
//draw
function draw()
{
if(keys[37]&&!keys[39])
{
if(inverse)
{
if(vacant(jcur,typecur,poscur,Math.round(rot)-1)){app=Math.round(rot)-1;approaching=true;}
}else
{
if(vacant(jcur,typecur,poscur,Math.round(rot)+1)){app=Math.round(rot)+1;approaching=true;}
}
keys[37]=false;
}
if(keys[39]&&!keys[37])
{
if(inverse)
{
if(vacant(jcur,typecur,poscur,Math.round(rot)+1)){app=Math.round(rot)+1;approaching=true;}
}else
{
if(vacant(jcur,typecur,poscur,Math.round(rot)-1)){app=Math.round(rot)-1;approaching=true;}
}
keys[39]=false;
}
if(keys[38])
{
if(vacant(jcur,typecur,poscur+1,app)){poscur++;}
keys[38]=false;
}
if(keys[40])
{
fastsettle(typecur,poscur);
keys[40]=false;
}
if(approaching)
{
rot+=(app-rot)/4;
if(Math.abs(app-rot)<0.01){rot=app;approaching=false;}
}
if(frame%int==0){jcur--;}
settle(jcur,typecur,poscur);
ctx.drawImage(imgbg,0,0,c.width,c.height,0,0,c.width,c.height);
var a=0.0;
ctx.beginPath();
ctx.arc(r,r,r+1,0,Math.PI*2,true);
ctx.arc(r,r,r+2,0,Math.PI*2,true);
if(grid)
{
for(var i=4;i<16;i++)
{
ctx.moveTo(r+r*i/15,r);
ctx.arc(r,r,r*i/15,0,Math.PI*2,true);
}
}
for(var i=0;i<8;i++)
{
a=i+rot;
ctx.moveTo(Math.round(r+r*Math.cos(a*Math.PI/8-Math.PI/16)),Math.round(r-r*Math.sin(a*Math.PI/8-Math.PI/16)));
ctx.lineTo(Math.round(r-r*Math.cos(a*Math.PI/8-Math.PI/16)),Math.round(r+r*Math.sin(a*Math.PI/8-Math.PI/16)));
}
ctx.closePath();
ctx.strokeStyle="#666666";
ctx.stroke();
for(var i=0;i<16;i++){for(var j=1;j<16;j++){if(squares[i][j]!=""){drawsquare(i,j,squares[i][j],rot);}}}
drawfalling(jcur,typecur,poscur,color[typecur]);
drawnext(typenext,posnext);
ctx.font=~~(0.06*r)+"px Comic Sans MS";
ctx.fillStyle="#FFFFFF";
ctx.fillText("NEXT",~~(0.06*r),~~(0.06*r));
ctx.fillText(str,100,50);
ctx.font=~~(0.1*r)+"px Comic Sans MS";
ctx.fillStyle="#FFFFFF";
ctx.fillText("Score:"+score,~~(1.5*r),~~(0.1*r));
}
//generatefalling
function generatefalling()
{
typecur=typenext;
poscur=posnext;
jcur=15;
typenext=~~(Math.random()*7);
posnext=~~(Math.random()*4);
if(mode==GAME){gameover(typecur,poscur);}
}
//gameover
function gameover(type,pos)
{
if(squares[(28+shapes[4*type+pos%4][0][0]-app%16)%16][15+shapes[4*type+pos%4][0][1]]!=""||
squares[(28+shapes[4*type+pos%4][1][0]-app%16)%16][15+shapes[4*type+pos%4][1][1]]!=""||
squares[(28+shapes[4*type+pos%4][2][0]-app%16)%16][15+shapes[4*type+pos%4][2][1]]!=""||
squares[(28+shapes[4*type+pos%4][3][0]-app%16)%16][15+shapes[4*type+pos%4][3][1]]!="")
{
loadgameoverbuttons();
mode=GAMEOVER;
for(var i=0;i<16;i++)
{
squares[i]=new Array(18);
squares[i][0]="#000";
for(var j=1;j<18;j++)
{
squares[i][j]="";
}
}
}
}
//gamaoverpage
function gamaoverpage()
{
if(clickevent)
{
for(var i=0;i<button.length;i++)
{
if(button[i].onclick(clickx,clicky)){break;}
}
clickevent=false;
}
ctx.drawImage(imgbg,0,0,c.width,c.height,0,0,c.width,c.height);
ctx.font=~~(0.2*r)+"px Comic Sans MS";
ctx.fillStyle="#000";
ctx.fillText("GAME OVER",~~(r*0.4),~~(r*0.8));
ctx.font=~~(0.1*r)+"px Comic Sans MS";
ctx.fillText("Score:"+score,r,~~(1.2*r));
for(var i=0;i<button.length;i++){button[i].draw();}
}