📄 engine.java
字号:
level = 0;
}
restartLevel();
}
else
{
ballNumber = 1;
if (i == 0)
ball[0] = ball[1];
}
}
ballCollisioned(i);
if (ball[i].vx > 2.0f)
ball[i].vx = 2.0f;
if (ball[i].vx < -2.0f)
ball[i].vx = -2.0f;
if (ball[i].vy > 2.0f)
ball[i].vy = 2.0f;
if (ball[i].vy < -2.0f)
ball[i].vy = -2.0f;
if ((int)(ball[i].vx) == 0)
{
ball[i].vx = ((float)(randomG.nextG(7) - 64)) / 50.0f;
}
if ((int)(ball[i].vy) == 0)
{
ball[i].vy = ((float)(randomG.nextG(7) - 64)) / 50.0f;
}
}
public void capsulemoveLimit(int i)
{
if (capsule[i].vx < 0 && capsule[i].x <= 0)
capsule[i].vx *= -1.0f;
else if (capsule[i].x + capsule[i].cx >= Screen.width && capsule[i].vx > 0)
capsule[i].vx *= -1.0f;
if (capsule[i].vy < 0 && capsule[i].y <= 0)
capsule[i].vy *= -1.0f;
else if (capsule[i].vy > 0 && capsule[i].y + capsule[i].cy >= Screen.height - (Screen.fontHeight + 3))
{
capsule[i].use();
}
capsuleCollisioned(i);
}
public void ballCollisioned(int i)
{
ball[i].CollisionWithObject(paddle);
for (int x = 0; x < brickNum; x++)
{
if (bricks[x].strong > 0)
{
if (ball[i].CollisionWithObject(bricks[x]))
{
if ((bricks[x].strong -= 1) <= 0)
{
brickCount--;
score += ((Brick)bricks[x]).count;
hs.processDoc("/score.txt");
hs.setScore(score);
rank = hs.compareScore();
if(rank >= 2 && rank <= 10)
nextScore = hs.Score[rank - 2];
else if( rank == -1)
nextScore = hs.Score[9];
else if ( rank == 1)
nextScore = -1;
emitBonus(bricks[x].bonus, bricks[x].x + 32 / 2 - 7, bricks[x].y + 18);
if (brickCount <= 0)
{
ballNumber = 0;
capsuleNumber = 0;
brickNum = 0;
paddleNumber = 0;
level++;
if (level < 3)
{
startLevel();
}
else
{
level = 0;
startLevel();
}
}
}
}
}
}
}
public void capsuleCollisioned(int i)
{
if (capsule[i].CollisionWithObject(paddle))
{
capsule[i].use();
useBonus(i);
}
}
public void useBonus(int i)
{
currentCapsule = i;
bonusbeginTime = 0;
switch (capsule[i].type)
{
case 3:
plateEnlarge();
break;
}
}
public void resumebeforeBounus()
{
int i = capsule[currentCapsule].type;
switch (i)
{
case 3:
paddle.enlarge("/j6.png", changeRatioToPixW(conf.paddles[0].shape_width), changeRatioToPixW(conf.paddles[0].shape_height));
break;
}
}
public void emitBonus(int bonus, int x, int y)
{
switch (bonus)
{
case 2:
twoBalls();
break;
case 3:
capsule[capsuleNumber] = new Capsule("/j12.png", x, y,
0, 1.5f, 3);
capsule[capsuleNumber].setPos(x, y);
capsuleNumber = capsuleNumber + 1;
break;
}
}
public void twoBalls()
{
if (ballNumber == 1)
{
ball[1] = new Ball("/j5.png", (int)(Screen.width * conf.ball_initpos_width), (int)(Screen.height * conf.ball_initpos_height), (float)(conf.ball_initspeed_width), (float)(conf.ball_initspeed_height), 0);
ballNumber = 2;
}
}
public void plateEnlarge()
{
paddle.enlarge("/j2.png", changeRatioToPixW(conf.paddles[0].shape_width) * 2, changeRatioToPixW(conf.paddles[0].shape_height));
}
public void run()
{
boolean recentCollision;
long then;
int px, pw, delta;
int paddleSpeed = 0;
recentCollision = false;
then = System.currentTimeMillis();
while (!done)
{
if ((state == TITLE || state == OVER || state == HELP || state == NONETWORK)
&& System.currentTimeMillis() - lastKeyPress > LAST_KEY_DELTA)
{
state = MENU;
lastKeyPress = System.currentTimeMillis();
}
if ((state == PLAY) && !paused)
{
if (key == Canvas.LEFT)
{
left = true;
right = false;
}
else if (key == Canvas.RIGHT)
{
left = false;
right = true;
}
else if (key == 0)
{
left = false;
right = false;
}
paddle.move(left, right);
paddle.getV();
platemoveLimit();
for (int i = 0; i < ballNumber; i++)
{
if (ball[i].CollisionWithObject(this.paddle))
plategenerateMove = false;
ballmoveLimit(i);
ball[i].generateMove();
}
if (capsuleNumber > 0)
{
for (int i = 0; i < capsuleNumber; i++)
{
if (!capsule[i].isUsed())
{
capsulemoveLimit(i);
capsule[i].generateMove();
}
}
}
if (plategenerateMove)
paddle.generateMove();
plategenerateMove = true;
}
screen.repaint();
delta = (int)(System.currentTimeMillis() - then);
if (delta < 10)
{
try
{
Thread.sleep(10 - delta);
}
catch (InterruptedException e) { }
}
then = System.currentTimeMillis();
bonusbeginTime = bonusbeginTime + 10;
if (bonusbeginTime > 10000 && currentCapsule != -1)
{
resumebeforeBounus();
}
}
}
public int randomGen(double chance)
{
Random random = new Random(System.currentTimeMillis());
int k = random.nextInt();
int j = Math.abs(k % 100);
System.out.println("randombrick" + j);
int barrier = (int)(chance * 100);
if (j > barrier)
{
return 1;
}
else
return 2;
}
public int randomBrick(double chance)
{
//return 1;
Random random = new Random(System.currentTimeMillis());
int k = random.nextInt();
int j = Math.abs(k % 100);
System.out.println("randombrick" + j);
int barrier = (int)(chance * 100);
if (j > barrier)
{
return 1;
}
else
return 3;
}
public Image scale(Image src, int width, int height)
{
int scanline = src.getWidth();
int srcw = src.getWidth();
int srch = src.getHeight();
int buf[] = new int[srcw*srch];
src.getRGB(buf, 0, scanline, 0, 0, srcw, srch);
int buf2[] = new int[width*height];
for (int y = 0; y < height; y++)
{
int c1 = y * width;
int c2 = (y * srch / height) * scanline;
for (int x = 0; x < width; x++)
{
buf2[c1 + x] = buf[c2 + x * srcw / width];
}
}
Image img = Image.createRGBImage(buf2, width, height, true);
return img;
}
protected void setState(int state)
{
this.state = state;
}
protected int getAvailableLevels()
{
return availableLevels;
}
protected int getAvailableLives()
{
return availableLives;
}
protected void showMenu()
{
state = MENU;
oldBricks = bricks;
paused = true;
screen.repaint();
}
protected void resumeGame()
{
if (state == PLAY) paused = true;
levelStarted = true;
if (oldBricks != null)
{
bricks = oldBricks;
}
screen.repaint();
screen.serviceRepaints();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -