选择游戏后,使用处理创建游戏街机。不会画画,仍然会跑。加工



嗨,基本上每当我点击pb来运行我的游戏时,它们都会运行,但你看不到它们,因为它们不会覆盖主菜单屏幕。如果分开,这些游戏确实有效。

PImage pongImage, brickImage;
boolean mouseDown = false;
boolean [] keys = new boolean [128];
Ball ball;
Paddleb gamerPaddle;
static ArrayList<Brick> bricks = new ArrayList();
Puck puck;
Paddle one;//left
Paddle two;//right
int oneScore = 0;
int twoScore = 0;
int gameScreen = 0;
void setup() {
fullScreen();
ball = new Ball();//creating objects
gamerPaddle = new Paddleb();
puck = new Puck();//creating objects
one = new Paddle(true);
two = new Paddle(false);
}
void draw() {
menuPress();
if (gameScreen == 0) {
mainMenu();
}
if (gameScreen ==1) {
gamePong();
}
if (gameScreen == 2) {
gameBrick();
}
}
void keyReleased() {
keys[key] = false;
one.move(0);
two.move(0);
gamerPaddle.move(0);
}
void menuPress() {
if (keys['p'] == true) {
gameScreen = 1;
} else if (keys ['b'] == true) {
gameScreen =2;
} else {
gameScreen = 0;
}
}
void moves() {
if (keys['w'] == true) {
one.move(-10);
} else if (keys['s'] == true) {
one.move(10);
}
if (keys['i'] == true) {
two.move(-10);
} else if (keys['k'] == true) {
two.move(10);
}
if (keys['a'] == true) {
gamerPaddle.move(-10);
} else if (keys['d'] == true) {
gamerPaddle.move(10);
}
}
void keyPressed() {
keys[key] = true;
}
void drawBricks() {
for (int i = 0; i <= bricks.size() - 1; i++) {
fill(255);
rectMode(CORNER);
rect(bricks.get(i).x, bricks.get(i).y, bricks.get(i).s, bricks.get(i).s2);
}
}
void bricksSetup() {
rectMode(CORNER);
float s = 80;
float x = width/4;
float y = Brick.space;
while (y < height/2) {
while (x < width - width/4) {
bricks.add(new Brick(x, y, s, s));
x +=90;
}
x = width/4;
y +=90;
}
}
void mainMenu() {
float picsY = height/2;
float brickX = 2 * width/3;
float pongX = width/3 - width/4;
pongImage = loadImage("pong photo.PNG");
brickImage = loadImage("Brick breaker.PNG");
pongImage.resize(width/4, height/4);
brickImage.resize(width/4, height/4);
background(150);
fill(255);
textSize(72);
text("AhMen's Arcade", width/5 + width/7, height/3);
image(pongImage, pongX, picsY);
text("Pong", width/6, 4 * height/5 + height/50);
image(brickImage, brickX, picsY);
text("Brick Breaker", 2 * width/3 + width/100, 4 * height/5 + height/50);
}
void gamePong() {
background(0);
System.out.println("cat");
boolean gameEnding = false;
do {
background(0);
one.screen();//creates paddle
two.screen();
puck.position();
puck.sides();
puck.screen();
moves();
puck.checkHitOne(one);
puck.checkHitTwo(two);
one.refresh();//limits y movement and keeps it moving at speed of 0 to make stops and starts not noticible
two.refresh();
fill(255);
textSize(32);
text(oneScore, 20, 50);
text(twoScore, width-40, 50);
textMode(CENTER);
text("PONG", width/2-55, 50);
} while (gameEnding != true);
exit();
}
void gameBrick() {
System.out.println("ya");
background(0);
bricksSetup();
ball.position();
while (ball.y - ball.r > height || ball.p1Score >= ((bricks.size()-1)*50)) {
System.out.println('l');
background(0);
moves();
drawBricks();
ball.checkHitTwo(gamerPaddle);
ball.checkHitBrick();
gamerPaddle.screen();//creates paddle
gamerPaddle.refresh();//limits y movement and keeps it moving at speed of 0 to make stops and starts not noticible
gamerPaddle.refresh();
ball.position();
ball.sides();
ball.screen();
ball.score();
}
exit();
}

这只是btw的主要方法,我确实有其他方法用于对象。我不知道为什么这不起作用,但如果有人知道问题可能是什么,请lmk。

处理绘图函数不在单独的线程上运行。当你有一个while循环,它没有结束时,draw函数就再也不会执行了。

您必须使用处理文件范围内的变量,而不仅仅是一个函数,然后在当前用作游戏循环的函数中修改这些变量。

例如,如果你想要一个程序,其中一个球向右移动,并在经过它后返回到坐标0,你必须这样构建它:

Ball ball = new Ball();
void draw() {
playBallGame();
drawBall();
}
void playBallGame() {
if (ball.x > width) ball.x = 0;
ball.x++;
}

不是这样的:

void draw() {
drawBall();
playBallGame();
}
void playBallGame() {
Ball ball = new Ball();
while (true) {
if (ball.x > width) ball.x = 0;
ball.x++;
}
}

最新更新