예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weapon"></param>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <param name="movementSpeed"></param>
        public void SpawnProjectile(WeaponComponent weapon, Vector2 position, float rotation, float movementSpeed)
        {
            // First get texture for the projectile, add to dictionary if it isn't there.
            if (!_projectileTextures.TryGetValue(weapon.ProjectileName, out var texture))
            {
                texture = _atlas.GetRegion(weapon.ProjectileName);
                _projectileTextures[weapon.ProjectileName] = texture
                                                             ?? throw new ArgumentException($"Invalid projectile name defined in WeaponComponent: {weapon.ProjectileName}");
            }

            // Spawn our entity
            var projectile = _entityManager.AddEntity(new Projectile(texture, position, movementSpeed)
            {
                Rotation     = rotation,
                DamageSource = weapon.DamageSource
            });

            if (projectile == null)
            {
                Debug.WriteLine("Unable to add projectile.");
                return;
            }
            // Accelerate it
            projectile.Accelerate(movementSpeed);
            // Spawn the flash
            _entityManager.AddEntity(new ProjectileFlashEffect(_flashTexture, position, rotation, 200));
        }
예제 #2
0
        bool AddComponent(IComponent component, bool updateEntity)
        {
            if (Has(component))
            {
                return(false);
            }

            allComponents.Add(component);
            component.Entity = this;

            var  subComponentTypes = ComponentUtility.GetSubComponentTypes(component.GetType());
            bool isNew             = false;

            for (int i = 0; i < subComponentTypes.Length; i++)
            {
                int index = ComponentUtility.GetComponentIndex(subComponentTypes[i]);
                AddComponentToGroup(component, index);
                isNew |= AddSingleComponent(component, index);
            }

            if (isNew && updateEntity)
            {
                entityManager.AddEntity(this);
            }

            component.OnAdded();

            return(isNew);
        }
예제 #3
0
 /// <summary>
 /// Handles the collision between the player and a meteor.
 /// </summary>
 /// <param name="player">The player that may collide.</param>
 /// <param name="meteor">The meteor that may collide.</param>
 private void HandlePlayerMeteorCollision(Player player, Meteor meteor)
 {
     if (CollisionDetector.CheckCollision(player.BoundingCircle, meteor.BoundingCircle))
     {
         player.Damage(1);
         meteor.Destroy();
         _entityManager.AddEntity(new Explosion(meteor.Position, meteor.BoundingCircle.Radius));
     }
 }
예제 #4
0
        /// <summary>
        /// Adds a player entity to the entity manager
        /// </summary>
        private void LoadPlayer()
        {
            _player = new Player(TextureHolder.Textures["player"], _game.Input, new LaserFactory(_entityManager))
            {
                Position = _game.Center
            };

            _entityManager.AddEntity(_player);
        }
예제 #5
0
        public void Create(Vector2 position, Vector2 direction, float rotation, float speed)
        {
            var velocity = direction * speed;
            var laser    = new Laser(_bulletRegion, velocity)
            {
                Position = position,
                Rotation = rotation
            };

            _entityManager.AddEntity(laser);
        }
예제 #6
0
        /// <summary>
        /// Loads the level.
        /// After the level is loaded all the level entities are added to the entitymanager.
        /// </summary>
        /// <param name="deltaTime">The deltatime of the last gamecycle.</param>
        private void Load(float deltaTime)
        {
            LoadingTime -= deltaTime;

            if (LoadingTime <= 0)
            {
                foreach (Entity entity in _entities)
                {
                    _entityManager.AddEntity(entity);
                }
                Loaded = true;
            }
        }
예제 #7
0
        private void AddPlayerTrigger()
        {
            var trigger = new Trigger(Constants.TriggerIds.PlayerId)
            {
                Position       = new Vector2(Window.ClientBounds.Width - 4, 0),
                Width          = 4,
                Height         = Window.ClientBounds.Height,
                Color          = Color.Red,
                TriggerHandler = _serviceProvider.Resolve <PlayerTriggerHandler>()
            };

            _entityManager.AddEntity(trigger);
        }
예제 #8
0
        /// <summary>
        /// Adds a new laser to the entityManager.
        /// </summary>
        /// <param name="type">Het type laser</param>
        /// <param name="position">De positie van de laser</param>
        /// <param name="rotation">De richting/rotatie van de laser</param>
        public void SpawnLaser(LaserType type, Vector2 position, float rotation)
        {
            Laser laser = null;

            switch (type)
            {
            case LaserType.LIGHT: laser = new LightLaser(position, rotation); break;

            case LaserType.MEDIUM: laser = new MediumLaser(position, rotation); break;

            case LaserType.STRONG: laser = new HeavyLaser(position, rotation); break;
            }

            _entityManager.AddEntity(laser);
        }
예제 #9
0
        /// <summary>
        /// Creates a new meteor entity.
        /// </summary>
        /// <param name="type">The type of the new meteor</param>
        /// <param name="position">The position of the new meteor</param>
        /// <param name="direction">The direction of the new meteor</param>
        /// <param name="linearVelocity">The linear velocity of the new meteor</param>
        /// <param name="rotationVelocity">The rotation velocity of the new meteor</param>
        ///
        /// <returns>The new meteor entity.</returns>
        public Meteor CreateMeteor(MeteorType type, Vector2 position, Vector2 direction, float linearVelocity, float rotationVelocity, bool inject)
        {
            Meteor newMeteor = null;

            switch (type)
            {
            case MeteorType.TINY: newMeteor = new TinyMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.SMALL: newMeteor = new SmallMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.MEDIUM: newMeteor = new MediumMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.BIG: newMeteor = new BigMeteor(position, direction, linearVelocity, rotationVelocity); break;
            }

            if (inject)
            {
                _entityManager.AddEntity(newMeteor);
            }

            return(newMeteor);
        }