📄 iceblox.java
字号:
else
{
creature[actors]=3;
look[actors]=24;
}
x[actors]=x[i]+coorDx[dir];
y[actors]=y[i]+coorDy[dir];
dx[actors]=15;
dy[actors]=15;
playGraphics.fillRect(x[actors]-30,y[actors]-30,30,30);
motion[actors]=dir;
actors++;
playArea[j+sideIX[dir]]=0;
}
else if ((inFront>1)&&(inFront<18)) // Crack ice
{
playArea[j+sideIX[dir]]++;
if (inFront==9) // All cracked?
{
playGraphics.fillRect(x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,30,30);
playArea[j+sideIX[dir]]=0;
updateScore(5);
}
else if (inFront==17)
{
playGraphics.fillRect(x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,30,30);
playArea[j+sideIX[dir]]=0;
updateScore(100);
coins++;
}
else
playGraphics.drawImage(small[inFront+15],x[i]+coorDx[dir]-30,y[i]+coorDy[dir]-30,this);
}
}
}
if (motion[i]!=0)
look[i]=animP[(motion[i]-1)*4+counter%4];
for (k=1;k<actors;k++)
if (creature[k]==4)
if (((x[k]-x[i])<20)&&((x[i]-x[k])<20)&&((y[k]-y[i])<20)&&((y[i]-y[k])<20))
{
creature[k]=6;
x[k]=0;
y[k]=0;
motion[k]=0;
ccount[i]=0;
dx[i]=0;
dy[i]=0;
creature[i]=7;
}
break;
case 2: // Moving ice block
if ((x[i]%30 == 0)&&(y[i]%30 == 0)&&(playArea[j+sideIX[motion[i]]]!=0))
{
playArea[j]=2;
playGraphics.drawImage(small[16],x[i]-30,y[i]-30,this);
removeActor(i);
}
break;
case 3: // Moving frozen coin
if ((x[i]%30 == 0)&&(y[i]%30 == 0)&&(playArea[j+sideIX[motion[i]]]!=0))
{
playArea[j]=10;
playGraphics.drawImage(small[24],x[i]-30,y[i]-30,this);
removeActor(i);
}
break;
case 4: // Flame
look[i]=animF[counter%8];
if (motion[i]==0)
motion[i]=(int)(1+m.random()*4);
if ((x[i]%30 == 0)&&(y[i]%30 == 0)) // Track penguin
{
if (((x[i]-x[0])<3)&&((x[0]-x[i])<3))
{
if (y[i]>y[0])
motion[i]=3;
else
motion[i]=4;
}
else if (((y[i]-y[0])<3)&&((y[0]-y[i])<3))
{
if (x[i]>x[0])
motion[i]=1;
else
motion[i]=2;
}
if (playArea[j+sideIX[motion[i]]]!=0)
motion[i]=0;
}
for (k=1;k<actors;k++) // Colliding with moving block?
if ((creature[k]&254)==2)
if (((x[k]-x[i])<30)&&((x[i]-x[k])<30)&&((y[k]-y[i])<30)&&((y[i]-y[k])<30))
{
creature[i]=5;
k=actors;
look[i]=37;
motion[i]=0;
ccount[i]=0;
updateScore(50);
}
break;
case 5: // Flashing "50"
look[i]=37+(counter&1);
if (ccount[i]>20)
{
flames--;
removeActor(i);
}
break;
case 6: // Dummy
break;
case 7: // Skeleton
if (ccount[i]<8)
look[i]=39+ccount[i];
else if (ccount[i]<30)
look[i]=47;
else
{
lives--;
if (lives<0)
gameState=5;
else
{
actors=1;
flames=0;
counter=0;
dx[i]=6;
dy[i]=6;
creature[0]=1;
look[0]=2;
offGraphics.setColor(Color.black);
offGraphics.fillRect(300,0,45,14);
for (k=0;k<lives;k++)
offGraphics.drawImage(small[13],300+k*15,-16,this);
}
}
break;
default:
break;
}
}
if (coins>4)
{
gameState=3;
updateScore(1000);
counter=0;
coins=0;
offGraphics.drawImage(playField,0,mainY-playY,this);
}
}
public void happyPenguin()
{
if (counter>35)
{
level++;
gameState=4;
counter=0;
}
}
public void clearField()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(playX/2-(playX*counter/30),mainY-playY/2-(playY*counter/30),
playX*counter/15,playY*counter/15);
if (counter>14)
gameState=0;
}
public void fixDeath()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(0,0,mainX,mainY);
offGraphics.setColor(Color.white);
offGraphics.drawString("GAME OVER",175,100);
offGraphics.drawString("You scored "+score,160,130);
offGraphics.drawImage(small[2],190,150,this);
counter=0;
gameState=6;
}
public void gameOver()
{
if (counter>80)
gameState=7;
}
public void drawIntro1()
{
level=0;
score=0;
lives=3;
offGraphics.setColor(Color.black);
offGraphics.fillRect(0,0,mainX,mainY);
offGraphics.setColor(Color.white);
offGraphics.drawImage(title,(mainX-224)/2,10,this);
offGraphics.drawString("ACTORS AND OBJECTS",145,97);
offGraphics.drawImage(small[2],140,110,this);
offGraphics.drawString("Pixel Pete, the penguin",180,130);
offGraphics.drawImage(small[34],120,150,this);
offGraphics.drawImage(small[32],140,150,this);
offGraphics.drawString("Evil flames",180,170);
offGraphics.drawImage(small[16],140,190,this);
offGraphics.drawString("Ice cube",180,210);
offGraphics.drawImage(small[14],140,230,this);
offGraphics.drawString("Solid rock",180,250);
offGraphics.drawImage(small[24],140,270,this);
offGraphics.drawString("Frozen gold coin",180,290);
offGraphics.drawString("Press SPACE to start",138,330);
counter=0;
gameState=8;
}
public void waitIntro1()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(120,150,50,30);
offGraphics.drawImage(small[animF[(counter+2)&7]],120,150,this);
offGraphics.drawImage(small[animF[counter&7]],140,150,this);
if (counter>70)
gameState=9;
}
public void drawIntro2()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(0,75,mainX,230);
offGraphics.setColor(Color.white);
offGraphics.drawString("HOW TO PLAY",165,97);
offGraphics.drawImage(small[2],140,110,this);
offGraphics.drawString("Move up, down, left and right",180,122);
offGraphics.drawString("with the K, M, A and D keys",180,137);
offGraphics.drawImage(small[10],70,150,this);
offGraphics.drawImage(small[16],140,150,this);
offGraphics.drawString("Walk against ice cubes",180,162);
offGraphics.drawString("to move them out of the way",180,177);
offGraphics.drawLine(110,160,136,160);
offGraphics.drawLine(116,169,136,169);
offGraphics.drawImage(small[10],80,190,this);
offGraphics.drawImage(small[18],110,190,this);
offGraphics.drawImage(small[16],140,190,this);
offGraphics.drawString("Walk against blocked",180,202);
offGraphics.drawString("ice cubes to crack them",180,217);
offGraphics.drawImage(small[28],110,230,this);
offGraphics.drawImage(small[9],140,230,this);
offGraphics.drawString("Free the gold coins by",180,242);
offGraphics.drawString("crushing the ice around them",180,257);
offGraphics.drawImage(small[9],80,270,this);
offGraphics.drawImage(small[32],140,270,this);
offGraphics.drawLine(110,280,126,280);
offGraphics.drawLine(110,289,130,289);
offGraphics.drawString("And watch out",180,282);
offGraphics.drawString("for the flames",180,297);
gameState=10;
counter=0;
}
public void waitIntro2()
{
offGraphics.setColor(Color.black);
offGraphics.drawImage(small[1+(counter % 12)],140,110,this);
offGraphics.fillRect(140,270,30,30);
offGraphics.drawImage(small[animF[counter&7]],140,270,this);
if (counter>80)
gameState=11;
}
public void drawIntro3()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(0,75,mainX,230);
offGraphics.setColor(Color.white);
offGraphics.drawString("SCORING",180,97);
offGraphics.drawImage(small[10],110,110,this);
offGraphics.drawImage(small[18],140,110,this);
offGraphics.drawString("Breaking ice,",180,122);
offGraphics.drawString("5 points",180,137);
offGraphics.drawImage(small[33],60,150,this);
offGraphics.drawImage(small[16],80,150,this);
offGraphics.drawImage(small[9],140,150,this);
offGraphics.drawLine(112,160,126,160);
offGraphics.drawLine(112,169,130,169);
offGraphics.drawString("Putting out flame",180,162);
offGraphics.drawString("with ice, 50 points",180,177);
offGraphics.drawImage(small[10],110,190,this);
offGraphics.drawImage(small[27],140,190,this);
offGraphics.drawString("Freeing coin,",180,202);
offGraphics.drawString("100 points",180,217);
for (j=0;j<5;j++)
offGraphics.drawImage(small[15],100-9*j,230,this);
offGraphics.drawImage(small[39],140,230,this);
offGraphics.drawString("Taking all coins and advancing",180,242);
offGraphics.drawString("to next level, 1000 points",180,257);
gameState=12;
counter=0;
}
public void waitIntro3()
{
offGraphics.setColor(Color.black);
offGraphics.fillRect(60,150,20,30);
offGraphics.drawImage(small[animF[counter&7]],60,150,this);
offGraphics.drawImage(small[16],80,150,this);
if (counter>70)
gameState=7;
}
public void removeActor(int i)
{
int j;
for (j=i;j<actors;j++)
{
x[j]=x[j+1];
y[j]=y[j+1];
dx[j]=dx[j+1];
dy[j]=dy[j+1];
look[j]=look[j+1];
motion[j]=motion[j+1];
creature[j]=creature[j+1];
}
actors--;
}
public void updateScore(long i)
{
score+=i;
offGraphics.setColor(Color.black);
offGraphics.fillRect(50,0,60,12);
offGraphics.setColor(Color.white);
offGraphics.drawString(String.valueOf(score),50,12);
}
public void paint(Graphics g)
{
g.drawImage(offImage,0,0,this);
}
public void update(Graphics g)
{
int k;
switch (gameState)
{
case 2: // Playing
offGraphics.drawImage(playField,0,mainY-playY,this);
for (k=0;k<actors;k++)
offGraphics.drawImage(small[look[k]],x[k]-30,y[k]-30+mainY-playY,this);
break;
case 3:
offGraphics.drawImage(small[39*(counter&1)],x[0]-30,y[0]-30+mainY-playY,this);
break;
default:
break;
}
paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -