private void HandleInputs() { double left = input.left(); double right = input.right(); bool gotDirInput = false; if (!punch.IsActive()) { //Move left if left is pressed if (left > 0) { Vel = new Vector2((float)(-speed * left), Vel.Y); gotDirInput = true; flip = true; } //Move right if right is pressed else if (right > 0) { Vel = new Vector2((float)(speed * right), Vel.Y); gotDirInput = true; flip = false; } //Jump if up is pressed if ((input.up() > .999 || input.select()) && Vel.Y == 0) { Vel = new Vector2(Vel.X, -speed * 5); } } //If no directional input, reset X velocity. if (!gotDirInput) { Vel = new Vector2(0, Vel.Y); } if (gettingPunched && recoilAnim.Looped) { idleAnim.Reset(); gettingPunched = false; } else if (punching && punchAnim.Looped) { idleAnim.Reset(); punching = false; if (flip) { SetPos(new Vector2(Pos.X + punchAnim.GetWidth() - idleAnim.GetWidth(), Pos.Y)); } } //Punch if punch key is pressed if (input.punch() && !punching) { punch.Trigger(); punchAnim.Reset(); punching = true; if (flip) { SetPos(new Vector2(Pos.X - punchAnim.GetWidth() + idleAnim.GetWidth(), Pos.Y)); } } }
public override void Draw(SpriteBatch batch) { anim.UpdateTime(new GameTime(new TimeSpan(), new TimeSpan(0, 0, 0, 0, 1000 / 30))); batch.Draw(tex, new Rectangle(x, y, SIZE, SIZE), Color.White); batch.Draw(anim.GetSheet(), new Rectangle(x + PADDING, y + PADDING, (int)((float)anim.GetWidth() / anim.GetHeight() * (SIZE - 2 * PADDING)), SIZE - 2 * PADDING), anim.GetWindow(), Color.White); }