Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final int PARADO = 0;
- final int ANDANDO = 1;
- final int PARADODIREITA = 2;
- final int ANDANDODIREITA = 3;
- int xPos = 250;
- int estadoMario = PARADO;
- int contagem = 0;
- PImage parado;
- PImage andando;
- PImage parado2;
- PImage andando2;
- boolean move = false;
- void setup() {
- size(800, 800);
- parado = loadImage("parado.png");
- andando = loadImage("correndo.png");
- parado2 = loadImage("parado2.png");
- andando2 = loadImage("correndo2.png");
- }
- void mostraMario(int estado, int posMario){
- //if (estado == ANDANDO){
- // if(frameCount % 30 > 15){
- // image(andando, width/2 - andando.width/2, height/2 - andando.height/2);
- // }else{
- // image(parado, width/2 - parado.width/2, height/2 - parado.height/2);
- // estadoMario = PARADO;
- // }
- //}else{
- // image(parado, width/2 - parado.width/2, height/2 - parado.height/2);
- //}
- switch(estado){
- case PARADO:
- image(parado, posMario, height/2 - parado.height/2);
- break;
- case ANDANDO:
- if(frameCount % 30 > 15){
- image(andando, posMario, height/2 - andando.height/2);
- }else{
- image(parado, posMario, height/2 - parado.height/2);
- estadoMario = PARADO;
- }
- break;
- case PARADODIREITA:
- image(parado2, posMario, height/2 - parado.height/2);
- break;
- case ANDANDODIREITA:
- if(frameCount % 30 > 15){
- image(andando2, posMario, height/2 - andando.height/2);
- }else{
- image(parado2, posMario, height/2 - parado.height/2);
- estadoMario = PARADODIREITA;
- }
- break;
- }
- }
- void keyReleased(){
- contagem = 0;
- }
- void contadorDeMovimento(){
- if(contagem > 60){
- contagem = 0;
- }else{
- contagem++;
- }
- }
- void draw() {
- background(0);
- if((keyPressed==true)&&(keyCode==LEFT)){
- xPos -= 2;
- estadoMario=ANDANDO;
- }
- if((keyPressed==true)&&(keyCode==RIGHT)){
- xPos += 2;
- estadoMario=ANDANDODIREITA;
- }
- contadorDeMovimento();
- mostraMario(estadoMario, xPos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement