/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); networkManager.LoadContent(); inputManager = new InputManager(this); Services.AddService(typeof(IInputService), inputManager); Components.Add(inputManager); player = new Tank(this); player.LoadContent(); enemy = null; }
/// <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) this.Exit(); float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; if (networkManager.enemyCreated) { enemy = new Tank(this); enemy.position = new Vector2(100, 100); enemy.LoadContent(); networkManager.enemyCreated = false; } if (enemy != null) { float px = networkManager.tankDataHolder.px; float py = networkManager.tankDataHolder.py; float angle = networkManager.tankDataHolder.rotationAngle; float newX = enemy.position.X + px; float newY = enemy.position.X + py; enemy.position = new Vector2(px,py); enemy.rotationAngle = angle; } player.Update(deltaTime); base.Update(gameTime); }