📄 worldcupsoccerslime.java
字号:
case Event.KEY_ACTION_RELEASE:
case 402: // Event.KEY_RELEASE
switch(event.key)
{
case 's':
case 'S':
fP1Sticky = false;
break;
case 'k':
case 'K':
case Event.DOWN:
fP2Sticky = false;
break;
case 65: // 'A'
case 97: // 'a'
if(p1XV < 0)
p1XV = 0;
break;
case 68: // 'D'
case 100: // 'd'
if(p1XV > 0)
p1XV = 0;
break;
case Event.LEFT:
case 74: // 'J'
case 106: // 'j'
if(p2XV < 0)
if (!worldCup)
p2XV = 0;
break;
case Event.RIGHT:
case 76: // 'L'
case 108: // 'l'
if(p2XV > 0)
if (!worldCup)
p2XV = 0;
break;
}
}
return false;
}
private int[] pointsX = new int[4], pointsY = new int[4];
private void DrawSlimers()
{
int k1 = nWidth / 10;
int j2 = nHeight / 10;
int i3 = nWidth / 50;
int j3 = nHeight / 25;
int k3 = (ballX * nWidth) / 1000;
int l3 = (4 * nHeight) / 5 - (ballY * nHeight) / 1000;
int i = (p1OldX * nWidth) / 1000 - k1 / 2;
int l = (7 * nHeight) / 10 - (p1OldY * nHeight) / 1000;
screen.setColor(Color.blue);
screen.fillRect(i, l, k1, j2);
i = (p2OldX * nWidth) / 1000 - k1 / 2;
l = (7 * nHeight) / 10 - (p2OldY * nHeight) / 1000;
screen.setColor(Color.blue);
screen.fillRect(i, l, k1, j2);
if (!fEndGame) MoveBall();
i = (p1X * nWidth) / 1000 - k1 / 2;
l = (7 * nHeight) / 10 - (p1Y * nHeight) / 1000;
screen.setColor(fSuperSlime ? slimaryCols[frenzyCol = ((frenzyCol + 1) % slimaryCols.length)] : slimaryCols[p1Col]);
screen.fillArc(i, l, k1, 2 * j2, 0, 180);
screen.setColor(secondaryCols[p1Col]);
pointsX[0] = pointsX[2] = i+k1/2; pointsX[1] = i + k1 * 2 / 5; pointsX[3] = i + k1 / 8;
pointsY[0] = l; pointsY[1] = pointsY[3] = l + j2/2; pointsY[2] = l + j2;
screen.fillPolygon(pointsX, pointsY, 4);
int l4 = p1X + 38;
int i5 = p1Y - 60;
i = (l4 * nWidth) / 1000;
l = (7 * nHeight) / 10 - (i5 * nHeight) / 1000;
int i4 = i - k3;
int j4 = l - l3;
int k4 = (int)Math.sqrt(i4 * i4 + j4 * j4);
boolean flag = Math.random() < 0.01D;
if(flag)
p1Blink = 5;
if(p1Blink == 0)
{
screen.setColor(Color.white);
screen.fillOval(i - i3, l - j3, i3, j3);
if(k4 > 0 && !flag)
{
screen.setColor(Color.black);
screen.fillOval(i - (4 * i4) / k4 - (3 * i3) / 4, l - (4 * j4) / k4 - (3 * j3) / 4, i3 / 2, j3 / 2);
}
} else
{
p1Blink--;
}
if(p1Score > p2Score + SMILE_DIFF)
{
int j = (p1X * nWidth) / 1000;
int i1 = (7 * nHeight) / 10 - ((p1Y - 40) * nHeight) / 1000;
int l1 = nWidth / 20;
int k2 = nHeight / 20;
int j5 = 0;
do
{
screen.setColor(Color.black);
screen.drawArc(j, i1 + j5, l1, k2, -30, -150);
} while(++j5 < 3);
}
i = (p2X * nWidth) / 1000 - k1 / 2;
l = (7 * nHeight) / 10 - (p2Y * nHeight) / 1000;
screen.setColor(fSuperSlime ? slimaryCols[frenzyCol = ((frenzyCol + 1) % slimaryCols.length)] : slimaryCols[p2Col]);
screen.fillArc(i, l, k1, 2 * j2, 0, 180);
screen.setColor(secondaryCols[p2Col]);
pointsX[0] = pointsX[2] = i+k1/2; pointsX[1] = i+k1*3/5; pointsX[3] = i+k1*7/8;
pointsY[0] = l; pointsY[1] = pointsY[3] = l+j2/2; pointsY[2] = l+j2;
screen.fillPolygon(pointsX, pointsY, 4);
l4 = p2X - 18;
i5 = p2Y - 60;
i = (l4 * nWidth) / 1000;
l = (7 * nHeight) / 10 - (i5 * nHeight) / 1000;
i4 = i - k3;
j4 = l - l3;
k4 = (int)Math.sqrt(i4 * i4 + j4 * j4);
flag = Math.random() < 0.01D;
if(flag)
p2Blink = 5;
if(p2Blink == 0)
{
screen.setColor(flag ? Color.gray : Color.white);
screen.fillOval(i - i3, l - j3, i3, j3);
if(k4 > 0 && !flag)
{
screen.setColor(Color.black);
screen.fillOval(i - (4 * i4) / k4 - (3 * i3) / 4, l - (4 * j4) / k4 - (3 * j3) / 4, i3 / 2, j3 / 2);
}
} else
{
p2Blink--;
}
if(p2Score > p1Score + SMILE_DIFF)
{
int i2 = nWidth / 20;
int l2 = nHeight / 20;
int k = (p2X * nWidth) / 1000 - i2;
int j1 = (7 * nHeight) / 10 - ((p2Y - 40) * nHeight) / 1000;
int k5 = 0;
do
{
screen.setColor(Color.black);
screen.drawArc(k, j1 + k5, i2, l2, -10, -150);
} while(++k5 < 3);
}
}
public void paint(Graphics g)
{
nWidth = size().width;
nHeight = size().height;
screen.setColor(Color.blue);
screen.fillRect(0, 0, nWidth, (4 * nHeight) / 5);
screen.setColor(Color.gray);
screen.fillRect(0, (4 * nHeight) / 5, nWidth, nHeight / 5);
screen.setColor(Color.white);
// g.fillRect(nWidth / 2 - 2, (7 * nHeight) / 10, 4, nHeight / 10 + 5);
drawScores();
if (!fInPlay)
{
DrawSlimers();
drawButtons();
}
DrawGoals();
drawPrompt();
if(!fInPlay)
{
FontMetrics fontmetrics = screen.getFontMetrics();
screen.setColor(Color.white);
if (fSuperSlime)
screen.drawString("Super Soccer Slime!", nWidth / 2 - fontmetrics.stringWidth("Super Soccer Slime!") / 2, nHeight / 2 - fontmetrics.getHeight());
else
screen.drawString("Soccer Slime!", nWidth / 2 - fontmetrics.stringWidth("Soccer Slime!") / 2, nHeight / 2 - fontmetrics.getHeight());
screen.setColor(Color.white);
fontmetrics = screen.getFontMetrics();
screen.drawString("Written by Quin Pendragon", nWidth / 2 - fontmetrics.stringWidth("Written by Quin Pendragon") / 2, nHeight / 2 + fontmetrics.getHeight() * 2);
}
flip();
}
public void destroy()
{
gameThread.stop();
gameThread = null;
}
private void ReplayFrame(int i, int j, int k, int l, int i1, boolean flag)
{
if(flag)
{
ballX = -1000; ballOldX = 500;
ballY = -1000; ballOldY = 500;
p1OldX = p1OldY = p2OldX = p2OldY = -10000;
} else
{
int j1 = i != 0 ? i - 1 : 199;
p1OldX = replayData[j1][0];
p1OldY = replayData[j1][1];
p2OldX = replayData[j1][2];
p2OldY = replayData[j1][3];
if (i == 0)
{
ballOldX = 500;
ballOldY = 200;
}
else
{
ballOldX = replayData[j1][4];
ballOldY = replayData[j1][5];
}
}
p1X = replayData[i][0];
p1Y = replayData[i][1];
p2X = replayData[i][2];
p2Y = replayData[i][3];
ballX = replayData[i][4];
ballY = replayData[i][5];
p1Col = replayData[i][6];
p2Col = replayData[i][7];
ballVX = 0;
ballVY = 1;
if((i / 10) % 2 > 0)
{
screen.setColor(Color.red);
screen.drawString("Replay...", j, k);
} else
{
screen.setColor(Color.blue);
screen.fillRect(j, k - i1, l, i1 * 2);
}
DrawSlimers();
DrawGoals();
try
{
Thread.sleep(20L);
return;
}
catch(InterruptedException _ex)
{
return;
}
}
private String MakeTime(long l)
{
long l1 = (l / 10L) % 100L;
long l2 = (l / 1000L) % 60L;
long l3 = (l / 60000L) % 60L;
String s = "";
if(l3 < 10L)
s += "0";
s += l3;
s += ":";
if(l2 < 10L)
s += "0";
s += l2;
s += ":";
if(l1 < 10L)
s += "0";
s += l1;
return s;
}
private void MoveSlimers()
{
if (worldCup) //get the AI to move p2
{
switch (worldCupRound)
{
case 0: controlP2v0(); break;
case 1: controlP2v1(); break;
case 2: controlP2v2(); break;
case 3: controlP2v3(); break;
}
}
p1X += p1XV;
if(p1X < 50)
p1X = 50;
if(p1X > 950)
p1X = 950;
if(p1YV != 0)
{
p1Y += p1YV -= GRAVITY;
if(p1Y < 0)
{
p1Y = 0;
p1YV = 0;
}
}
p2X += p2XV;
if(p2X > 950)
p2X = 950;
if(p2X < 50)
p2X = 50;
if(p2YV != 0)
{
p2Y += p2YV -= GRAVITY;
if(p2Y < 0)
{
p2Y = 0;
p2YV = 0;
}
}
}
public WorldCupSoccerSlime()
{
p2Col = 1;
replayData = new int[200][8];
}
private void MoveBall()
{
int k = (30 * nHeight) / 1000;
int i = (ballOldX * nWidth) / 1000;
int j = (4 * nHeight) / 5 - (ballOldY * nHeight) / 1000;
screen.setColor(Color.blue);
screen.fillOval(i - k, j - k, k * 2, k * 2);
ballY += --ballVY;
ballX += ballVX;
if(!fEndGame)
{
int l1 = (ballX - p1X) * 2;
int i2 = ballY - p1Y;
int j2 = l1 * l1 + i2 * i2;
int k2 = ballVX - p1XV;
int l2 = ballVY - p1YV;
if(i2 > 0 && j2 < 15625 && j2 > 25)
{
int l = (int)Math.sqrt(j2);
int j1 = (l1 * k2 + i2 * l2) / l;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -