テトリス簡易版(more)


SPALM more用、簡易版テトリス

改良の余地が大いにあると思いますので協力してくれると有難いです。m(__)m

[サブソース]

images

[メインソース]

#images#

@(sc,40,100,300,1200)
@(tm,1400,1250,1100,900,750,600,400,250,100,750,450,250,50)
@(record,load(0),load(1),load(2),load(3),load(4))
w=10
h=20

setfont("S")

label menu
soft1("")
soft2("Exit")
origin(0,0)
col(0)
frect(0,0,width,height)
drawimg(logo,120,70,17)
col(0xff)
text("PUSH START!",120,250,33)
text("PUSH START!",121,250,33)
while(1){
key=input()
if(key==(1<<18)){end}
if(key==(1<<16)){break}
}

label play
score=0
lines=0
level=0
col(0)
frect(0,0,width,height)
origin(40,60)
soft1("Pause")

lock()
for(i=0;i<h;i++){
for(j=0;j<w;j++){
drawimg(bk[1],j*9,i*9,0)}}

col(0x333333)
fround(w*9+20,10,80,18,8,8)
fround(w*9+20,50,80,18,8,8)
fround(w*9+20,90,80,18,8,8)
col(0xffffff)
text("SCORE",w*9+25,12,0)
text("LINES",w*9+25,52,0)
text("LEVEL",w*9+25,92,0)
sshow()

for(i=0;i<h;i++){copy(none,0,map[i],0,w)}
for(i=0;i<w;i++){'map[-1][i]='map[h][i]=-1}
for(i=0;i<h;i++){map[i][-1]=map[i][w]=-1}

copy(none,0,tmnx,1,4)
copy(none,0,tmny,1,4)
create()
t=tick

while(1){
show()
unlock()
if(smode&&scan==key){
key=scan
}else{
smode=0
key=input(10)
}
lock()
unshow()
if(key==(1<<18)){end}
elsif(key==(1<<17)){col(0xdddddd) round(0,h*9+20,w*9,20,5,5) col(0xffffff) text("PAUSE",w*9/2,h*9+30,3) show() unlock() while(1){key=input() if(key==(1<<18)){end}elsif(key==(1<<17)){break}}col(0) frect(0,h*9+20,w*9+1,21) unshow()}
elsif(key==(1<<0)){spin(0)}
elsif(key==(1<<16)||key==(1<<5)){spin(1)}
elsif(!invalid(-1,0)&&key==(1<<13)||key==(1<<4)){px-- if(!smode){st=tick while(scan==key&&tick-st<100){} if(tick-st>=100){smode=1}}else{sleep(50)}}
elsif(!invalid(1,0)&&key==(1<<14)||key==(1<<6)){px++ if(!smode){st=tick while(scan==key&&tick-st<100){} if(tick-st>=100){smode=1}}else{sleep(50)}}
elsif(!invalid(0,1)&&key==(1<<15)||key==(1<<8)){py++ if(!smode){smode=1}else{sleep(20) score+=2 sshow()}}
elsif(key==(1<<12)||key==(1<<2)){while(!invalid(0,1)){py++}}
elsif(key==(1<<7)){while(!invalid(-1,0)){px--}}
elsif(key==(1<<9)){while(!invalid(1,0)){px++}}

if(!mwait&&invalid(0,1)){mwait=tick '遊び'}
elsif(mwait&&!invalid(0,1)){mwait=0}

elsif(mwait&&tick-mwait>500){
mwait=0
show()
addmap()
t=tick
l=0
for(i=0;i<h;i++){
for(j=0;j<w&&map[i][j];j++){}
if(j==w){for(j=i;j>=1;j--){copy(map[j-1],0,map[j],0,w)}
l++
}}
if(l){
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(map[i][j]){drawimg(box[map[i][j]],j*9,i*9,0)}else{drawimg(bk[1],j*9,i*9,0)}
}}
if(lines/5!=(lines+l)/5){level++}
if(level<10){score+=sc[l-1]*(level+1)}
else{score+=sc[l-1]*10}
lines+=l
unlock()
input(500)
}
create()
sshow()
for(i=0;invalid(0,-i)&&i<5;i++){}
py-=i
if(invalid(0,0)){goto "over"}
}

elsif(!invalid(0,1)&&tick-t>tm[level%13]){py++ t=tick}
}

label over
soft1("")
soft2("Back")
col(0x0)
frect(0,0,width,height)
col(0xdd0000)
text("GAME OVER",width/2-40,20,1)

for(i=0;i<5;i++){
if(score>record[i]){
for(j=4;j>i;j--){
record[j]=record[j-1]
}
record[i]=score
col(0xffff00)
line(0,i*20+70,width-70,i*20+70)
break;
}}

col(0xffffff)
text("1st",10,70,36)
text("2nd",10,90,36)
text("3rd",10,110,36)
text("4th",10,130,36)
text("5th",10,150,36)
for(i=0;i<5;i++){
text(record[i],width-80,i*20+70,40)
save(record[i],i)
}
unlock()
input()
goto "menu"

func create(){
glb px=(w-4)/2
glb py=-1
glb type=abs(rand%7)+1

tmnx[1]=2 tmny[1]=2
tmnx[2]=2 tmny[2]=3
switch(type){
case 1:
tmny[3]=1 tmnx[3]=2
tmny[4]=4 tmnx[4]=2
break
case 2:
py--
tmny[3]=2 tmnx[3]=3
tmny[4]=3 tmnx[4]=3
break
case 3:
tmny[3]=1 tmnx[3]=1
tmny[4]=2 tmnx[4]=1
break
case 4:
tmny[3]=1 tmnx[3]=3
tmny[4]=2 tmnx[4]=3
break
case 5:
tmny[3]=1 tmnx[3]=2
tmny[4]=3 tmnx[4]=1
break
case 6:
tmny[3]=1 tmnx[3]=2
tmny[4]=3 tmnx[4]=3
break
case 7:
py--
tmny[3]=2 tmnx[3]=1
tmny[4]=2 tmnx[4]=3
break
}}

func show(){
clip(0,0,w*9,h*9)
for(l=1;l<=4;l++){
drawimg(box[type],(tmnx[l]+px)*9,(tmny[l]+py)*9,0)
}
clip(-30,-30,width,height)
}

func unshow(){
clip(0,0,w*9,h*9)
for(l=1;l<=4;l++){
drawimg(bk[1],(tmnx[l]+px)*9,(tmny[l]+py)*9,0)
}
clip(-30,-30,width,height)
}

func sshow(){
col(0)
frect(w*9+25,32,80,17)
frect(w*9+25,72,80,17)
frect(w*9+25,112,80,17)
col(0xffffff)
text(score,w*9+100,32,24)
text(lines,w*9+100,72,24)
text(level,w*9+100,112,24)
}

func addmap(){
for(l=1;l<=4;l++){
map[tmny[l]+py][tmnx[l]+px]=type
}}

func invalid(tx,ty){
for(l=1;l<=4;l++){
if(map[tmny[l]+py+ty][tmnx[l]+px+tx]){return l}}
return 0
}

func spin(rl){
mwait=0
if(type==2){return}
copy(tmnx,1,tmpx,1,4)
copy(tmny,1,tmpy,1,4)
if(rl){
for(l=1;l<=4;l++){
tmnx[l]=4-tmny[l]
tmny[l]=tmpx[l]
}}else{
for(l=1;l<=4;l++){
tmnx[l]=tmny[l]
tmny[l]=4-tmpx[l]
}}

if(tmp=invalid(0,0)){
if(tmnx[tmp]<2&&!invalid(1,0)){px++}
elsif(tmnx[tmp]>2&&!invalid(-1,0)){px--}
elsif(tmny[tmp]<2&&!invalid(0,1)){py++}
elsif(tmny[tmp]>2&&!invalid(0,-1)){py--}
}
if(invalid(0,0)){
copy(tmpx,1,tmnx,1,4)
copy(tmpy,1,tmny,1,4)
}}