Hi, I want to add the pong game below a speed function which makes game speed increase with 10 hits.

PImage startscreen;

final int stageStartscreen = 1; // game stages final int stageGame = 2;
final int stageGameOver = 3;

int stage; // stage of the program

int base=20; int x, y; int hit = 0; int miss = 0;

int changeX=-5; int changeY=-5;

int gameOver=0;

void setup() { stage = 1; startscreen = loadImage("2teniscourt.jpg"); image(startscreen, 0, 0, 600, 600); size(600, 600); x=(int)random(23, width-23); y=height-base-23; }

void draw() { if (stage==1) { //background (0); image(startscreen, 600, 600);
textAlign(CENTER); textSize(45); fill(66, 104, 244); text("PONG GAME", width/2, 170); text("Press any key to start", width/2, 170+77); if (keyPressed == true) { stage = 2; } } else if (stage == 2) {

background(100, 200, 100);

if (gameOver==0) { 
  background(0); 
  textAlign(LEFT); 
  fill(244, 66, 66); 
  text("hit: " + hit, 7, 40); 
  fill(66, 104, 244); 
  rect(mouseX, height-base, 150, base); 
  ellipse(x, y, 40, 40); 
  //move
  x=x+changeX; 
  y=y+changeY; 
  // we use 20 here which is the radius of the ball  
  if (x<20 | x>width-20) { 
    changeX=-changeX;
  } 
  if (y<20) { 
    changeY=-changeY;
  } 
  if (y>height-base-20) { 
    //check whether it is falling inside the rectangle or not
    if (x>mouseX && x<mouseX+200) { 
      changeY = -changeY; 
      y-=6; 
      //bounce back 
      hit += 1;
    } else { 
      // game over
      gameOverSplash();
    }
  }
} else { 
  background(244, 78, 66); 
  fill(66, 104, 244); 
  textAlign(CENTER); 
  text("Game Over!", width/2, height/2); 
  text("CLICK MOUSE TO RESTART", width/2, height/2+60);
}//else

}//stage 2 }// func

void gameOverSplash() { gameOver=1; }

void mouseClicked() { if (gameOver==1) { changeY=-changeY; hit +=1; gameOver=0; } }

Answers

  • Answer ✓

    hi, i want you to format the code so that we can read it.

    edit the post, highlight the code, press ctrl-o

  • Answer ✓

    Post your code correctly

  • Answer ✓

    and please don't post duplicates.

  • I am sorry. I don't know why there is such a problem.

  • Answer ✓

    First don't post new but edit old post

    Click on the gearwheel to the right and then on edit

    Then select entire code and hit ctrl-o

    Or the small C in the command bar

  • Answer ✓

    Now I see you haven't made the changes I recommended

  • Answer ✓

    ;-)

  • very sorry for that

  • I am in a such hurry that I cannot check the format of the site. Sorry for that guys.

  • No pain no gain

  • First don't post new but edit old post

    Click on the gearwheel to the right and then on edit

    Then select entire code and hit ctrl-o

  • edited January 2017

    Look at if greater 10

    Then increase what you add to ball pos

    if(hit>10) {
        if (changeX<0) changeX--; else changeX++; 
        if (changeY<0) changeY--; else changeY++; 
    }
    
  • I am in a such hurry that I cannot check the format of the site.

    it takes literally 20 seconds. and without it we have trouble reading your code.

Sign In or Register to comment.