Exemple #1
0
        public DebrisSpawner(float timeToActivate, Debris spawnerType, bool canSpawnMore) : base(0, 0)
        {
            _canSpawnMore    = canSpawnMore;
            _timeToActivate  = timeToActivate;
            _activationTimer = new Timer();
            int randomType = random.Next(100);

            if (spawnerType != null)
            {
                _spawnerType = spawnerType;
            }
            else if (randomType > 44)
            {
                _spawnerType = new SpaceRock();
            }
            else
            {
                _spawnerType = new Satellite();
            }
            _debrisSpawnTimer = new Timer();

            _newSpawnerTimer = new Timer();

            OnUpdate += RandomRotate;
            OnUpdate += CreateDebris;
            OnUpdate += Activate;
            OnUpdate += CreateNewSpawners;
        }
        public void CheckCollision(float deltaTime)
        {
            if (Parent != null)
            {
                foreach (Actor hitCheck in Parent.GetChildren)
                {
                    if (hitCheck is Debris && !(_origin is Debris))
                    {
                        Debris debris = (Debris)hitCheck;
                        if (debris.DetectCollision(_hitbox))
                        {
                            Destroy();
                            if (debris is Satellite)
                            {
                                Ship.Score += 150;
                            }
                            else
                            {
                                Ship.Score += 100;
                            }
                        }
                    }
                    if (hitCheck is Ship && !(_origin is Ship))
                    {
                        Ship ship = (Ship)hitCheck;
                        if (ship.DetectCollision(_hitbox, _damage))
                        {
                            Destroy();
                        }
                    }
                    if (hitCheck is Bullet)
                    {
                        Bullet bullet = (Bullet)hitCheck;
                        if (bullet._origin is Ship && !(_origin is Ship))
                        {
                            if (_hitbox.DetectCollision(bullet._hitbox))
                            {
                                Destroy();

                                bullet.Destroy();

                                Ship.Score += 10;
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public void CreateDebris(float deltaTime)
        {
            if (_isActive)
            {
                if (_debrisSpawnTimer.Seconds >= _debrisSpawRate)
                {
                    _debrisSpawnTimer.Restart();
                    Vector3 facing = new Vector3(GetM12, GetM11, 0) * random.Next(50, 200);
                    if (_spawnerType is SpaceRock)
                    {
                        _spawnerType = new SpaceRock(100, 100, facing.x, facing.y);

                        int spawnLocation = random.Next(4);
                        switch (spawnLocation)
                        {
                        case 0:
                            _spawnerType.Y = 0;
                            _spawnerType.X = random.Next(1280 + 1);
                            break;

                        case 1:
                            _spawnerType.Y = 780;
                            _spawnerType.X = random.Next(1280 + 1);
                            break;

                        case 2:
                            _spawnerType.X = 0;
                            _spawnerType.Y = random.Next(780 + 1);
                            break;

                        case 3:
                            _spawnerType.X = 1280;
                            _spawnerType.Y = random.Next(780 + 1);
                            break;
                        }

                        Parent.AddChild(_spawnerType);
                    }

                    else
                    {
                        _spawnerType = new Satellite(100, 100, facing.x, facing.y);

                        int spawnLocation = random.Next(4);
                        switch (spawnLocation)
                        {
                        case 0:
                            _spawnerType.Y = 0;
                            _spawnerType.X = random.Next(1280 + 1);
                            break;

                        case 1:
                            _spawnerType.Y = 780;
                            _spawnerType.X = random.Next(1280 + 1);
                            break;

                        case 2:
                            _spawnerType.X = 0;
                            _spawnerType.Y = random.Next(780 + 1);
                            break;

                        case 3:
                            _spawnerType.X = 1280;
                            _spawnerType.Y = random.Next(780 + 1);
                            break;
                        }

                        Parent.AddChild(_spawnerType);
                    }
                }
            }
        }