Juego acelerado


boolean  gameOver = true;

float posX;
float posY;

float speedX = 1;
float speedY = 1;     //DECLARAMOS

void setup () {
  size (500, 500);
  posY = random (height);
  posX = random (width);
  rectMode (CENTER); //posision del rectangulo de la base
  posX = width/2;
  posY = height/2;
}

void draw () {
  background (0);

  if (gameOver == true) {   //codigos para que salga game over
    background (#048630);   //fondo de ventana game over
    fill(255);    //color texto
    text ("GAME OVER", width/2, height/2);   //texto
  }

  else {    //codigos para cuando se esta jugando
    fill(255);    //color texto
    text("JUGANDO", width/2, height/2);    //texto

  fill (255);
  rect( mouseX, height*0.95, 80, 10);   //rectangulo: tamaños y codigo para que funcione con el mouse
  fill (#F50202);
  ellipse (posX, posY, 10, 10);

  if (speedY > 10) {
    speedY = 6;
  }

  if (posY > height) {
    speedY = -(speedY*1);  //AUMENTAMOS LA VELOCIDAD EN Y DE ABAJO
    posY = height;
  }
  if (posY < 0) {
    speedY = -(speedY*2); // AUMENTAMOS VELOCIDAD EN Y ARRIBA
    posY = 0;
  }
  if (posX > width) {
    speedX = -(speedX*1); //AUMENTAMOS VELOCIDAD EN X DERECHA
    posX = width;
  }
   if (posX < 0) {
    speedX = -(speedX*1);  //AUMENTAMOS VELOCIDAD EN X IZQUIERDA
    posX = 0;
  }

  if (posY == height) //codigo para cuando se reinicie y la pelotita salga del centro
{
  posX = width/2;
  posY = height/2;
  gameOver = true;
  speedX = speedX ;
  speedY = speedY ;
}
    if (posX > mouseX-30 && posX < mouseX + 30 && posY > 0.95*height-5 && posY < 0.95*height+5){
  speedX = speedX;
  speedY = -1*speedY;
    }


  posX = posX+speedX;
  posY = posY+speedY;
}
}
void keyPressed() {   //codigos para que se reinicie el juego
  if (gameOver == true) {
    gameOver = false;
  }
}

No hay comentarios:

Publicar un comentario