public void Update(GameTime gameTime, Direction direction) { // Don't do anything if the sprite is not animating if (bAnimating) { // If there is not a currently active animation if (CurrentMoveAnimation == null) { // Make sure we have an animation associated with this sprite if (animations.Count > 0) { // Set the active animation to the first animation // associated with this sprite string[] sKeys = new string[animations.Count]; animations.Keys.CopyTo(sKeys, 0); CurrentAnimation = sKeys[0]; } else { return; } } // Run the Animation's update method CurrentMoveAnimation.Update(gameTime); Hitbox info = CurrentMoveAnimation.CurrentHitboxInfo; // Ready hitbox info // if (info != null) { hitbox = info.getHitboxRectangle(hurtbox, direction, v2Position, CurrentMoveAnimation.FrameWidth); } else { hitbox = new Rectangle(); } Hitbox hurtboxInfo = CurrentMoveAnimation.CurrentHurtboxInfo; // Set up the hurtbox for the move // if (hurtboxInfo != null) { hurtbox = hurtboxInfo.getHitboxRectangle(hurtbox, direction, v2Position, CurrentMoveAnimation.FrameWidth); } else { hurtbox = new Rectangle(); } // Calculate where our bounding box is. Calculating this every cycle hopefully doesn't add too much overhead // if (BoundingBoxHeight != null) { boundingBox.Height = boundingBoxHeight; boundingBox.Width = boundingBoxWidth; boundingBox.X = CenterX - boundingBoxWidth / 2; boundingBox.Y = (int)v2Position.Y + Height - boundingBoxHeight; } else { boundingBox = new Rectangle(); } // Check to see if there is a "followup" animation named for this animation // if (!String.IsNullOrEmpty(CurrentMoveAnimation.NextAnimation)) { // If there is, see if the currently playing animation has // completed a full animation loop // if (CurrentMoveAnimation.IsDone) { Console.WriteLine("SWITCHING TO " + CurrentMoveAnimation.NextAnimation); // If it has, set up the next animation CurrentAnimation = CurrentMoveAnimation.NextAnimation; } } } }
public void AddHurtboxInfo(int index, Hitbox hitbox) { hurtboxInfo[index] = hitbox; }
public void AddHurtbox(String moveName, int index, Hitbox hitbox) { animations[moveName].AddHurtboxInfo(index, hitbox); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { frameTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (frameTimer > frameLength) { frameTimer = 0.0f; if (mode == "player") { move = player1.Sprite.CurrentMoveAnimation; spriteAnimation = player1.Sprite.CurrentMoveAnimation; } else { move = player1.ProjectileA.CurrentProjectile; spriteAnimation = player1.ProjectileA.CurrentProjectile; } hitbox = move.CurrentHitboxInfo; hurtboxInfo = move.CurrentHurtboxInfo; // Ready hitbox info // if (hitboxType == "HURTBOX") { if (hurtboxInfo != null) { player1.Sprite.Hurtbox = hurtboxInfo.getHitboxRectangle(player1.Sprite.Hurtbox, player1.Direction, player1.Sprite.Position, player1.Sprite.CurrentMoveAnimation.FrameWidth); } else { player1.Sprite.Hurtbox = new Rectangle(100, 100, 100, 100); hurtboxInfo = new Hitbox("100", "100", "100", "100"); } } if (hitboxType == "HITBOX") { if (hitbox != null) { //player1.ProjectileStrum.Hitbox player1.Sprite.Hitbox = hitbox.getHitboxRectangle(player1.Sprite.Hitbox, player1.Direction, player1.Sprite.Position, player1.Sprite.CurrentMoveAnimation.FrameWidth); } else { player1.Sprite.Hitbox = new Rectangle(); } } // Set up the hurtbox for the move // if (lastState.IsKeyUp(Keys.Right) && Keyboard.GetState().IsKeyDown(Keys.Right)) { spriteAnimation.CurrentFrame++; } if (lastState.IsKeyUp(Keys.Left) && Keyboard.GetState().IsKeyDown(Keys.Left)) { spriteAnimation.CurrentFrame--; } if (lastState.IsKeyUp(Keys.Down) && Keyboard.GetState().IsKeyDown(Keys.Down)) { // player1.Sprite.CurrentAnimation; index--; if (index < 0) { index = 0; } player1.Sprite.CurrentAnimation = animationsList[index]; } if (lastState.IsKeyUp(Keys.Up) && Keyboard.GetState().IsKeyDown(Keys.Up)) { // player1.Sprite.CurrentAnimation; index++; if (index >= animationsList.Count) { index = animationsList.Count - 1; } player1.Sprite.CurrentAnimation = animationsList[index]; } if (hitboxType == "HURTBOX") { if (Keyboard.GetState().IsKeyDown(Keys.A)) { hurtboxInfo.XPos++; } if (Keyboard.GetState().IsKeyDown(Keys.D)) { hurtboxInfo.XPos--; } if (Keyboard.GetState().IsKeyDown(Keys.W)) { hurtboxInfo.YPos--; } if (Keyboard.GetState().IsKeyDown(Keys.S)) { hurtboxInfo.YPos++; } if (Keyboard.GetState().IsKeyDown(Keys.K)) { hurtboxInfo.Width++; } if (Keyboard.GetState().IsKeyDown(Keys.H)) { hurtboxInfo.Width--; } if (Keyboard.GetState().IsKeyDown(Keys.J)) { hurtboxInfo.Height--; } if (Keyboard.GetState().IsKeyDown(Keys.U)) { hurtboxInfo.Height++; } } else { if (Keyboard.GetState().IsKeyDown(Keys.A)) { hitbox.XPos++; } if (Keyboard.GetState().IsKeyDown(Keys.D)) { hitbox.XPos--; } if (Keyboard.GetState().IsKeyDown(Keys.W)) { hitbox.YPos--; } if (Keyboard.GetState().IsKeyDown(Keys.S)) { hitbox.YPos++; } if (Keyboard.GetState().IsKeyDown(Keys.K)) { hitbox.Width++; } if (Keyboard.GetState().IsKeyDown(Keys.H)) { hitbox.Width--; } if (Keyboard.GetState().IsKeyDown(Keys.J)) { hitbox.Height--; } if (Keyboard.GetState().IsKeyDown(Keys.U)) { hitbox.Height++; } } } lastState = Keyboard.GetState(); }