} // Gå animeringen hos spelaren public Vector2 update(KeyboardState pressedKeys) { velocity.Y = 2; velocity.X = 2; #region movement // om w och eller a,d är nertryck kan man gå snett. Kan springa max agility velocity. agilityAccel är hur snabbt man kan springa till max hastigheten agility if (pressedKeys.IsKeyDown(Keys.W)) { position.Y = position.Y -= velocity.Y; } if (pressedKeys.IsKeyDown(Keys.S)) { position.Y = position.Y += velocity.Y; } if (pressedKeys.IsKeyDown(Keys.A)) { position.X = position.X -= velocity.X; } if (pressedKeys.IsKeyDown(Keys.D)) { position.X = position.X += velocity.X; } velocity.X = 0; velocity.Y = 0; #endregion #region ChangeWeaponAndKillThisInstance if (pressedKeys.Equals(Keys.D1)|| pressedKeys.Equals(Keys.D2)|| pressedKeys.Equals(Keys.D3)) { if (pressedKeys.Equals(Keys.D1)) { type = "bow"; } else if (pressedKeys.Equals(Keys.D2)) { type = "sword"; } else if (pressedKeys.Equals(Keys.D3)) { type = "staff"; } game1.changeWeapon(type, thisType); player = null; } #endregion return position; }
public void update(GameTime gametime, KeyboardState current, KeyboardState previous) { if (current.IsKeyDown(Keys.Enter) && previous.IsKeyUp(Keys.Enter)) { evaluate(information); information = ""; return; } if (!previous.Equals(current)) { for (int i = 0; i < previous.GetPressedKeys().Length; i++) { bool notPressed = false; for (int j = 0; j < current.GetPressedKeys().Length; j++) { if (current.GetPressedKeys()[j].Equals(previous.GetPressedKeys()[i])) notPressed = true; } if (!notPressed) { if (previous.GetPressedKeys()[i].Equals(Keys.Space)) information += " "; else if (previous.GetPressedKeys()[i].Equals(Keys.RightShift) || previous.GetPressedKeys()[i].Equals(Keys.LeftShift) || previous.GetPressedKeys()[i].Equals(Keys.RightAlt) || previous.GetPressedKeys()[i].Equals(Keys.LeftAlt) || previous.GetPressedKeys()[i].Equals(Keys.RightControl) || previous.GetPressedKeys()[i].Equals(Keys.LeftControl)) information += ""; else if (previous.GetPressedKeys()[i].Equals(Keys.OemComma)) information += ","; else if (previous.GetPressedKeys()[i].Equals(Keys.OemPeriod)) information += "."; else if (previous.GetPressedKeys()[i].Equals(Keys.OemQuestion)) information += "?"; else if (previous.GetPressedKeys()[i].Equals(Keys.OemMinus)) information += "-"; else if (previous.GetPressedKeys()[i].Equals(Keys.Back)) { if (information.Length > 0) information = information.Substring(0, information.Length - 1); } else if (previous.GetPressedKeys()[i].CompareTo(Keys.A) >= 0 && previous.GetPressedKeys()[i].CompareTo(Keys.Z) <= 0) { information += previous.GetPressedKeys()[i]; } else if ((previous.GetPressedKeys()[i].CompareTo(Keys.D9) <= 0 && previous.GetPressedKeys()[i].CompareTo(Keys.D0) >= 0)) { String parseD = (previous.GetPressedKeys()[i] + ""); information += parseD.Substring(1, parseD.Length - 1); ; } } } } }