public void Update(KeyboardState input, GamePadState padState, GameTime gameTime)
{
//Update move animation, this will have to be separated into Roth and Bat as Bat doesn't stop moving her wings when still.
if (idles)
{
next();
}
if (!active)
{
return;
}
//debug stuff goes here
if ((input.IsKeyDown(Keys.Q)))
{
this.bounce = !this.bounce;
}
if (blinkBlocked)
{
if ((float)gameTime.TotalGameTime.TotalSeconds - blockTime > DEATHTIMER)
{
blinkBlocked = false;
}
}
if (blinked)
{
if (velocity.X != 0 && atRest)
{
dustTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
if (dustTimer < 0)
{
Animation poof = new Animation(dustEffect, new Vector2(playerRect.X - 30, playerRect.Y + playerRect.Height - 16), 20f, 6, aniList, directionFacing);
dustTimer = TRAILTIMER;
}
}
if (deathTimer < -1)
{
blinkJuice -= (float)gameTime.ElapsedGameTime.TotalSeconds;
if (blinkJuice <= 0)
{
blinkJuice = 0;
Boolean blocked = inPlayer();
if (!blocked)
{
blocked = inWall();
}
if (!blocked)
{
blinked = false;
curMultiplier = 1f;
Unblink_Sound.Play();
blinkCoolDown = BLINKCOOL;
stunTimer = STUNTIME;
deathTimer = -2;
}
else
{
deathTimer = DEATHTIMER;
}
}
}
else
{
deathTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
if (deathTimer <= 0)
{
setDead(true, null, "EXPIRE");
blinked = false;
Unblink_Sound.Play();
curMultiplier = 1f;
}
}
}
else
{
if (blinkJuice < MAXBLINKJUICE)
{
blinkJuice += (float)gameTime.ElapsedGameTime.TotalSeconds;
if (blinkJuice > MAXBLINKJUICE)
{
blinkJuice = MAXBLINKJUICE;
}
}
}
if (blinkCoolDown > 0)
{
blinkCoolDown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
}
if (stunTimer > 0)
{
stunTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
}
//Blink
if ((input.IsKeyDown(Keys.LeftAlt) || padState.IsButtonDown(Buttons.LeftShoulder)) && !blinkKeyDown && !blinkBlocked)
{
blink();
}
else if (blinkKeyDown && (input.IsKeyUp(Keys.LeftAlt) && padState.IsButtonUp(Buttons.LeftShoulder)))
{
blinkKeyDown = false;
}
// Use Powerup
if (inventory != PowerupEnum.none && (padState.IsButtonDown(Buttons.Y) || input.IsKeyDown(Keys.C)) && !dead)
{
//Use powerup here !
switch (inventory)
{
case PowerupEnum.spearCatch:
spearCatch = true;
break;
case PowerupEnum.shield:
shield = true;
break;
case PowerupEnum.bombSpear:
//not fully
bombSpear = true;
break;
case PowerupEnum.backupSpear:
backupSpear = true;
break;
case PowerupEnum.unblinker:
unblinkEveryone((float)gameTime.TotalGameTime.TotalSeconds);
break;
}
inventory = PowerupEnum.none;
}
//Implicit Aim
if (padState.ThumbSticks.Left.Length() > 0.85f)
{
spearVector = padState.ThumbSticks.Left;
}
bool moveEnd = moving;
moving = false;
//Are we aiming?
if ((!(padState.IsButtonDown(Buttons.B)) && !(padState.IsButtonDown(Buttons.X))) || !hasSpear)
{
//Horizontal movement
if ((input.IsKeyDown(Keys.Right) || padState.IsButtonDown(Buttons.LeftThumbstickRight)) && !dead && !victory && stunTimer <= 0)
{
next();
moving = true;
if (velocity.X < ACC_CAP * curMultiplier)
{
velocity.X += SPEED * curMultiplier;
if (velocity.X < -SPEED)
{
velocity.X += SPEED * curMultiplier / 2;
}
}
}
else if ((input.IsKeyDown(Keys.Left) || padState.IsButtonDown(Buttons.LeftThumbstickLeft)) && !dead && !victory && stunTimer <= 0)
{
next();
moving = true;
if (velocity.X > -ACC_CAP * curMultiplier)
{
velocity.X -= SPEED * curMultiplier;
if (velocity.X > SPEED)
{
velocity.X -= SPEED * curMultiplier / 2;
}
}
}
if (moveEnd && !moving)
{
curFrame = 0;
nextFrame = frameLength;
}
//Initiating a melee attack!
if (attackKeyDown && spear != null)
{
spear.isInUse = true;
//animate attack
attackFrameWait = attackAnimationFrames;
attackType = 0;
attackKeyDown = false;
}
//Initiating a thrown attack!
else if (throwKeyDown && spear != null)
{
throwKeyDown = false;
spear.setThrownBy(this);
spear.throwSpear();
}
}
else
{
if (padState.IsButtonDown(Buttons.B))
{
attackKeyDown = true;
}
if (padState.IsButtonDown(Buttons.X))
{
throwKeyDown = true;
}
if (padState.ThumbSticks.Left.Length() > 0.85f)
{
directionFacing = VectorMath.rotationFromVector(spearVector) > Math.PI || VectorMath.rotationFromVector(spearVector) < 0 ? 0 : 1;
}
}
//Friction
if (velocity.X != 0 && !padState.IsButtonDown(Buttons.LeftThumbstickRight) && !padState.IsButtonDown(Buttons.LeftThumbstickLeft) && !input.IsKeyDown(Keys.Left) && !input.IsKeyDown(Keys.Right))
{
float fric = curFriction;
if (!atRest)
{
fric = airFriction;
}
if (velocity.X < 0)
{
if (velocity.X > -fric)
{
velocity.X = 0;
}
else
{
velocity.X += fric;
}
}
else
{
if (velocity.X < fric)
{
velocity.X = 0;
}
else
{
velocity.X -= fric;
}
}
}
if (victory)
{
if (atRest && !dead)
{
velocity.Y -= (JUMP / 2);
atRest = false;
}
}
else
{
//Jump
if ((input.IsKeyDown(Keys.LeftControl) || padState.IsButtonDown(Buttons.A) || bounce) && atRest && !dead && stunTimer <= 0)
{
velocity.Y -= JUMP * curMultiplier;
atRest = false;
Jump_Sound.Play();
}
}
//Velocity applications
int footing = arena.checkFooting(new Vector2(playerRect.X, playerRect.Y));
if ((atRest && footing < 10) || (atRest && footing >= 20 && blinked))
{
atRest = false;
}
if (footing == 11 || footing == 21)
{
curFriction = iceFriction;
SPEED = ICESPEED;
}
else
{
curFriction = groundFriction;
SPEED = GROUNDSPEED;
}
applyMove(velocity.X < 0, velocity.Y < 0);
//Is there an attack animation in progress?
if (attackFrameWait > 0)
{
//Melee?
if (attackType == 0 && spear != null)
{
spear.meleeCheck(attackFrameWait);
}
attackFrameWait--;
}
else
if (spear != null && spear.isInUse)
{
spear.isInUse = false;
}
blockDataUpdate();
// Look for power up
if (inventory == PowerupEnum.none)
{
inventory = arena.checkPowerup(playerRect);
}
arena.updatePowerup(gameTime);
//give spear if not holding one and player has backupspear effect
if (backupSpear && !hasSpear)
{
backupSpear = false;
SpearClass s = new SpearClass(this, StateGame.spearSprite, SCREENSIZE, arena, players);
s.Throw_Sound = StateGame.Throw_Sound.CreateInstance();
s.Hit_Player_Sound = StateGame.Hit_Player_Sound.CreateInstance();
s.Hit_Wall_Sound = StateGame.Hit_Wall_Sound.CreateInstance();
s.Stab_Sound = StateGame.Stab_Sound.CreateInstance();
StateGame.spears.Add(s);
}
//Gravity
if (!atRest && velocity.Y < TERMINAL_V)
{
velocity.Y += GRAVITY;
}
//Check whether player is moving left/right
if (velocity.X > 0)
{
directionFacing = 1;
}
else if (velocity.X < 0)
{
directionFacing = 0;
}
}