需要一点帮助让我的标题屏幕出现



当我运行这段代码时,我得到一个没有任何动作的空白屏幕。我从我完成的另一项任务中使用了gameState和drawScreen,游戏在游戏开始前出现标题页效果非常好。由于某些原因,我无法在这款游戏中使用它。我专注于帮助,特别是在我的drawScreen功能中看是否有我缺少的东西是否有我需要取出的东西。再次,我只是想让标题屏幕出现,这样我就不会有一个空白的屏幕时,启动程序。

int numBubbles = 40; // initial bubble count
final int BROKEN = -99; // code for "broken", may have other states later
final int MAXDIAMETER = 120; // maximum size of expanding bubble
PVector[] ellipses = { new PVector(150, 150), new PVector(300, 150), new PVector(450, 150)};
int diam = 100;
int mouseClicks = 15;
int gameState;
public final int INTRO = 1;
public final int PLAY = 2;
public final int PAUSE = 3;
public final int GAMEOVERWIN = 4;
public final int GAMEOVERLOSE = 5;
PFont font;


ArrayList pieces; // all the playing pieces

// CHANGE: variable to keep score
int score = 0;

void setup() {
pieces = new ArrayList(numBubbles);
background(0);
size(640, 640);
font = createFont("Cambria", 32); 
frameRate(24);
noStroke();
smooth();
for(int i = 0; i < numBubbles; i++) {
pieces.add(new Bubble(random(width), random(height), 30, i, pieces));
}

}

void mousePressed() {



// on click, create a new burst bubble at the mouse location and add it to the field
Bubble b = new Bubble(mouseX,mouseY,2,numBubbles,pieces);
// CHANGE: decrementing the score once so that score for new bubbles is not counted
--score;
b.burst();
pieces.add(b);
numBubbles++;
if (mouseButton == LEFT) { mouseClicks--; } else { mouseClicks = 15; }

}

void draw() {

switch(gameState) 
{
case INTRO:
drawScreen("Welcome!", "Press s to start");
break;
case PAUSE:
drawScreen("PAUSED", "Press p to resume");
break;
case GAMEOVERWIN:
drawScreen("GAME OVER, YOU WON!", "Press s to try again");
break;
case GAMEOVERLOSE:
drawScreen("GAME OVER, YOU LOST", "Press s to try again");
break;
case PLAY:
background(0);

if(mouseClicks >= 0 && score !=40)
gameState = GAMEOVERLOSE;
else
gameState = GAMEOVERWIN;
for(int i = 0; i < numBubbles; i++) {
Bubble b = (Bubble)pieces.get(i); // get the current piece
if(b.diameter < 1) { // if too small, remove
pieces.remove(i);
numBubbles--;
i--;
}
else {
// check collisions, update state, and draw this piece
if(b.broken == BROKEN) { // only bother to check collisions with broken bubbles
b.collide();
}
}
b.update();
b.display();
}

// CHANGE: printing the score to screen
textSize(32);
fill(0, 102, 153);
text(score , 10, 30);
text(mouseClicks+"Clicks remaing", 0,600,width,height);
break;
}
}

void drawScreen(String title, String instructions) 
{
background(0);

// draw title
fill(255,100,0);
textSize(60);
textAlign(CENTER, BOTTOM);
text(title, width/2, height/2);

// draw instructions
fill(255,255,255);
textSize(32);
textAlign(CENTER, TOP);
text(instructions, width/2, height/2);
}

看起来您从未设置过gameState的初始值。它将默认为0,这不是switch语句中的情况之一。

将变量初始化为1 (int gameState = 1;),或者将INTRO更改为零,您应该会看到介绍屏幕弹出。

最新更新