Deber Juego



boolean  gameOver = true; //DECLARAMOS (EN ESTE CASO VERDADERO)

float posX; // DECLARAMOS POSICIONES DE X /  Y
float posY;

float speedX = 3;  //DECLARAMOS VELOCIDAD DE X /Y
float speedY = 3;

void setup () {
  size (500, 500);
  posY = random (height);  //POSCICION ALEATORIA
  posX = random (width);
  rectMode (CENTER); //POSCICION DEL RECTANGULO EN LA BASE
  posX = width/2;
  posY = height/2;
}

void draw () {

  if (gameOver == true) {   // CONDICIONAL IF (GAME OVER)
    background (#100630);   // FONDO VENTANA GAME OVER
    fill(200);    //color texto
    text ("GAME OVER", width/2, height/2);   // TEXTO
  } else {    // CODIGOS PARA CUANDO SE ESTA JUGANDO

    fill(255);    //COLOR DE TEXTO
    text("JUGANDO", width/2, height/2);    //TEXTO


  fill (255);
  rect( mouseX, height*0.95, 80, 10);   //RECTANGULO (MOVIMIENTO CON EL MOUSE)
  fill (#F02222);
  ellipse (posX, posY, 10, 10);


  if (posY > height) {
    speedY = -random(1,4);
    posY = height;
  }
  if (posY < 0) {
    speedY = 3;
    posY = 0;
  }
  if (posX > width) {
    speedX = -random(1,4);
    posX = width;
  }
   if (posX < 0) {
    speedX = -speedX;
    posX = 0;
  }

  if (posY == height) //REINICIO DE LA PELOTA
{
  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;    //REBOTE EN EL RECTANGULO
    }


  posX = posX+speedX;
  posY = posY+speedY;
}
}
void keyPressed() {   //REINICIO DE JUEGO ( APLASTANDO UNA TECLA)
  if (gameOver == true) {
    gameOver = false;
  }
}

No hay comentarios:

Publicar un comentario