//******************************************* //* * //* http://tofuculub.com/ * //* * //******************************************* document.scroll = function(){ return { left: this.body.scrollLeft || this.documentElement.scrollLeft, top: this.body.scrollTop || this.documentElement.scrollTop } } //---- COPY function copy(copy_Str,alert_Str){ clipboardData.setData('Text',copy_Str); if(alert_Str.length>0)alert(alert_Str); } //---- BLOG TAG function blogTag(tag_Str){ var str; str=""; str+=tag_Str; return str; } function getLeft(obj){ return (!obj.style.pixelLeft)?obj.style.left.toString().replace(/px/,"")*1:obj.style.pixelLeft; } function getTop(obj){ return (!obj.style.pixelTop)?obj.style.top.toString().replace(/px/,"")*1:obj.style.pixelTop; } function getPageX(e){ if(!e)var e=event; return e.pageX | document.body.scrollLeft+e.x; } function getPageY(e){ if(!e)var e=event; return e.pageY | document.body.scrollTop+e.y; } //********** IMG ********** //---- IMG TAG COPY function imgTagCopy(){ var i; for(i in document.getElementsByTagName("img")){ document.getElementsByTagName("img")[i].onclick= function(){ var str=""; str=str.replace(/src="gif/ig,'src="'+document.domain+'/gif'); copy(str,"copy("+str+")"); } } } //---- IMG MOVE TO function imgMoveTo(img_Obj,x_Int,y_Int){ img_Obj.style.position="absolute"; img_Obj.style.top=y_Int; img_Obj.style.left=x_Int; } //---- IMG MOVE BY function imgMoveBy(img_Obj,x_Int,y_Int){ img_Obj.style.position="absolute"; img_Obj.style.top=getTop(img_Obj)+y_Int; img_Obj.style.left=getLeft(img_Obj)+x_Int; } //---- img MOUSE STALKER function imgMouseStalker(){ var i; // try{ imgMoveBy(arguments[1],(getPageX(arguments[0])-getLeft(arguments[1]))/30,(getPageY(arguments[0])-getTop(arguments[1]))/20); i=2; while(arguments[i]){ imgMoveBy(arguments[i],(getLeft(arguments[i-1])-getLeft(arguments[i]))/20,(getTop(arguments[i-1])-getTop(arguments[i]))/20); i++; } // }catch(e){} } //---- MOUSE STALKER function mouseStalker(obj,m){ if(!m)var m=1; var x; var y; if(document.scroll().left+event.x-arguments[0].style.pixelLeft==0){ x=0; }else if(document.scroll().left+event.x-arguments[0].style.pixelLeft>0){ x=m; }else{ x=-m; } if(document.scroll().top+event.y-arguments[0].style.pixelTop==0){ y=0; }else if(document.scroll().top+event.y-arguments[0].style.pixelTop>0){ y=m; }else{ y=-m; } imgMoveBy(obj,x,y); } //==== imgKurukuru OBEJCT imgKurukuru_Obj=[]; function imgKurukuru(Id_str){ if(typeof(Id_str)=="object"){ this.obj=Id_str; Id_str=imgKurukuru_Obj.length+102102; } imgKurukuru_Obj[Id_str]=this; this.id=Id_str; this.style=new Object(); this.style.left=300; this.style.top=300; this.position=""; this.speed=3; this.zoom=3; this.actType=0; this.count=0; } //==== imgZoomzoom OBJECT imgZoomzoom_Obj=[]; function imgZoomzoom(Id_str){ if(Id_str.toString().indexOf("object",0)>-1){ this.obj=Id_str; Id_str=imgZoomzoom_Obj.length+102102; } imgZoomzoom_Obj[Id_str]=this; this.id=Id_str; this.style=new Object(); this.style.zoom=1; this.style.left=300; this.style.top=300; this.position=""; this.max=2; this.min=.5; this.count=1; this.speed=1; this.direction=1; } //********** INTERVAL ********** //---- KURUKURU INTERVAL function kurukuruStart(interval){ if(!interval)interval=100; kurukuru_Intrerval=setInterval("kurukuru_tick()",interval); } function kurukuru_tick(){ var i,x,y,img_Obj; for(i in imgKurukuru_Obj){ obj=imgKurukuru_Obj[i]; obj.count+=obj.speed/10; x=obj.style.top+Math.sin(obj.count)*10*obj.zoom; y=obj.style.pixelTop+Math.cos(obj.count)*10*obj.zoom; if(!obj.obj){ img_Obj=document.getElementById(obj.id); }else{ img_Obj=obj.obj; } imgMoveTo(img_Obj,x,y); } } //---- ZOOMZOOM INTERVAL function zoomzoomStart(interval){ if(!interval)interval=100; zoomzoom_Intrerval=setInterval("zoomzoom_tick()",interval); } function zoomzoom_tick(){ var i,img_Obj; for(i in imgZoomzoom_Obj){ obj=imgZoomzoom_Obj[i]; if(obj.count>obj.max)obj.direction=-1; if(obj.countobj.max)obj.direction=-1; if(obj.count-1){ count++; if(numberInt==count){ return tag[i]; } i++; continue; } } if(tag[i].innerHTML){ if(tag[i].innerHTML.replace(/<.+>/,"").indexOf(txtStr)>-1){ count++; if(numberInt==count){ return tag[i]; } i++; continue; } } if(tag[i].src){ if(tag[i].src.indexOf(txtStr)>-1){ count++; if(numberInt==count){ return tag[i]; } i++; continue; } } if(tag[i].href){ if(tag[i].href.indexOf(txtStr)>-1){ count++; if(numberInt==count){ return tag[i]; } i++; continue; } } i++; } return ""; } //---- P SET pset=pSet; function pSet(xInt,yInt,colorStr,pointStr,screenObj,posStr){ if(!posStr)posStr="absolute"; if(!colorStr)colorStr="black"; if(!pointStr)pointStr="."; var obj; if(!screenObj)screenObj=document.body; obj=document.createElement("div"); obj.style.position=posStr; obj.style.left=xInt; obj.style.top=yInt; obj.innerHTML=pointStr obj.style.color=colorStr; screenObj.appendChild(obj); return obj; } //---- line function line(x1,y1,x2,y2,colorStr,pointStr,box,step,screenObj){ var i; if(!step)step=1; if(!colorStr)colorStr="black"; if(!pointStr)pointStr="."; if(x1>x2){ var xx=x2; x2=x1; x1=xx; var yy=y2; y2=y1; y1=yy; } var x; var y; var ax=x2-x1; var ay=y2-y1; var a=ay/ax; if(ax>ay){ for(i=0;iendDegree){ if(startDegree>360)return; endDegree+=360; } startRad=startDegree*pi/180-pi; endRad=endDegree*pi/180-pi; for(i=startRad;i
"); } //--- HIT TEST function hitTest(x,y,obj){ if(!obj)return; var top=obj.getBoundingClientRect()['top']; var bottom=obj.getBoundingClientRect()['bottom']; var left=obj.getBoundingClientRect()['left']; var right=obj.getBoundingClientRect()['right']; if(x>=left && x<=right && y>=top && y<=bottom){ return true; } return false; } //---- objHitTest function objHitTest(obj1,obj2){ try{ var top1=obj1.getBoundingClientRect()['top']; var bottom1=obj1.getBoundingClientRect()['bottom']; var left1=obj1.getBoundingClientRect()['left']; var right1=obj1.getBoundingClientRect()['right']; var top2=obj2.getBoundingClientRect()['top']; var bottom2=obj2.getBoundingClientRect()['bottom']; var left2=obj2.getBoundingClientRect()['left']; var right2=obj2.getBoundingClientRect()['right']; if(top1<=bottom2 && bottom1>=top2 && left1<=right2 && right1>=left2){ return true; } }catch(e){} return false; } function getBounds(obj,str){ if(str=="left" || str=="right"){ return obj.getBoundingClientRect()[str]+document.scroll().left; } if(str=="top" || str=="bottom"){ return obj.getBoundingClientRect()[str]+document.scroll().top; } } //==== map function map(){ this.tip=new Object() this.data=""; this.tip.data=[]; this.tip.width=45; this.tip.height=45; this.top=0; this.left=0; this.tips=[]; for(i=0;i<10;i++){ this.tips[i]=[]; } this.write=function(){ var i; var x=this.left; var y=this.top; for(i=0;i0){ this.block.nowItem.rotation--; }else{ this.block.nowItem.rotation=itemrotation; } this.draw(); } } this.draw=function(){ var i,j,k,l; for(i=0;i=50)return false; var item=this.block.nowItem.item; var itemrotation=this.block.item[item].length-1; if(!rotation)rotation=this.block.nowItem.rotation; if(rotation>itemrotation)rotation=0; if(rotation<0)rotation=itemrotation; var x=this.block.location.x+X; var y=this.block.location.y+Y; for(i=0;i<4;i++){ for(j=0;j<4;j++){ if(this.block.item[item][rotation][i][j]!=""){ if((i+x)>(this.field.width-1) || (i+x)<0 || (j+y)>(this.field.height-1) || this.field.data[i+x][j+y])return false; } } } return true; } this.moveR=function(){ if(this.move(1,0)){ this.block.location.x++; this.draw(); } } this.moveL=function(){ if(this.move(-1,0)){ this.block.location.x--; this.draw(); } } if(!writeData){ this.writeData=function(){ var i,j,k,l; try{this.sound.writedata.play();}catch(e){} var x=this.block.location.x; var y=this.block.location.y; var item=this.block.nowItem.item; var rotation=this.block.nowItem.rotation; for(i=0;i<4;i++){ for(j=0;j<4;j++){ var data=this.block.item[item][rotation][i][j] if(data!=""){ this.field.data[i+x][j+y]=data; } } } var score=0; var flag; var i=this.field.height-1; while(i>-1){ flag=0; for(j=0;jthis.level){ img=this.level; }else{ img=this.background.length-1; } this.bgImage.src=this.background[img]; } this.panel.lines.innerHTML="LINES:
"+this.lines; }else{ i--; } } if(score==1)this.score+=score*40; if(score==2)this.score+=score*50; if(score==3)this.score+=score*100; if(score>3){ this.score+=score*300; try{this.sound.tetris.play();}catch(e){} } this.panel.score.innerHTML="SCORE:
"+this.score; this.newBlock(); } }else{ this.writeData=new writeData(this); } if(!afterWriteData){ this.afterWriteData=null; }else{ this.afterWriteData=new afterWriteData(this); } this.panel.level.innerHTML="LEVEL:
"+this.level; this.panel.lines.innerHTML="LINES:
"+this.lines; this.panel.score.innerHTML="SCORE:
"+this.score; if(!delLine){ this.delLine=function(x){ for(i=x;i>0;i--){ for(j=0;j<10;j++){ this.field.data[j][i]=this.field.data[j][i-1]; } } for(j=0;j<10;j++){ this.field.data[j][0]=""; } } }else{ this.delLine=new delLine(this); } this.newBlock=function(){ var i,j,k,l; var item=this.block.item.length-1; this.block.location.x=this.block.location.startx; this.block.location.y=this.block.location.starty; this.block.nowItem.item=this.block.nextItem.item; var rnd=random(this.block.item.length); if(rnd<0)rnd=0; if(rnd>item)rnd=item; this.block.nextItem.item=rnd; this.block.nowItem.rotation=0; if(!this.move(0,0))this.gameover(); this.panel.draw(); } this.block.nextItem.item=random(this.block.item.length-1); this.newBlock(); this.gameover=function(){ var i,j,k,l; this.game=false; document.body.onkeydown=null; try{this.sound.bgm.stop();}catch(e){} try{this.sound.fielddown.play();}catch(e){}//opera:Error this.panel.level.innerHTML="GAMEOVER------------LEVEL: "+this.level+" ------------"; clearInterval(this.interval); this.interval=setInterval(_tetris_obj.gameover_tick,60); if(this.score>100){ if(!this.userid){ this.panel.rank.style.backgroundColor="white"; var parent=this.panel.rank; var label=eSet("span",0,0,0,0,null,null,parent); label.innerHTML="name"; this.username=eSet("input",0,this.size,this.size*4,this.size,null,null,parent); var c=new cookie(); this.username.value=c.load("tetris_name"); this.rankbutton=eSet("button",0,this.size*2,this.size*4,this.size,null,null,parent); this.rankbutton.innerHTML="Send_Ranking"; this.rankbutton.onclick=this.post_rank; }else{ this.post_rank('',this.userid); } } } this.fx=0; this.fy=0; this.gameover_tick=function(){ var i,j,k,l; //var x=_tetris_obj.fx; var i; var y=_tetris_obj.fy; for(i=0;i<_tetris_obj.field.width;i++){ if(_tetris_obj.field.data[i][y]!=""){ try{_tetris_obj.field.obj[i][y].style.backgroundColor="gray";}catch(e){} } } _tetris_obj.fy++; if(_tetris_obj.fy>(_tetris_obj.field.height-1)){ try{_tetris_obj.sound.gameover.play();}catch(e){} clearInterval(_tetris_obj.interval); } } this.post_rank=function(e,name){ if(!name){ var name=_tetris_obj.username.value; if(!/[a-zA-Z0-9]+/.test(name)){ alert("Please do not use Japanese."); return; } } eSet("img",0,0,0,0,"http://tofuclub.com/tetris/post_"+_tetris_obj.rankingfile+"?score="+_tetris_obj.score+"&level="+_tetris_obj.level+"&lines="+_tetris_obj.lines+"&username="+name); var c=new cookie(); c.save("tetris_name",name,365); try{_tetris_obj.panel.rank.style.display="none";}catch(e){} } this.main_tick=function(){ _tetris_obj.focus.focus(); if(_tetris_obj.move(0,1)){ _tetris_obj.block.location.y++; _tetris_obj.draw(); }else{ //alert("write"); _tetris_obj.writeData(); } } setTimeout("_tetris_obj.interval=setInterval(_tetris_obj.main_tick,_tetris_obj.speed)",1000); try{init(this);}catch(e){} } //==== tetris_sound function tetris_sound(){ var i,j,k,l; //pSet(xInt,yInt,colorStr,pointStr,screenObj,posStr) //eSet(tagNameStr,x,y,width,height,src,tip,parentObj) try{ this.screen=eSet("div",0,0,0,0); this.screen.style.display="none"; this.bgmObj=pSet(0,0,'','',this.screen); this.bgm=this.bgmObj.firstChild; this.writedataObj=pSet(0,0,'','',this.screen); this.writedata=this.writedataObj.firstChild; this.levelupObj=pSet(0,0,'','',this.screen); this.levelup=this.levelupObj.firstChild; this.gameoverObj=pSet(0,0,'','',this.screen); this.gameover=this.gameoverObj.firstChild; this.tetrisObj=pSet(0,0,'','',this.screen); this.tetris=this.tetrisObj.firstChild; this.fielddownObj=pSet(0,0,'','',this.screen); this.fielddown=this.fielddownObj.firstChild; }catch(e){} } //==== tetris_panel function tetris_panel(parentObj,size){ var i,j,k,l; this.obj=eSet("div",size+size*parentObj.field.width,size,-size*2+size*(parentObj.width-parentObj.field.width),-size*2+size*parentObj.height,null,null,parentObj.obj); this.nextPanel=[]; for(i=0;i<4;i++){ this.nextPanel[i]=[]; for(j=0;j<4;j++){ this.nextPanel[i][j]=eSet("div",size+i*size,j*size,size,size,null,null,this.obj); this.nextPanel[i][j].style.border="1px solid "; this.nextPanel[i][j].style.backgroundColor="white"; } } this.draw=function(){ for(i=0;i<4;i++){ for(j=0;j<4;j++){ var item=parentObj.block.nextItem.item; var color=parentObj.block.item[item][0][i][j]; if(!color)color="white"; this.nextPanel[i][j].style.backgroundColor=color; } } } this.level=eSet("div",size,size*7,size*4,size*2,null,null,this.obj); this.lines=eSet("div",size,size*9,size*4,size*2,null,null,this.obj); this.score=eSet("div",size,size*11,size*4,size*2,null,null,this.obj); this.rank=eSet("div",size,size*15,size*4,size*4,null,null,this.obj); this.ranking=eSet("div",size,size*21,size*4,size*2,null,null,this.obj); this.level.style.backgroundColor="white"; this.level.style.textAlign="right"; this.lines.style.backgroundColor="white"; this.lines.style.textAlign="right"; this.score.style.backgroundColor="white"; this.score.style.textAlign="right"; this.ranking.innerHTML="
Ranking
"; } //==== tetris_field function tetris_field(x,y,size,parentObj){ var i,j,k,l; this.data=[]; this.obj=[]; this.width=parentObj.fieldWidth; this.height=parentObj.fieldHeight; for(i=0;i-4){ for(i=0;i<4;i++){ for(j=0;j<4;j++){ var data=obj.block.item[item][rotation][i][j] if(data!=""){ obj.field.data[i+x][j+y]=data; } } } obj.block.location.y=50; obj.delLine.delflag=true; obj.panel.score.innerHTML="SCORE:
"+obj.score; } obj.interval=setInterval("_tetris_obj.afterWriteData()",300); //obj.delLine.main(); } return this.main; } //==== delLine function puyopuyo_delLine(obj){ this.delcount=4; this.data=[]; this.puyo=[]; this.delpuyo=[]; this.delpuyobuf=[]; this.count=0; this.delflag=false; this.scoreCount=0; this.main=function(){ var i,j,k,l; this.data=[]; this.puyo=[]; this.delpuyo=[]; this.delpuyobuf=[]; this.count=0; this.delflag=false; for(i=0;i0){ buf=this.puyo[this.count]; x=buf["x"]; y=buf["y"]; this.delpuyobuf[count]=[]; this.delpuyobuf[count]["x"]=x this.delpuyobuf[count]["y"]=y this.count--; }else{ loop=false; } } if(count>this.delcount){ this.scoreCount++; if(this.scoreCount<2){ try{obj.sound.puyo1.play();}catch(e){} }else if(this.scoreCount<3){ try{obj.sound.puyo2.play();}catch(e){} }else{ try{obj.sound.puyo3.play();}catch(e){} } obj.lines+=count-1; var level=floor(obj.lines/30); if(obj.levelobj.level){ img=obj.level; }else{ img=obj.background.length-1; } obj.bgImage.src=obj.background[img]; } obj.score+=count*pow((obj.level+1),this.scoreCount)*10; obj.panel.level.innerHTML="LEVEL:
"+obj.level; obj.panel.lines.innerHTML="PUYO:
"+obj.lines; obj.panel.score.innerHTML="SCORE:
"+obj.score; this.delflag=true; var len; for(k=1;k<(count);k++){ buf=this.delpuyobuf[k]; len=this.delpuyo.length; this.delpuyo[len]=[]; this.delpuyo[len]["x"]=buf["x"]; this.delpuyo[len]["y"]=buf["y"]; len=this.delpuyo.length; } this.delpuyo[len]=[]; this.delpuyo[len]["x"]=i; this.delpuyo[len]["y"]=j; } this.count=0; this.puyo=[]; this.delpuyobuf=[]; } } } for(i in this.delpuyo){ var x=this.delpuyo[i]["x"]; var y=this.delpuyo[i]["y"]; obj.field.data[x][y]=""; } if(!this.delflag){ //if(!obj.interval){ if(obj.block.location.y>50)obj.block.location.y=-4;obj.newBlock(); obj.interval=setInterval(_tetris_obj.main_tick,_tetris_obj.speed); document.body.onkeydown=obj.keydown; this.scoreCount=0; // } }else{ //setTimeout("_tetris_obj.writeData();",400); obj.writeData(); obj.draw(); } } this.find=function(x,y,color){ if(this._find(x,y,0,1,color)){ this.puyo[this.count]=[]; this.puyo[this.count]["x"]=x; this.puyo[this.count]["y"]=y+1; } if(this._find(x,y,0,-1,color)){ this.puyo[this.count]=[]; this.puyo[this.count]["x"]=x; this.puyo[this.count]["y"]=y-1; } if(this._find(x,y,1,0,color)){ this.puyo[this.count]=[]; this.puyo[this.count]["x"]=x+1; this.puyo[this.count]["y"]=y; } if(this._find(x,y,-1,0,color)){ this.puyo[this.count]=[]; this.puyo[this.count]["x"]=x-1; this.puyo[this.count]["y"]=y; } } this._find=function(x,y,findX,findY,color){ x+=findX; y+=findY; if(x>(obj.field.width-1) || y>(obj.field.height-1) || x<0 || y<0)return false; try{var flag=this.data[x][y];} catch(e){flag="";} if(flag==color){ this.count++; this.data[x][y]=""; return true; } return false; } } //==== puyopuyo_afterWriteData function puyopuyo_afterWriteData(obj){ this.main=function(){ var i,j,k; var flag; flag=[0,0,0,0,0,0,0,0,0,0]; var nextflag=true; if(obj.delLine.delflag){ for(i=0;i0){ flag[j]=-1; nextflag=false; for(k=i;k>0;k--){ var data=obj.field.data[j][k-1]; obj.field.data[j][k]=data; } obj.field.data[j][0]=""; } }else if(flag[j]==0){ flag[j]++; } } } } obj.draw(); if(nextflag){ clearInterval(obj.interval); obj.delLine.main(); } } return this.main; } //==== puyopuyo_sound function puyopuyo_sound(){ var i,j,k,l; try{ //pSet(xInt,yInt,colorStr,pointStr,screenObj,posStr) //eSet(tagNameStr,x,y,width,height,src,tip,parentObj) this.screen=eSet("div",0,0,0,0); this.screen.style.display="none"; //this.bgmObj=pSet(0,0,'','',this.screen); //this.bgm=this.bgmObj.firstChild; this.writedataObj=pSet(0,0,'','',this.screen); this.writedata=this.writedataObj.firstChild; this.levelupObj=pSet(0,0,'','',this.screen); this.levelup=this.levelupObj.firstChild; this.gameoverObj=pSet(0,0,'','',this.screen); this.gameover=this.gameoverObj.firstChild; //this.tetrisObj=pSet(0,0,'','',this.screen); //this.tetris=this.tetrisObj.firstChild; this.fielddownObj=pSet(0,0,'','',this.screen); this.fielddown=this.fielddownObj.firstChild; this.puyo1Obj=pSet(0,0,'','',this.screen); this.puyo1=this.puyo1Obj.firstChild; this.puyo2Obj=pSet(0,0,'','',this.screen); this.puyo2=this.puyo2Obj.firstChild; this.puyo3Obj=pSet(0,0,'','',this.screen); this.puyo3=this.puyo3Obj.firstChild; }catch(e){} } function puyopuyo_init(obj){ var i,j,k,l; //field for(i=0;i