Ejemplo n.º 1
0
 private void SpawnPlayer(BulletFactory bulletFactory)
 {
     var spaceshipTexture = Content.Load<Texture2D>("playerShip1_blue");
     var spaceshipRegion = new TextureRegion2D(spaceshipTexture);
     _player = _entityManager.AddEntity(new Spaceship(spaceshipRegion, bulletFactory));
 }
Ejemplo n.º 2
0
        private void CheckCollisions()
        {
            var meteors = _entityManager.Entities.Where(e => e is Meteor).Cast<Meteor>().ToArray();
            var lasers = _entityManager.Entities.Where(e => e is Laser).Cast<Laser>().ToArray();

            foreach (var meteor in meteors)
            {
                if (_player != null && !_player.IsDestroyed && _player.BoundingCircle.Intersects(meteor.BoundingCircle))
                {
                    Explode(meteor.Position, meteor.Size);
                    Explode(_player.Position, 3);

                    _player.Destroy();
                    _player = null;
                    meteor.Destroy();
                }

                foreach (var laser in lasers.Where(laser => meteor.Contains(laser.Position)))
                {
                    meteor.Damage(1);
                    laser.Destroy();
                    _score++;

                    Explode(laser.Position, meteor.Size);

                    if (meteor.Size >= 2)
                    {
                        _meteorFactory.SplitMeteor(meteor);
                    }
                }

                if (_player != null && _shieldHealth > 0 && meteor.BoundingCircle.Intersects(new CircleF(_player.Position, _shieldRadius)))
                {
                    _shieldHealth--;
                    _shieldRadius--;
                    Explode(meteor.Position, meteor.Size);
                    meteor.Destroy();
                }
            }
        }