Advertisement
bethdps

Mario

Oct 17th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. final int PARADO = 0;
  2. final int ANDANDO = 1;
  3. final int PARADODIREITA = 2;
  4. final int ANDANDODIREITA = 3;
  5.  
  6. int xPos = 250;
  7. int estadoMario = PARADO;
  8. int contagem = 0;
  9.  
  10. PImage parado;
  11. PImage andando;
  12. PImage parado2;
  13. PImage andando2;
  14. boolean move = false;
  15.  
  16. void setup() {
  17.   size(800, 800);
  18.   parado = loadImage("parado.png");
  19.   andando = loadImage("correndo.png");
  20.   parado2 = loadImage("parado2.png");
  21.   andando2 = loadImage("correndo2.png");
  22. }
  23.  
  24. void mostraMario(int estado, int posMario){
  25.  //if (estado == ANDANDO){
  26.  //  if(frameCount % 30 > 15){
  27.  //    image(andando, width/2 - andando.width/2, height/2 - andando.height/2);
  28.  //  }else{
  29.  //    image(parado, width/2 - parado.width/2, height/2 - parado.height/2);
  30.  //    estadoMario = PARADO;
  31.  //  }
  32.  //}else{
  33.  //  image(parado, width/2 - parado.width/2, height/2 - parado.height/2);
  34.  //}
  35.  switch(estado){
  36.    case PARADO:
  37.      image(parado, posMario, height/2 - parado.height/2);
  38.      break;
  39.    case ANDANDO:
  40.      if(frameCount % 30 > 15){
  41.      image(andando, posMario, height/2 - andando.height/2);
  42.    }else{
  43.      image(parado, posMario, height/2 - parado.height/2);
  44.      estadoMario = PARADO;
  45.    }
  46.    break;
  47.    case PARADODIREITA:
  48.      image(parado2, posMario, height/2 - parado.height/2);
  49.      break;
  50.    case ANDANDODIREITA:
  51.      if(frameCount % 30 > 15){
  52.        image(andando2, posMario, height/2 - andando.height/2);
  53.      }else{
  54.        image(parado2, posMario, height/2 - parado.height/2);
  55.        estadoMario = PARADODIREITA;
  56.      }
  57.      break;
  58.  }
  59. }
  60.  
  61. void keyReleased(){
  62.   contagem = 0;
  63. }
  64.  
  65. void contadorDeMovimento(){
  66.   if(contagem > 60){
  67.     contagem = 0;
  68.   }else{
  69.     contagem++;
  70.   }
  71. }
  72.  
  73. void draw() {
  74.   background(0);
  75.   if((keyPressed==true)&&(keyCode==LEFT)){
  76.     xPos -= 2;
  77.     estadoMario=ANDANDO;
  78.   }
  79.   if((keyPressed==true)&&(keyCode==RIGHT)){
  80.     xPos += 2;
  81.     estadoMario=ANDANDODIREITA;
  82.   }
  83.  
  84.     contadorDeMovimento();
  85.     mostraMario(estadoMario, xPos);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement