// Draw shaky gahame text public static void DrawShakingText(SpriteBatch spriteBatch, GameFont font, string text, Vector2 pos, float intensity, Color c) { // the offset for each char Vector2 offset = new Vector2(0, 0); text = Gahamefy(text); // draw each char for (int i = 0; i < text.Length; i++) { Vector2 shake = new Vector2(MyMaths.RandomInRange(-intensity, intensity), MyMaths.RandomInRange(-intensity, intensity)); string textToDraw; if (IsCons(text[i])) { if (i != text.Length - 1) { if (IsVowel(text[i + 1])) { textToDraw = "" + text[i] + text[i + 1]; i++; } else { textToDraw = "" + text[i]; } } else { textToDraw = "" + text[i]; } } else { textToDraw = "" + text[i]; } font.DrawString(spriteBatch, textToDraw, pos + offset + shake, c); offset.X += font.MeasureString(textToDraw).X; if (text[i] == '\n') { offset.X = 0; offset.Y += font.LineSpacing; } } }
// Draw shaky text public static void DrawShakingText(SpriteBatch spriteBatch, SpriteFont font, string text, Vector2 pos, float intensity, Color c) { // the offset for each char Vector2 offset = new Vector2(0, 0); // draw each char for (int i = 0; i < text.Length; i++) { Vector2 shake = new Vector2(MyMaths.RandomInRange(-intensity, intensity), MyMaths.RandomInRange(-intensity, intensity)); spriteBatch.DrawString(font, "" + text[i], pos + offset + shake, c); offset.X += font.MeasureString("" + text[i]).X; if (text[i] == '\n') { offset.X = 0; offset.Y += font.LineSpacing; } } }
// Checks all of the controlls (should happen in Game class) public static void Update() { keyboardState = Keyboard.GetState(); gamePadState = GamePad.GetState(0); // Check is keyboard mode or controller mode if (gamePadState.IsConnected) { // Get buttons pressed bool keyboardButtonPressed = keyboardState.GetPressedKeys().Length > 0; GamePadState emptyInput = new GamePadState(Vector2.Zero, Vector2.Zero, 0, 0, 0); // checks the keyboard and controller buttons if (gamePadState != emptyInput && !keyboardButtonPressed) { ControllerMode = true; } else if (keyboardButtonPressed) { ControllerMode = false; } } else { ControllerMode = false; } // Abs left controller stick on X axis AbsLeftStickX = Math.Min(Math.Abs(gamePadState.ThumbSticks.Left.X) + .05f, 1); // Abs left controller stick on Y axis AbsLeftStickY = Math.Min(Math.Abs(gamePadState.ThumbSticks.Left.Y) + .05f, 1); // left controller stick on X axis LeftStickX = MyMaths.Clamp(gamePadState.ThumbSticks.Left.X + Math.Sign(gamePadState.ThumbSticks.Left.X) * .05f, -1, 1); // Left controller stick on Y axis LeftStickY = -MyMaths.Clamp(gamePadState.ThumbSticks.Left.Y + Math.Sign(gamePadState.ThumbSticks.Left.Y) * .05f, -1, 1); // stick controlls PlatformerMovementStickX = MyMaths.Clamp(gamePadState.ThumbSticks.Left.X + Math.Sign(gamePadState.ThumbSticks.Left.X) * .05f, -1, 1); PlatformerMovementStickY = MyMaths.Clamp(gamePadState.ThumbSticks.Left.Y + Math.Sign(gamePadState.ThumbSticks.Left.Y) * .05f, -1, 1); if (Math.Abs(PlatformerMovementStickX) < .40f) { PlatformerMovementStickX = 0; } if (Math.Abs(PlatformerMovementStickY) < .40f) { PlatformerMovementStickY = 0; } shootStickX = gamePadState.ThumbSticks.Left.X; shootStickY = gamePadState.ThumbSticks.Left.Y; if (Math.Abs(shootStickX) < 1 / (2 * Math.Sqrt(2))) { shootStickX = 0; } if (Math.Abs(shootStickY) < 1 / (2 * Math.Sqrt(2))) { shootStickY = 0; } Right = keyboardState.IsKeyDown(RightKey) || gamePadState.ThumbSticks.Left.X > stickDeadZone; Left = keyboardState.IsKeyDown(LeftKey) || gamePadState.ThumbSticks.Left.X < -stickDeadZone; Up = keyboardState.IsKeyDown(UpKey) || gamePadState.ThumbSticks.Left.Y > stickDeadZone; Down = keyboardState.IsKeyDown(DownKey) || gamePadState.ThumbSticks.Left.Y < -stickDeadZone; RightPressed = (keyboardState.IsKeyDown(RightKey) && !previousKeyboardState.IsKeyDown(RightKey)) || (gamePadState.ThumbSticks.Left.X > stickDeadZone && !(previousGamePadState.ThumbSticks.Left.X > stickDeadZone)); LeftPressed = (keyboardState.IsKeyDown(LeftKey) && !previousKeyboardState.IsKeyDown(LeftKey)) || (gamePadState.ThumbSticks.Left.X < -stickDeadZone && !(previousGamePadState.ThumbSticks.Left.X < -stickDeadZone)); UpPressed = (keyboardState.IsKeyDown(UpKey) && !previousKeyboardState.IsKeyDown(UpKey)) || (gamePadState.ThumbSticks.Left.Y > stickDeadZone && !(previousGamePadState.ThumbSticks.Left.Y > stickDeadZone)); DownPressed = (keyboardState.IsKeyDown(DownKey) && !previousKeyboardState.IsKeyDown(DownKey)) || (gamePadState.ThumbSticks.Left.Y < -stickDeadZone && !(previousGamePadState.ThumbSticks.Left.Y < -stickDeadZone)); Jump = (keyboardState.IsKeyDown(Keys.Space) && !previousKeyboardState.IsKeyDown(Keys.Space)) || (gamePadState.IsButtonDown(Buttons.A) && !previousGamePadState.IsButtonDown(Buttons.A)); JumpHeld = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A); ActivateHeld = keyboardState.IsKeyDown(Keys.E) || gamePadState.IsButtonDown(Buttons.B); Activate = (keyboardState.IsKeyDown(Keys.E) && !previousKeyboardState.IsKeyDown(Keys.E)) || (gamePadState.IsButtonDown(Buttons.B) && !previousGamePadState.IsButtonDown(Buttons.B)); Esc = (keyboardState.IsKeyDown(Keys.Escape) && !previousKeyboardState.IsKeyDown(Keys.Escape)) || (gamePadState.IsButtonDown(Buttons.Start) && !previousGamePadState.IsButtonDown(Buttons.Start)); EscHeld = (keyboardState.IsKeyDown(Keys.Escape) || gamePadState.IsButtonDown(Buttons.Start)); Enter = keyboardState.IsKeyDown(Keys.Enter) && !previousKeyboardState.IsKeyDown(Keys.Enter) || (gamePadState.IsButtonDown(Buttons.Back) && !previousGamePadState.IsButtonDown(Buttons.Back)); Delete = keyboardState.IsKeyDown(Keys.Delete); DeletePressed = Delete && !previousKeyboardState.IsKeyDown(Keys.Delete); F5 = keyboardState.IsKeyDown(Keys.F5) && !previousKeyboardState.IsKeyDown(Keys.F5); F6 = keyboardState.IsKeyDown(Keys.F6) && !previousKeyboardState.IsKeyDown(Keys.F6); Shift = keyboardState.IsKeyDown(Keys.LeftShift); RightCD = Right && !GahameController.CutScene; LeftCD = Left && !GahameController.CutScene; UpCD = Up && !GahameController.CutScene; DownCD = Down && !GahameController.CutScene; JumpCD = Jump && !GahameController.CutScene; ActivateCD = Activate && !GahameController.CutScene; }