static void RespondToJoystickEvents(RectangleShape player) { buttonText.DisplayedString = XboxController.RefreshButtonPressed(); axisText.DisplayedString = XboxController.RefreshAxisPressed(); if (JoyState.HasFlag(ControllerState.DPAD_UP_PRESSED)) { player.Position = new Vector2f(player.Position.X, player.Position.Y - 1); } if (JoyState.HasFlag(ControllerState.DPAD_DOWN_PRESSED)) { player.Position = new Vector2f(player.Position.X, player.Position.Y + 1); } if (JoyState.HasFlag(ControllerState.DPAD_LEFT_PRESSED)) { player.Position = new Vector2f(player.Position.X - 1, player.Position.Y); } if (JoyState.HasFlag(ControllerState.DPAD_RIGHT_PRESSED)) { player.Position = new Vector2f(player.Position.X + 1, player.Position.Y); } if (JoyState.HasFlag(ControllerState.B_PRESSED)) { player.Position = RespawnCentreScreen(); } }
static void Main(string[] args) { RenderWindow app = new RenderWindow(new VideoMode(800, 600), "OMG, it works!"); app.Closed += new EventHandler(OnClose); Color windowColor = new Color(77, 255, 130); CircleShape shape = new CircleShape(10); shape.FillColor = new Color(Color.Red); RectangleShape square = new RectangleShape(); square.FillColor = new Color(Color.Red); square.Position = new Vector2f(app.Size.X / 2, app.Size.Y / 2); square.OutlineColor = new Color(0, 0, 0, 255); square.Size = new Vector2f(50, 50); // Start the game loop while (app.IsOpen()) { // Process events app.DispatchEvents(); // Clear screen app.Clear(windowColor); app.Draw(shape); app.Draw(square); Console.WriteLine(XboxController.RefreshButtonPressed()); Console.WriteLine(XboxController.RefreshAxisPressed()); if (JoyState.HasFlag(ControllerState.DPAD_UP_PRESSED)) { square.Position = new Vector2f(square.Position.X, square.Position.Y - 1); } if (JoyState.HasFlag(ControllerState.DPAD_DOWN_PRESSED)) { square.Position = new Vector2f(square.Position.X, square.Position.Y + 1); } if (JoyState.HasFlag(ControllerState.DPAD_LEFT_PRESSED)) { square.Position = new Vector2f(square.Position.X - 1, square.Position.Y); } if (JoyState.HasFlag(ControllerState.DPAD_RIGHT_PRESSED)) { square.Position = new Vector2f(square.Position.X + 1, square.Position.Y); } // Update the window app.Display(); } }
static void Main(string[] args) { GameApp = new RenderWindow(new VideoMode(ScreenWidth, ScreenHeight), "Display Sprites"); GameApp.Closed += new EventHandler(OnClose); Color windowColor = new Color(0, 192, 255); SetupFont(); SetupPlayerSprite(); SetupBombSprite(); SetupAppleSprite(); SetupGameText(); // quick alias var app = GameApp; // Start the game loop while (app.IsOpen()) { // Process events app.DispatchEvents(); // Clear screen app.Clear(windowColor); BombSprite.Position = GameUtils.RandomlyMovePosition(BombSprite.Position, app.Size); buttonText.DisplayedString = XboxController.RefreshButtonPressed(); axisText.DisplayedString = XboxController.RefreshAxisPressed(); PlayerSprite.Position = RespondToJoystickEvents(PlayerSprite.Position); if (IsPlayerOverFood(PlayerSprite.GetGlobalBounds(), AppleSprite.GetGlobalBounds()) == true) { // Respawn food and increase health! AppleSprite.Position = RespawnRandomLocation(); foodCountText.DisplayedString = string.Format("Food: {0}", ++foodCount); } if (IsPlayerOverEnemy(PlayerSprite.GetGlobalBounds(), BombSprite.GetGlobalBounds()) == true) { PlayerSprite.Position = RespawnTopLeftScreen(); killCountext.DisplayedString = string.Format("Killed: {0}", ++killCount); } app.Draw(headerText); app.Draw(buttonText); app.Draw(axisText); app.Draw(foodCountText); app.Draw(killCountext); app.Draw(PlayerSprite); app.Draw(BombSprite); app.Draw(AppleSprite); // Update the window app.Display(); } }
private static void JoystickEvents() { buttonText.DisplayedString = XboxController.RefreshButtonPressed(); axisText.DisplayedString = XboxController.RefreshAxisPressed(); var obj = GameManager.GetPlayerObject(); var playerSprite = (Sprite)obj.GameObj; playerSprite.Position = RespondToJoystickEvents(playerSprite.Position); }