private void GetHurt(GameTime gameTime) { position.Y = startYPosition; if (oldState != MoveState.Hurt) { currentFrame = hurtStartFrame; } animationTimer += gameTime.ElapsedGameTime.Milliseconds; if (animationTimer > hurtPerFrame) { animationTimer = 0; currentFrame++; } if (currentFrame > hurtEndFrame) { currentFrame = idleStartFrame; moveState = MoveState.Stand; oldKeysCombo = KeysCombo.None; } oldState = moveState; }
private void PickState(GameTime gameTime) { keysCombo = control.KeysDown(gameTime); if ((moveState != MoveState.Jump) && (moveState != MoveState.Cast)) { switch (keysCombo) { case KeysCombo.RightArrow: if (oldKeysCombo != KeysCombo.RightArrow) { currentFrame = walkRightStartFrame; } animationTimer += gameTime.ElapsedGameTime.Milliseconds; if (animationTimer > walkPerFrame) { animationTimer = 0; if ((position.X + charWidth) < screenWidth && !isWizMonColl) { position.X += walkSpeed; } currentFrame++; if (currentFrame > walkRightEndFrame) { currentFrame = walkRightStartFrame; } } break; case KeysCombo.LeftArrow: if (oldKeysCombo != KeysCombo.LeftArrow) { currentFrame = walkLeftStartFrame; } animationTimer += gameTime.ElapsedGameTime.Milliseconds; if (animationTimer > walkPerFrame) { animationTimer = 0; if (position.X > 0) { position.X -= walkSpeed; } currentFrame++; if (currentFrame > walkLeftEndFrame) { currentFrame = walkLeftStartFrame; } } break; case KeysCombo.UpArrow: currentFrame = jumpRightStartFrame; moveState = MoveState.Jump; posYModifier = basicPosMofifier; jumpMovement = 0; break; case KeysCombo.UpRightArrows: currentFrame = jumpRightStartFrame; moveState = MoveState.Jump; posYModifier = basicPosMofifier; jumpMovement = 10; break; case KeysCombo.UpLeftArrows: currentFrame = jumpLeftStartFrame; moveState = MoveState.Jump; posYModifier = basicPosMofifier; jumpMovement = -10; break; case KeysCombo.W: if (spellParams["lighting"].SpellCost <= mana) { currentFrame = castingStartFrame; moveState = MoveState.Cast; castMagicFrame = 110; castStartXPosition = position.X + castWidth / 4 * 3; castStartYPosition = position.Y - 100; mana -= spellParams["lighting"].SpellCost; spells.Add(new CharacterSpell("lighting", spellParams["lighting"].SpellPower, spellsTextures[0], castStartXPosition, castStartYPosition, gameTime, 0, 9, 4, 3, 30, 20)); } else { noMana = true; } break; case KeysCombo.A: if (spellParams["water"].SpellCost <= mana) { currentFrame = castingStartFrame; moveState = MoveState.Cast; castMagicFrame = 110; castStartXPosition = position.X + castWidth / 4 * 3; castStartYPosition = position.Y; mana -= spellParams["water"].SpellCost; spells.Add(new CharacterSpell("water", spellParams["water"].SpellPower, spellsTextures[1], castStartXPosition, castStartYPosition, gameTime, 5, 12, 5, 5, 30, 20)); } else { noMana = true; } break; case KeysCombo.S: if (spellParams["gravity"].SpellCost <= mana) { currentFrame = castingStartFrame; moveState = MoveState.Cast; castMagicFrame = 110; castStartXPosition = position.X + castWidth / 4 * 3; castStartYPosition = position.Y; mana -= spellParams["gravity"].SpellCost; spells.Add(new CharacterSpell("gravity", spellParams["gravity"].SpellPower, spellsTextures[2], castStartXPosition, castStartYPosition, gameTime, 4, 10, 5, 4, 30, 20)); } else { noMana = true; } break; case KeysCombo.D: if (spellParams["shield"].SpellCost <= mana) { currentFrame = castingStartFrame; moveState = MoveState.Cast; castMagicFrame = 110; castStartXPosition = position.X; castStartYPosition = position.Y; mana -= spellParams["shield"].SpellCost; spells.Add(new CharacterSpell("shield", spellParams["shield"].SpellPower, spellsTextures[3], castStartXPosition, castStartYPosition, gameTime, 0, 0, 1, 1, 30, 0)); } else { noMana = true; } break; case KeysCombo.DownLeftX: if (spellParams["special"].SpellCost <= mana && specialAbilityLeft) { currentFrame = castingStartFrame; moveState = MoveState.Cast; castMagicFrame = 110; castStartXPosition = position.X + 50; castStartYPosition = position.Y - 150; mana -= spellParams["special"].SpellCost; specialAbilityLeft = false; spells.Add(new CharacterSpell("special", spellParams["special"].SpellPower, spellsTextures[4], castStartXPosition, castStartYPosition, gameTime, 0, 15, 6, 6, 5, 30)); } else { noMana = true; } break; default: animationTimer += gameTime.ElapsedGameTime.Milliseconds; if (animationTimer > idlePerFrame) { animationTimer = 0; currentFrame++; if (currentFrame > idleEndFrame) { currentFrame = idleStartFrame; } } break; } oldKeysCombo = keysCombo; } // condition to continue idle when the cast button is pressed, but the wizard has not enough mana if (noMana) { animationTimer += gameTime.ElapsedGameTime.Milliseconds; if (animationTimer > idlePerFrame) { animationTimer = 0; currentFrame++; if (currentFrame > idleEndFrame) { currentFrame = idleStartFrame; } } noMana = false; } // perform additional action switch (moveState) { case MoveState.Jump: Jump(gameTime); break; case MoveState.Cast: Cast(gameTime); break; default: break; } }