Need a little help getting my title screen to appear

Font400

When I run this code i get a blank screen with no action. I took gameState and drawScreen from another assignment that I completed and the game works great with the title page appearing before the game. For some reason I can't get it to work with this game. I'm focusing on help specifically in my drawScreen function and seeing if there's something that I'm missing and if there's something that I need to takeout. Again I'm just trying to get the title screen to appear so that I won't have a blank screen when launching program.

      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);
      }
Cadin

It doesn't look like you ever set the initial value of gameState. It will default to 0, which is not one of the cases in your switch statement.

Initialize the variable with 1 (int gameState = 1;), OR change your INTRO case to be zero and you should see the intro screen pop up.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Just need a little help debugging my code

Need help getting a Toast to appear on a Tab Fragment

Need help getting my divs to display inline

Need little help php mysql

Need a little regex help in python

need a little help finishing this code

Need a little help populating in Excel

Need little help on React hooks

Need help getting a custom layout to work with my Android AlertDialog

need help in my php code getting wrong directory on breadcrumb

Need help in my C code - Getting unexpected output

I need help getting my object to move around

HTML/CSS Need help getting my anchors to be the same size

Need help getting a list of people that like my photo on facebook

I need help getting my code to look like this:

I need help getting on('focus') to work with my website search box

Need help in getting my combination of strings from treeview column into textbox

I need some help at my script (c#) with little lines of code or explanation for math formula

new to coding, need if statement help on my own little code I made

Need a little help, in hiding/disabling the jbutton

Need a little help to fix an Arduino RFID program

I need some help for a little SwiftUI animation

Need help getting this closure working

onActivityResult need help getting image

Need help getting percent of a number

Need help getting rid of NaN

Need help changing Title of the page using JQuery

Simplification of code (need help to refine the title of this question ... )

Need help finding why my application does not leave the home screen upon button click (which should take me to a second activity screen)