Create Game Menu in Py.Processing

edited June 2016 in Python Mode

Hey all! I'm trying to create a simple game menu in my py.processing game, where I have options to view game instructions, a high score list and an option to start the game.

def draw():
    if game.State == "Menu":
        loadImage(path+'/background.png')
        if 200<= mouseX <= 310 and 150 <= mouseY <= 170:
            fill (255,0,0)

        else:
            fill(255)
        text("Play the Game!",300,200)
        text("View High Scores!",100,300)
        text("How to Play",30,50)

    elif game.state == "Play":
        game.display()
    elif game.state == "inputName":
        text("Game Over! Save your score:",200,100)
        text(game.name,300,200)

This is what I have so far. A menu displays just fine, but I can't give unique options to each feature. Any advice?

Answers

  • generic answer: you need to make buttons and then when the mouse is pressed in state Menu, check in which button the mouse has been pressed and set state accordingly with game.state = "Play" or so.

    The buttons are rects (can be invisible) that enclose the text "Play the Game!" and "View High Scores!" etc.

    you have state and State - make sure, you use only state

    this is in JAVA processing

    // moves ellipse by ScreenButtons for the Mouse 
    
    
    final color Green_C = color (2, 222, 2);
    
    int q=300; // x
    int w=100;  // y
    int s = 45;  // radius 
    int s2 = 110;  // radius 
    
    // =======================================
    
    void setup () {
    
      size (800, 880);
      strokeWeight(1);
    }
    
    
    void draw() {
      // delete screen
      background(111);
    
      // line color black
      stroke (0);
    
      fill(222);
      rect(60, 300, 60, 60);  
      fill(22);  
      text("UP", 70, 320);
    
      fill(222);
      rect(120, 300, 60, 60); 
      fill(22);  
      text(">", 130, 320);  
    
      fill(222);
      rect(180, 300, 60, 60);  
      fill(22);  
      text("Dn", 190, 320);    
    
      fill(222);
      rect(240, 300, 60, 60);      
      fill(22);  
      text("<", 250, 320);  
    
      stroke(Green_C);
      fill(Green_C);
      ellipse(q, w, s, s2);
    }
    
    // ========================================
    
    
    void mousePressed() {
      if ((mouseX>60) && (mouseY>300) && (mouseX<120) && (mouseY<360))
      {
        w = w-60;
      }
      if ((mouseX>120) && (mouseY>300) && (mouseX<180) && (mouseY<360))
      {
        q = q+60;
      }
      if ((mouseX>180) && (mouseY>300) && (mouseX<240) && (mouseY<360))  
      {
        w = w+60;
      }
      if ((mouseX>240) && (mouseY>300) && (mouseX<300) && (mouseY<360)) 
      {
        q = q-60;
      }
    }
    
Sign In or Register to comment.