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 Vector2f RespondToJoystickEvents(Vector2f pos) { Vector2f newpos = new Vector2f(pos.X, pos.Y); if (JoyState.HasFlag(ControllerState.DPAD_UP_PRESSED)) { newpos = new Vector2f(pos.X, pos.Y - 1); } if (JoyState.HasFlag(ControllerState.DPAD_DOWN_PRESSED)) { newpos = new Vector2f(pos.X, pos.Y + 1); } if (JoyState.HasFlag(ControllerState.DPAD_LEFT_PRESSED)) { newpos = new Vector2f(pos.X - 1, pos.Y); } if (JoyState.HasFlag(ControllerState.DPAD_RIGHT_PRESSED)) { newpos = new Vector2f(pos.X + 1, pos.Y); } if (JoyState.HasFlag(ControllerState.B_PRESSED)) { newpos = RespawnCentreScreen(); } return(newpos); }
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(); } }