private void Awake() { _bigAsteroidsPool = ObjectPool.Build(AsteroidBig_Prefab, 25, 25); _smallAsteroidsPool = ObjectPool.Build(AsteroidSmall_Prefab, 25, 25); gameScreenLogger = GameScreenLogger.New(UIStorage.Instance.mainscreen_Text); AsteroidsManager.New(_bigAsteroidsPool, _smallAsteroidsPool); }
/// <summary> /// Collisions the detection. /// </summary> private void CollisionDetection() { foreach (var asteroid in AsteroidsManager.Asteroids) { foreach (var shot in ShotManager.Shots) { if (!shot.IsDead & !asteroid.IsDead & shot.IsCircleCollide(asteroid)) { shot.IsDead = true; asteroid.IsDead = true; score += 1000; ExplosionsManager.AddExplosion(asteroid.Center); if (asteroid.Scale > 0.5f) { var scale = asteroid.Scale == 1 ? 0.75f : 0.5f; AsteroidsManager.AddAsteroid(scale, asteroid.Center); AsteroidsManager.AddAsteroid(scale, asteroid.Center); } } } if (!ship.IsDead & !asteroid.IsDead & ship.IsCircleCollide(asteroid)) { ship.IsDead = true; ExplosionsManager.AddExplosion(ship.Center); respawnCounter = MaxRespawnCounter; SoundManager.StopThrust(); } } }
/// <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(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(background, Vector2.Zero, Color.White); bgScroll.Draw(spriteBatch); if (gameState == GameState.Menu) { spriteBatch.Draw(logo, new Vector2((Width - logo.Width) / 2, 100), Color.White); if (textEnable) { spriteBatch.DrawString(pericles14, "Press Space to continue", new Vector2(280, 300), Color.White); } } bgScroll2.Draw(spriteBatch); if (gameState == GameState.Play) { ship.Draw(spriteBatch); ShotManager.Draw(spriteBatch); AsteroidsManager.Draw(spriteBatch); ExplosionsManager.Draw(spriteBatch); spriteBatch.DrawString(pericles14, $"Score: {score}", new Vector2(10, 10), Color.White); } spriteBatch.End(); base.Draw(gameTime); }
/// <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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } bgScroll.Update(gameTime); bgScroll2.Update(gameTime); if (gameState == GameState.Menu) { textCounter--; if (textCounter <= 0) { textCounter = MaxRespawnCounter; textEnable = !textEnable; } if (InputHandler.IsKeyPressed(Keys.Space)) { gameState = GameState.Play; } } else if (gameState == GameState.Play) { if (ship.IsDead) { respawnCounter--; if (respawnCounter < 0) { ship.Center = new Vector2(Width / 2, Height / 2); ship.Velocity = Vector2.Zero; ship.IsDead = false; } } else { if (InputHandler.IsKeyDown(Keys.Left)) { ship.Rotation -= 0.05f; } if (InputHandler.IsKeyDown(Keys.Right)) { ship.Rotation += 0.05f; } ship.Thrust = InputHandler.IsKeyDown(Keys.Up); if (InputHandler.IsKeyDown(Keys.LeftControl)) { ShotManager.AddShot(ship.Center + ship.Heading * ship.Radius, ship.Heading * 3); } } ship.Update(gameTime); CollisionDetection(); ShotManager.Update(gameTime); AsteroidsManager.Update(gameTime); ExplosionsManager.Update(gameTime); } base.Update(gameTime); }
private void Awake() { GameController = m_GameController; UserInput = m_UserInput; PlayerManager = m_PlayerManager; PoolManager = m_PoolManager; BulletsManager = m_BulletsManager; AsteroidsManager = m_AsteroidsManager; ControllerUI = m_ControllerUI; }
/// <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); background = Content.Load <Texture2D>(@"Images\nebula_blue.f2014"); bgScroll = new BgScroll(Content.Load <Texture2D>(@"Images\debris2_blue")) { DxOffset = 0.5f }; bgScroll2 = new BgScroll(Content.Load <Texture2D>(@"Images\debris2_blue")) { Flip = true }; ship = new Ship(Content.Load <Texture2D>(@"Images\double_ship"), new Vector2(Width / 2, Height / 2)); ShotManager.Initialize(Content.Load <Texture2D>(@"Images\shot2")); AsteroidsManager.Initialize(Content.Load <Texture2D>(@"Images\asteroid_blue")); AsteroidsManager.AddAsteroids(5); pericles14 = Content.Load <SpriteFont>(@"Fonts\Pericles14"); ExplosionsManager.Initialize(Content.Load <Texture2D>(@"Images\explosion_alpha")); SoundManager.Initialize(Content, Width); logo = Content.Load <Texture2D>(@"Images\asteroids"); }