/// <summary>
        /// Updates all ballistics
        /// To be run in its own thread
        /// </summary>
        public void Update()
        {
            while (true)
            {
                if (Projectiles.Any())
                {
                    foreach (var projectile in Projectiles)
                    {
                        projectile.Update();

                        foreach (var invader in _game._invaders.Enemies)
                        {
                            if (invader.GetHitbox().ContainsCell(projectile.Model))
                            {
                                invader.Dead         = true;
                                projectile.Collision = true;
                            }
                        }
                    }

                    Projectiles.RemoveAll(x => x.Collision);
                }

                Thread.Sleep(100);
            }
        }
Example #2
0
        private void RemoveNotAliveGameObjects()
        {
            GameObjects.Where(go => !renderer.IsInBounds(go.Position))
            .ForEach(go => go.IsAlive = false);

            GameObjects.RemoveAll(go => !go.IsAlive);
            Enemies.RemoveAll(enemy => !enemy.IsAlive);
            Projectiles.RemoveAll(projectile => !projectile.IsAlive);
        }
Example #3
0
        // Update
        //
        // functions
        //  - Get and send input states to the InputHandler
        //  - Check collisions for all my MY projectiles and enemies
        //  - Log any collisions for my projectiles and ME
        //  - Check collisions for all enemies/projectiles and ME
        //  - Log my HP if hit
        //      - Check if I die and do anything I gotta
        //  - Update my position if I'm moving
        //      - collide with platforms below me
        //  - Log my position is I'm moving
        //
        // returns
        //
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            Cursor.Pos = new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y);

            ReadInput(Mouse.GetState(), Keyboard.GetState());
            HandleInput();

            if (gameStarted)
            {
                CheckEvents();

                foreach (Skeleton s in Enemies)
                {
                    s.Update(Stage, KillZones);
                }

                foreach (Doot p in Projectiles)
                {
                    p.Update(KillZones);
                }
                Projectiles.RemoveAll(p => p.Marked);

                foreach (PickUp p in PickUps)
                {
                    p.Update();
                }
                PickUps.RemoveAll(p => p.Marked);

                foreach (Tracer t in Tracers)
                {
                    t.Update();
                }
                Tracers.RemoveAll(p => p.Opacity <= 0);

                foreach (Platform p in Platforms)
                {
                    p.Update();
                }
                Platforms.RemoveAll(p => p.Opacity <= 0);

                if (boss != null && boss.Active)
                {
                    boss.Update();
                }

                player.Update(Platforms, KillZones, PickUps);

                boss.UpdateHPBar();
            }

            foreach (SpriteText s in Text)
            {
                s.Move(gameTime);
            }
            Text.RemoveAll(s => s.Opacity <= 0);

            Cursor.Animate();

            base.Update(gameTime);
        }