public void Initialize(int sprite_width, int sprite_height, ContentManager Content, int initial_x, int initial_y) { //Load Testures Texture2D player_run = Content.Load<Texture2D>("playerrun"); Texture2D player_sprint = Content.Load<Texture2D>("playersprint"); Texture2D player_idle = Content.Load<Texture2D>("playeridle"); Texture2D player_jump = Content.Load<Texture2D>("playerjump"); Texture2D player_turn = Content.Load<Texture2D>("playerturn"); Texture2D player_fall = Content.Load<Texture2D>("playerfall"); Texture2D player_spin = Content.Load<Texture2D>("playerspin"); position.X = initial_x; position.Y = initial_y; spriteHeight = sprite_height; spriteWidth = sprite_width; collisionColor = new Color[1]; rectangle = new Rectangle((int)position.X, (int)position.Y, spriteWidth, spriteHeight); //Set up the animation idleAnimation = new Animation(); runAnimation = new Animation(); sprintAnimation = new Animation(); jumpAnimation = new Animation(); turnAnimation = new Animation(); fallAnimation = new Animation(); spinAnimation = new Animation(); animation = new Animation(); idleAnimation.Initialize(player_idle, position, spriteWidth, spriteHeight, 0, 5, animSpeed*2, Color.White, 1, true); runAnimation.Initialize(player_run, position, spriteWidth, spriteHeight, 6, 13, animSpeed, Color.White, 1, true); sprintAnimation.Initialize(player_sprint, position, spriteWidth, spriteHeight, 0, 7, animSpeed, Color.White, 1, true); jumpAnimation.Initialize(player_jump, position, spriteWidth, spriteHeight, 0, 3, 3*animSpeed, Color.White, 1, false); turnAnimation.Initialize(player_turn, position, spriteWidth, spriteHeight, 0, 0, animSpeed, Color.White, 1, false); fallAnimation.Initialize(player_fall, position, spriteWidth, spriteHeight, 0, 1, 3*animSpeed, Color.White, 1, false); spinAnimation.Initialize(player_spin, position, spriteWidth, spriteHeight, 0, 6, animSpeed/2, Color.White, 1, true); animation = idleAnimation;//By default oldstate = new KeyboardState(); }
void choose_animation(int level) { if (!inAir) { if (speedX != 0) { if (speedX * direction < 0)//They are decellerating { animation = turnAnimation; } else if (burstMode && level != 0)//Don't start burst mode if you are at level 0. { animation = sprintAnimation; } else { animation = runAnimation; } } else { animation = idleAnimation; } } else { if (speedY > 0) { animation = jumpAnimation; } else if(!burstMode) { animation = fallAnimation; } if (spinning) { animation = spinAnimation; } } }