// Mario on Animated Sprites // by Robert Casey // Based on Animated Sprite (Shifty + Teddy) // by James Patterson and REAS // Press 'a' to move left // 'd' to move right // 'w' to jump // Created 06 Feb 2005 AniSprite[] mario_walking_right, mario_walking_left, mario_stopped_left, mario_stopped_right, mario_jump_left, mario_jump_right, mario_duck_right, mario_duck_left; float xpos, ypos; float jump_height = 10; float drag = 10.0; boolean face_left = false; boolean jumping_up = false; boolean jumping_down = false; boolean moving = false; boolean ducking = false; boolean[][] solid; int which_mario = 0; void setup() { size(200,200); background(255, 204, 0); solid = new boolean[width][height]; xpos = 0; ypos = height-56; framerate(15); for( int i=0; i (height-56)) solid[i][j] = true; else solid[i][j] = false; } } mario_walking_left = new AniSprite[2]; mario_walking_right = new AniSprite[2]; mario_stopped_left = new AniSprite[2]; mario_stopped_right = new AniSprite[2]; mario_jump_left = new AniSprite[2]; mario_jump_right = new AniSprite[2]; mario_duck_left = new AniSprite[2]; mario_duck_right = new AniSprite[2]; mario_walking_left[0] = new AniSprite("mario_walking", 2, true); mario_walking_right[0] = new AniSprite("mario_walking", 2); mario_stopped_left[0] = new AniSprite("mario_standing", 1, true); mario_stopped_right[0] = new AniSprite("mario_standing", 1); mario_jump_left[0] = new AniSprite("mario_jumping", 1, true); mario_jump_right[0] = new AniSprite("mario_jumping", 1); mario_duck_left[0] = new AniSprite("mario_ducking", 1, true); mario_duck_right[0] = new AniSprite("mario_ducking", 1); mario_walking_left[1] = new AniSprite("smario_walking", 2, true); mario_walking_right[1] = new AniSprite("smario_walking", 2); mario_stopped_left[1] = new AniSprite("smario_standing", 1, true); mario_stopped_right[1] = new AniSprite("smario_standing", 1); mario_jump_left[1] = new AniSprite("smario_jumping", 1, true); mario_jump_right[1] = new AniSprite("smario_jumping", 1); mario_duck_left[1] = new AniSprite("smario_ducking", 1, true); mario_duck_right[1] = new AniSprite("smario_ducking", 1); } void loop() { if( keyPressed ){ if( key == 'a' && accessible(xpos-3,ypos) ){ if( xpos > 0 ) xpos = xpos - 3; moving = true; face_left = true; } else if( key == 'd' && accessible(xpos+3,ypos) ){ if( xpos < (width-20) ) xpos = xpos + 3; moving = true; face_left = false; } else if( key == 'w' ){ if( jumping_down == false && is_solid(xpos,ypos+2) ) jumping_up = true; } else if( key == 's' ){ ducking = true; } else if( key == 'q' ){ which_mario = 0; } else if( key == 'e' ){ which_mario = 1; } } else{ moving=false; ducking=false; } if( jumping_up == true ){ if( jump_height > 0 ){ ypos -= 2; jump_height--; } else{ // jumping_down = true; jumping_up = false; jumping_down = false; jump_height = 10; } } else if( is_solid(xpos, ypos+2) == false ) ypos+=2; /* else if( jumping_down == true ){ if( jump_height < 10 ){ ypos += 1; jump_height++; } else{ jumping_down = false; } } */ background(153, 153, 0); if( face_left ){ if( jumping_up || jumping_down ) mario_jump_left[which_mario].display(xpos, ypos); else if( moving ) mario_walking_left[which_mario].display( xpos, ypos ); else if( ducking ) mario_duck_left[which_mario].display( xpos, ypos ); else mario_stopped_left[which_mario].display(xpos, ypos); } else{ if( jumping_up || jumping_down ) mario_jump_right[which_mario].display(xpos, ypos); else if( moving ) mario_walking_right[which_mario].display( xpos, ypos ); else if( ducking ) mario_duck_right[which_mario].display( xpos, ypos ); else mario_stopped_right[which_mario].display(xpos, ypos); } rect(0,height-25, width/2, height); } boolean is_valid( float x, float y ){ return( x>=0 && x=0 && y