// pac
var stsc,stmes;
sprite(1,"Pac",4);
function init(){
cls();
// set player
sett(scx/2,scy/2,1,1);
// set feeds
f=30;
for(i=0;i<f;i++){
sett(rand(scx-60)+30,rand(scy-60)+30,1,2,2);}
// set enemies
for(i=0;i<3+lv;i++){
sett(rand(scx),20,1,3,3);}
// text
stsc=print(16,16,"");status();
stmes=print(16,scy/2,"");
s=0;mo=0;}
function gameinit(){
lv=0;sc=0;}
//----
function move(i){
switch(t[i]){
// player
case 1:if(mo!=0)break;
sp=8;
switch(s){
case 1:sy-=sp;sr=90;break;
case 2:sx+=sp;sr=180;break;
case 3:sy+=sp;sr=270;break;
case 4:sx-=sp;sr=0;break;}
if(tx[i]!=sx||ty[i]!=sy)sn=(sn+1)&1
w=32*ss/2;
if(sx<w)sx=w;else if(sx>scx-w)sx=scx-w;
if(sy<w)sy=w;else if(sy>scy-w)sy=scy-w;
if(chkt(3,i,24)){end();}
break;
// feed
case 2:
if(chkt(1,i,15)){t[i]=0;++sc;status();
if(--f==0)clear();
}
break;
// enemy
case 3:if(mo!=0)break;
if(rand(10)==0){
sxx=rnd()*28-14;
syy=rnd()*28-14;}
sx+=sxx;
sy+=syy;
w=32*ss/2;
if(sx<w)sx=w;else if(sx>scx-w)sx=scx-w;
if(sy<w)sy=w;else if(sy>scy-w)sy=scy-w;
break;
}
}
function update(){
if(mo==0&&sndstatus(1)==0)sndloop(1);
}
function mousedown(x,y){
switch(mo){
case 0:
if(x<scx/2){if(--s<=0)s=4;}
else{if(++s==5)s=1;}break;
case 1:++lv;init();break;
case 2:gameinit();init();break;
}
}
function mouseup(x,y){
}
//---- game functions
function status(){
settext(stsc,sprintf("Score %4d",sc));
}
function end(){
settext(stmes,"GAME OVER");
tx[stmes]=(32-9)*8;
mo=2;
sndstop(1);
}
function clear(){
settext(stmes,"CLEAR!");
tx[stmes]=(32-6)*8;
mo=1;
sndstop(1);
}
gameinit();
|
2018 N.I