?? fallingstars.java
字號:
for(tempInt = 1; tempInt <= numberOffStars; tempInt++)
{
if(mouseMoved)
{
mouseMove();
}
switch(starSize[tempInt])
{
case 0: // '\0'
explosion.stop();
pause(10);
explosion.play();
starSize[tempInt] = 2;
exploding = true;
repaint();
break;
case 1: // '\001'
starX[tempInt] += starXAdd[tempInt];
if(starX[tempInt] > size().width - 5)
{
starX[tempInt] = (starX[tempInt] - (size().width - 5)) + 5;
}
if(starX[tempInt] < 5)
{
starX[tempInt] += size().width - 10;
}
starY[tempInt] += starYAdd[tempInt];
if(starY[tempInt] > size().height - 35)
{
starY[tempInt] -= size().height - 35;
}
offscreenG.drawImage(star, starX[tempInt] - (star.getWidth(this) * starSize[tempInt]) / 2, starY[tempInt] - (star.getHeight(this) * starSize[tempInt]) / 2, star.getWidth(this) * starSize[tempInt], star.getHeight(this) * starSize[tempInt], this);
break;
default:
starSize[tempInt]++;
if(starSize[tempInt] <= 6)
{
offscreenG.drawImage(star, starX[tempInt] - (star.getWidth(this) * starSize[tempInt]) / 2, starY[tempInt] - (star.getHeight(this) * starSize[tempInt]) / 2, star.getWidth(this) * starSize[tempInt], starSize[tempInt] * star.getHeight(this), this);
} else
{
endStar(tempInt);
}
break;
}
if(starX[tempInt] + star.getWidth(this) / 2 > shipX - ship.getWidth(this) / 2 && starX[tempInt] + star.getWidth(this) / 2 < shipX + ship.getWidth(this) / 2 && starY[tempInt] + star.getHeight(this) > size().height - 65)
{
shiphit = true;
numberOffShips--;
replaceStar(tempInt);
}
if(shiphit)
{
explosion.stop();
shipExploding.play();
shipExplode();
if(numberOffShips == 0)
{
theEnd();
}
shiphit = false;
}
}
repaint();
pause(100 - (((level - 1) / 4) * 80 * numberOffStars) / maxStars);
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
} else
if(starting)
{
makeItBlack();
choiceLevel();
} else
{
for(tempInt = 1; tempInt <= 10; tempInt++)
{
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
offscreenG.setColor(Color.green);
sky();
introText();
border();
offscreenG.setFont(f);
offscreenG.drawString(startString, (size().width - fm.stringWidth(startString)) / 2, size().height / 2);
repaint();
pause(100);
}
for(tempInt = 1; tempInt <= 10; tempInt++)
{
offscreenG.setColor(Color.black);
offscreenG.fillRect(0, 0, size().width, size().height);
offscreenG.setColor(Color.red);
sky();
introText();
border();
offscreenG.setFont(f);
offscreenG.drawString(startString, (size().width - fm.stringWidth(startString)) / 2, size().height / 2);
repaint();
pause(100);
}
}
}
}
public void update(Graphics g)
{
if(!ended)
{
if(started)
{
if(exploding)
{
g.setColor(Color.white);
g.fillRect(0, 0, size().width, size().height);
g.drawImage(ship, shipX, size().height - 65, this);
border(Color.red);
scoreBoard(Color.red);
exploding = false;
}
if(shiphit)
{
offscreenG.drawImage(shipexplode, shipX - (shipexplode.getWidth(this) * tempInt2) / 2, size().height - shipexplode.getHeight(this) * tempInt2 - 35, shipexplode.getWidth(this) * tempInt2, shipexplode.getHeight(this) * tempInt2, this);
border(Color.red);
scoreBoard(Color.red);
} else
{
offscreenG.drawImage(ship, shipX - ship.getWidth(this) / 2, size().height - 65, this);
border(Color.blue);
scoreBoard(Color.blue);
if(firing)
{
offscreenG.setColor(Color.red);
offscreenG.drawLine(shipX - 1, size().height - 65, shipX - 1, 6);
offscreenG.drawLine(shipX, size().height - 65, shipX, 6);
offscreenG.drawLine(shipX + 1, size().height - 65, shipX + 1, 6);
firing = false;
}
}
g.drawImage(offscreenI, 0, 0, this);
return;
} else
{
g.drawImage(offscreenI, 0, 0, this);
return;
}
} else
{
g.drawImage(offscreenI, 0, 0, this);
return;
}
}
public int rnd(int i)
{
return (int)((double)i * Math.random());
}
public void sky()
{
for(int i = 1; i <= 5; i++)
{
offscreenG.drawImage(star, rnd(size().width), rnd(size().height), this);
}
}
public void border()
{
for(int i = 0; i <= 4; i++)
{
offscreenG.drawRect(i, i, size().width - 2 * i, size().height - 2 * i);
}
}
public void border(Color color)
{
Color color1 = offscreenG.getColor();
offscreenG.setColor(color);
border();
offscreenG.setColor(color1);
}
public void introText()
{
Color color = offscreenG.getColor();
offscreenG.setColor(Color.white);
offscreenG.setFont(f2);
introY--;
if(introY <= -330)
{
introY = size().height + 10;
}
offscreenG.drawImage(ship, size().width / 2 - ship.getWidth(this) / 2, introY, this);
offscreenG.drawString(introText1, (size().width - fm2.stringWidth(introText1)) / 2, introY + 50);
offscreenG.drawString(introText2, (size().width - fm2.stringWidth(introText2)) / 2, introY + 70);
offscreenG.drawString(introText3, (size().width - fm2.stringWidth(introText3)) / 2, introY + 90);
offscreenG.drawString(introText4, (size().width - fm2.stringWidth(introText4)) / 2, introY + 110);
offscreenG.drawString(introText5, (size().width - fm2.stringWidth(introText5)) / 2, introY + 130);
offscreenG.drawString(introText6, (size().width - fm2.stringWidth(introText6)) / 2, introY + 150);
offscreenG.drawString(introText7, (size().width - fm2.stringWidth(introText7)) / 2, introY + 170);
offscreenG.drawString(introText8, (size().width - fm2.stringWidth(introText8)) / 2, introY + 190);
offscreenG.drawString(introText9, (size().width - fm2.stringWidth(introText9)) / 2, introY + 210);
offscreenG.drawString(introText10, (size().width - fm2.stringWidth(introText10)) / 2, introY + 230);
offscreenG.drawString(introText11, (size().width - fm2.stringWidth(introText11)) / 2, introY + 250);
offscreenG.drawString(introText12, (size().width - fm2.stringWidth(introText12)) / 2, introY + 270);
offscreenG.drawString(introText13, (size().width - fm2.stringWidth(introText13)) / 2, introY + 290);
offscreenG.drawString(introText14, (size().width - fm2.stringWidth(introText14)) / 2, introY + 310);
offscreenG.drawString(introText15, (size().width - fm2.stringWidth(introText15)) / 2, introY + 330);
offscreenG.drawString(introText16, (size().width - fm2.stringWidth(introText16)) / 2, introY + 350);
offscreenG.drawString(introText17, (size().width - fm2.stringWidth(introText17)) / 2, introY + 370);
offscreenG.setColor(color);
}
public void makeItBlack()
{
offscreenG.setColor(Color.black);
for(int i = 1; i <= size().height / 2; i += 5)
{
int j = (size().height * i) / size().width;
offscreenG.setColor(Color.black);
offscreenG.fillRect(size().width / 2 - i, size().height / 2 - j, 2 * i, 2 * j);
offscreenG.setColor(Color.blue);
offscreenG.drawRect(size().width / 2 - i, size().height / 2 - j, 2 * i, 2 * j);
repaint();
pause(10);
}
border(Color.blue);
repaint();
}
public void hitCheck()
{
for(int i = 1; i <= numberOffStars; i++)
{
if((starX[i] - 4 <= shipX + 1 && starX[i] + 4 >= shipX + 1 || starX[i] - 4 <= shipX - 1 && starX[i] + 4 >= shipX - 1) && starSize[i] == 1)
{
starSize[i] = 0;
score++;
}
}
}
public void paint(Graphics g)
{
update(g);
}
public void pause(int i)
{
try
{
Thread.sleep(i);
return;
}
catch(InterruptedException _ex)
{
return;
}
}
public void replaceStar(int i)
{
starX[i] = (int)((double)(size().width - 56) * Math.random() + 28D);
starY[i] = 6;
starYAdd[i] = (int)(5D + 13D * Math.random());
starYAdd[i] = starYAdd[i] / (6 - level);
starXAdd[i] = (int)((double)(starYAdd[i] + 1) * Math.random());
if(starXAdd[i] > starYAdd[i])
{
starXAdd[i] = starYAdd[i];
}
if(Math.random() < 0.5D)
{
starXAdd[i] *= -1;
}
}
public void shipExplode()
{
for(tempInt2 = 1; tempInt2 <= 8; tempInt2++)
{
offscreenG.drawImage(shipexplode, shipX - (shipexplode.getWidth(this) * tempInt2) / 2, size().height - shipexplode.getHeight(this) * tempInt2 - 35, shipexplode.getWidth(this) * tempInt2, shipexplode.getHeight(this) * tempInt2, this);
repaint();
pause(150);
}
for(int i = 1; i <= numberOffStars; i++)
{
if(starX[i] > shipX - (shipexplode.getWidth(this) * 4) / 2 && starX[i] < shipX + (shipexplode.getWidth(this) * 4) / 2 && starY[i] > size().height - shipexplode.getHeight(this) * 4 - 35)
{
replaceStar(i);
}
if(shipX - (shipexplode.getWidth(this) * 4) / 2 < 5 && starX[i] > size().width - 5 - shipX - (shipexplode.getWidth(this) * 4) / 2 - 5 && starY[i] > size().height - shipexplode.getHeight(this) * 4 - 35)
{
replaceStar(i);
}
if(shipX + (shipexplode.getWidth(this) * 4) / 2 > size().width - 5 && starX[i] < ((shipX + (shipexplode.getWidth(this) * 4) / 2) - (size().width - 5)) + 5 && starY[i] > size().height - shipexplode.getHeight(this) * 4 - 35)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -