public void update(World world) { if (Keyboard.IsKeyPressed(Keyboard.Key.Return)) { ControllerKey controllerKey = new ControllerKey(0, ControllDevice.GamePad); if (!players.ContainsKey(controllerKey)) { players[controllerKey] = new Player(world, Vector2.Zero, new KeyboardController()); } } GamePadInputManager padInputManager = Program.gamePadInputManager; foreach (uint padIndex in padInputManager.connectedPadIndices) { if (padInputManager.isClicked(GamePadButton.Start, padIndex)) { ControllerKey controllerKey = new ControllerKey(padIndex, ControllDevice.GamePad); if (!players.ContainsKey(controllerKey)) { players[controllerKey] = new Player(world, Vector2.Zero, new GamePadController(padIndex)); } } } foreach (Player player in players.Values) { player.update(); } }
public static string rootPath = "../../"; // path for development version //public static string rootPath = ""; // path for shipping version static void Main(string[] args) { // initialize window and view win = new RenderWindow(new VideoMode(800, 600), "2D Game Project"); view = new View(); resetView(); gui = new GUI(win, view); Text debugText = new Text("", calibriFont); debugText.Color = new Color(252, 143, 80); // exit Program, when window is being closed //win.Closed += new EventHandler(closeWindow); win.Closed += (sender, e) => { (sender as Window).Close(); }; // initialize GamePadInputManager, in case, there are GamePads connected gamePadInputManager = new GamePadInputManager(); // initialize GameState handleNewGameState(); // initialize GameTime gameTime = new GameTime(); gameTime.Start(); while (running && win.IsOpen()) { gamePadInputManager.update(); // TODO: reevaluate gamepads every once in a while currentGameState = state.update(); if (currentGameState != prevGameState) { handleNewGameState(); } // draw current frame win.Clear(new Color(100, 149, 237)); //cornflowerblue ftw!!! 1337 state.draw(win, view); state.drawGUI(gui); { //HACK debugText.DisplayedString = "fps:" + (1.0 / gameTime.EllapsedTime.TotalSeconds); debugText.DisplayedString += "\ntest"; gui.draw(debugText); } win.SetView(view); win.Display(); // check for window-events. e.g. window closed win.DispatchEvents(); // update GameTime gameTime.Update(); } }