/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } if (InputManager.InputManager.KeyJustPressed(Keys.Escape)) { LocalClient.Disconnect(); } // TODO: Add your update logic here InputManager.InputManager.Update(Keyboard.GetState(), Mouse.GetState(), IsActive); TimeManager.Update(gameTime); BackgroundWall.Update(); if (Program.Hosting) { Server.Update(); } LocalClient.Update(); PlatformWorld.Update(); base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { IsMouseVisible = true; TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 1000 / 120); InactiveSleepTime = TargetElapsedTime; Window.Title = "XNA Multiplayer Game - "; if (Program.Hosting) { Window.Title += "Listen server, hosting on port 5555."; } else { Window.Title += "Client, joined at " + Program.Ip + ":5555."; } // Initialize classes & members. sb = new SpriteBatch(GraphicsDevice); Helper.Initialize(this); ResourceHelper.Initialize(Content); // Load content. _backgroundWallTexture = ResourceHelper.LoadTexture("Backgrounds\\Veins"); _platformTexture = ResourceHelper.LoadTexture("Objects\\Platform"); _vignette = ResourceHelper.LoadTexture("Gui\\Vignette"); Platform.Texture = ResourceHelper.LoadTexture("Objects\\Platform"); Player.Texture = ResourceHelper.LoadTexture("Objects\\Player"); // TODO: Add your initialization logic here Helper.Initialize(this); _graphics.PreferredBackBufferWidth = 768; _graphics.PreferredBackBufferHeight = 768; _graphics.PreferMultiSampling = true; _graphics.SynchronizeWithVerticalRetrace = false; _graphics.ApplyChanges(); IsFixedTimeStep = true; BackgroundWall = new BackgroundWall(_backgroundWallTexture, DefaultScrollSpeed); if (Program.Hosting) { Server.Initialize(); } PlatformWorld.Initialize(DefaultScrollSpeed); LocalClient.Initialize(); base.Initialize(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(_clearColor); // TODO: Add your drawing code here sb.Begin(); BackgroundWall.Draw(sb); PlatformWorld.Draw(sb); LocalClient.Draw(sb); DrawVignette(); sb.End(); base.Draw(gameTime); }