- scoreH - bWidth) / 2 + 30);
goff.setColor(new Color(255, 160, 64));
s = "使用方向键控制球拍移动";
【java弹球小游戏代码 java弹球小游戏实验报告】goff.drawString(s, (d.width - fmSmall.stringWidth(s)) / 2, (d.height
- scoreH - bWidth) / 2 + 50);
}
public void DrawBricks() {
int i, j;
boolean nobricks = true;
int colorDelta = 255 / (line - 1);
for (j = 0; jline; j++) {
for (i = 0; ibrickNumOfLine; i++) {
if (showbrick[j * brickNumOfLine + i]) {
nobricks = false;
goff.setColor(new Color(255, j * colorDelta, 255 - j
* colorDelta));
goff.fillRect(bWidth + i * (brickW + space), startline + j
* (brickH + space), brickW, brickH);
}
}
}
if (nobricks) {
InitBricks();
if (ingame)
iScroe += 100;
}
}
public void DrawPlayField() {
goff.setColor(Color.white);
goff.fillRect(0, 0, d.width, bWidth);
goff.fillRect(0, 0, bWidth, d.height);
goff.fillRect(d.width - bWidth, 0, bWidth, d.height);
goff.fillRect(0, d.height - bWidth, d.width, bWidth);
goff.fillRect(batpos, d.height - 2 * bWidth - scoreH, batW, batH);
goff.fillRect(ballx, bally, ballsize, ballsize);
}
public void ShowScore() {
goff.setFont(sFont);
goff.setColor(Color.white);
goff.drawString("得分:" + iScroe, 40, d.height - 10);
String s = "生命:" + ballNum;
goff
.drawString(s, d.width - 40 - fmSmall.stringWidth(s),
d.height - 10);
}
public void MoveBall() {
ballx += balldx;
bally += balldy;
if (bally = bWidth) {
balldy = -balldy;
bally = bWidth;
}
if (bally = (d.height - ballsize - scoreH)) {
if (ingame) {
ballNum--;
if (ballNum = 0)
ingame = false;
}
ballx = batpos + (batW - ballsize) / 2;
bally = startline + line * (brickH + space);
balldy = dxval;
balldx = 0;
}
if (ballx = (d.width - bWidth - ballsize)) {
balldx = -balldx;
ballx = d.width - bWidth - ballsize;
}
if (ballx = bWidth) {
balldx = -balldx;
ballx = bWidth;
}
}
public void BatDummyMove() {
if (ballx(batpos + 2))
batpos -= 3;
else if (ballx(batpos + batW - 3))
batpos += 3;
}
public void CheckBat() {
batpos += batpos;
if (batposbWidth)
batpos = bWidth;
else if (batpos(d.width - bWidth - batW))
batpos = (d.width - bWidth - batW);
if (bally = (d.height - scoreH - 2 * bWidth - ballsize)
bally(d.height - scoreH - 2 * bWidth)
(ballx + ballsize) = batposballx = (batpos + batW)) {
bally = d.height - scoreH - ballsize - bWidth * 2;
balldy = -dxval;
balldx = CheckBatBounce(balldx, ballx - batpos);
}
}
public int CheckBatBounce(int dy, int delta) {
int sign;
int stepsize, i = -ballsize, j = 0;
stepsize = (ballsize + batW) / 8;
if (dy0)
sign = 1;
else
sign = -1;
while (ibatWdeltai) {
i += stepsize;
j++;
}
switch (j) {
case 0:
case 1:
return -4;
case 2:
return -3;
case 7:
return 3;
case 3:
case 6:
return sign * 2;
case 4:
case 5:
return sign * 1;
default:
return 4;
}
}
public void CheckBricks() {
int i, j, x, y;
int xspeed = balldx;
if (xspeed0)
xspeed = -xspeed;
int ydir = balldy;
if (bally(startline - ballsize)
|| bally(startline + line * (space + brickH)))
return;
for (j = 0; jline; j++) {
for (i = 0; ibrickNumOfLine; i++) {
if (showbrick[j * brickNumOfLine + i]) {
y = startline + j * (space + brickH);
x = bWidth + i * (space + brickW);
推荐阅读
- 斗鱼斗鱼七哥直播视频,斗鱼七哥2020不直播了
- ios如何一键更新应用,苹果如何一键更新所有app
- 高尔夫体育游戏规则和玩法,高尔夫玩法视频教程
- b站流量看直播没有弹幕,b站直播怎么没弹幕
- vb.net经典问题 vbnet doevent
- html标签属性值含有双引号,html标签中的单引号与双引号
- eps转pdf,eps转PDF
- 复杂css动画,css动画代码大全
- 关于linuxtree命令的信息