I can't fix my scoreboard on the screen

edited December 2014 in Questions about Code

I made this pong, but i can't fix me score on the screen, it appear when hit the padle and right after desappear

Answers

  • don't have the text(score....) where you check you paddle - better put it in draw()

    when the paddle is hit only increase your score

    also show your code when you want real help...

  • edited December 2014

    Here is my code guys, sorry about it

    boolean gameStart = false; PFont font; int placar = 0; float x = random(500); float y = random(700); float vx = random(10); float vy = random(10);

    void setup() { noCursor(); size(500, 700); }

    void draw() { noStroke(); background(0);

    font = loadFont("Minecraftia-25.vlw"); textFont(font, 50); text("placar", 50, 50);

    //condição para rebater na barra móvel, controlada pelo usuário if ( x > width-40 && x < width-20 && y > mouseY-200 && y < mouseY+200) { vx = vx * -1; x = x + vx; placar = placar + 1; text("placar = "+ placar, 50, 50); }

    fill(255); rect(0, 0, 30, height); rect(width-30, mouseY, 40, 200);

    fill(255, 255, 0); ellipse(x, y, 20, 20);

    if (gameStart) { x = x + vx; y = y + vy;

    //condição para bater na barra lateral fixa
    if (x <= 30) {
      vx = -vx;
      x = x + vx;
    }
    
    
    //para rebater no topo e na base
    if (y >= height-10 || y <= 10) {
      vy = -vy;
    }
    
    if (x > width) { 
      gameStart = false;
      x = 150;
      y = 150; 
      vx = random(3, 5);
      vy = random(3, 5);
      placar = 0;
    }
    

    } }

    void mousePressed() { gameStart = !gameStart; }

  • i definitely would load the font in setup() - it's a one time thing, so it belongs in setup().

    draw() is executed 60 times per second, so to load font here slows things down quite a bit.

    anyway concening the score, I guess you have to say fill (200) before it. or was it stroke, can't remember

    ;-)

  • also you got text(placar... twice, delete the one inside the if-clause

    also, read about how to post in the forum, how to format code here

    thank you!

Sign In or Register to comment.