コード例 #1
0
        //TODO: Totally a hacky method of doing this.
        /// <summary>
        /// Creates a explosions around the specified entity.
        /// </summary>
        public static void CreateAoEEntity(Entity entity)
        {
            var CPComponent         = entity.GetComponent <CombatPropertiesComponent>();
            var SEAComponent        = entity.GetComponent <StatusEffectPropertiesComponent>();
            var AttributesComponent = entity.GetComponent <AttributesComponent>();
            var EquipmentComponent  = entity.GetComponent <EquipmentComponent>();
            var MovementComponent   = entity.GetComponent <MovementComponent>();

            var aoeOffset = new Vector2(CorvusExtensions.GetSign(MovementComponent.CurrentDirection) * CPComponent.AoEOffset.X, CPComponent.AoEOffset.Y);

            var aoe = CorvEngine.Components.Blueprints.EntityBlueprint.GetBlueprint("AreaOfEffect").CreateEntity();

            aoe.Size = new Vector2(CPComponent.AoESize.X, CPComponent.AoESize.Y);
            var center = entity.Location.Center;

            aoe.Position = new Vector2(center.X - (aoe.Size.X / 2) + aoeOffset.X, center.Y - (aoe.Size.Y / 2) + aoeOffset.Y);
            entity.Scene.AddEntity(aoe);
            var spriteName = CPComponent.AoEName;
            var effect     = CorvusGame.Instance.GlobalContent.LoadSprite(spriteName);
            var sc         = aoe.GetComponent <SpriteComponent>();

            sc.Sprite = effect;
            var anim = sc.Sprite.ActiveAnimation;

            sc.Sprite.PlayAnimation(anim.Name, TimeSpan.FromSeconds(CPComponent.AoEDuration));

            //give it it's properties.
            if (EquipmentComponent.UseWeaponBonuses)
            {
                var ec = aoe.GetComponent <EquipmentComponent>();
                ec.UseWeaponBonuses = true;
                ec.EquipWeapon(EquipmentComponent.CurrentWeapon);
                var se = aoe.GetComponent <StatusEffectPropertiesComponent>();
                se.StatusEffectAttributes = EquipmentComponent.CurrentWeapon.Effect;
            }
            else
            {
                var se = aoe.GetComponent <StatusEffectPropertiesComponent>();
                se.StatusEffectAttributes = SEAComponent.StatusEffectAttributes;
            }
            var cpc = aoe.GetComponent <CombatPropertiesComponent>();

            cpc.CombatProperties = CPComponent.CombatProperties;
            var ac = aoe.GetComponent <AttributesComponent>();

            ac.Attributes = AttributesComponent.Attributes;
            var aoec = aoe.GetComponent <AreaOfEffectComponent>();

            aoec.Classification = CPComponent.AoEHitableEntities;

            AudioManager.PlaySoundEffect(CPComponent.AoESound);
        }
コード例 #2
0
ファイル: EquipmentComponent.cs プロジェクト: Octanum/Corvus
        private void DropWeapon(string weaponToDrop, float launchModifier = 1f)
        {
            var mc        = this.GetDependency <MovementComponent>();
            var scene     = Parent.Scene;
            var oldWeapon = EntityBlueprint.GetBlueprint(weaponToDrop).CreateEntity();

            oldWeapon.Position = new Vector2(Parent.Position.X + -CorvusExtensions.GetSign(mc.CurrentDirection) * (Parent.Size.X + 5), Parent.Position.Y - Parent.Size.Y - 5);
            oldWeapon.Size     = new Vector2(22, 22);
            scene.AddEntity(oldWeapon);

            Random rand = new Random();
            float  rMod = (float)rand.Next(20, 50);
            var    pc   = oldWeapon.GetComponent <PhysicsComponent>();

            pc.Velocity = new Vector2(-CorvusExtensions.GetSign(mc.CurrentDirection) * 225f * launchModifier + rMod, -325f * launchModifier + rMod);
        }
コード例 #3
0
        private void GenerateCoinEntity(string coinName, float xmod)
        {
            var c = EntityBlueprint.GetBlueprint(coinName).CreateEntity();

            c.Size     = new Vector2(12, 12);
            c.Position = new Vector2(Parent.Location.Center.X, Parent.Location.Top);
            Parent.Scene.AddEntity(c);

            Random rand = new Random();
            var    pc   = c.GetComponent <PhysicsComponent>();

            pc.HorizontalDragCoefficient = 0.01f;
            pc.GravityCoefficient        = 0.2f;
            var mc = this.GetDependency <MovementComponent>();

            pc.VelocityX = ((mc == null) ? ((rand.Next(0, 5) <= 2) ? 1 : -1) : -CorvusExtensions.GetSign(mc.CurrentDirection)) * (50f * xmod);
        }
コード例 #4
0
        /// <summary>
        /// Gets the reaction box centered on the entity.
        /// </summary>
        private Rectangle GetReactionBox()
        {
            //TODO: Remove this later. Some weird bug that i can't explain.
            if (Camera.Active == null)
            {
                return(new Rectangle());
            }

            var center = new Vector2(Parent.Location.Center.X, Parent.Location.Center.Y);

            //There's a bit of a bug when the direction is None. Basically, the Offset.X is gone when that happens.
            var       dirSign = CorvusExtensions.GetSign(MovementComponent.CurrentDirection);
            var       rectPos = new Vector2((center.X + (dirSign * Offset.X)) - ReactionRange.X / 2, (center.Y + Offset.Y) - ReactionRange.Y / 2);
            Rectangle rect    = new Rectangle((int)rectPos.X, (int)rectPos.Y, (int)ReactionRange.X, (int)ReactionRange.Y);

            return(rect);
        }
コード例 #5
0
        /// <summary>
        /// Starts the weapon swing animation based on the entity, weapon name, and it's duration (usually the attack speed.).
        /// </summary>
        public void Start(Entity src, string weapon, float duration, Vector2 offset)
        {
            _StartAnimation = true;
            _Entity         = src;
            _Weapon         = CorvusGame.Instance.GlobalContent.Load <Texture2D>(weapon);
            _Duration       = duration; //2; //Just to speed it up a bit.
            _StartTime      = DateTime.Now;
            _RotationAngle  = -0.5f;    //This looks proper facing right, which is the common direction.

            var mc = _Entity.GetComponent <MovementComponent>();

            //Account for for change in rotation when facing left.
            if (mc.CurrentDirection == Direction.Left)
            {
                _RotationAngle = _RotationAngle * -1;
            }

            _Direction = CorvusExtensions.GetSign(mc.CurrentDirection);
            _Origin    = (mc.CurrentDirection == Direction.Left) ? new Vector2(_Entity.Size.X / 2, _Entity.Size.Y / 2) : new Vector2(0f, _Entity.Size.Y / 2);
            _Flip      = (mc.CurrentDirection == Direction.Left) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            _OffSet    = new Vector2(_Direction * offset.X, offset.Y);
        }
コード例 #6
0
ファイル: CombatComponent.cs プロジェクト: Octanum/Corvus
        private void EnemyAttackMelee()
        {
            AudioManager.PlaySoundEffect(CombatPropertiesComponent.AttackSound);
            //Enumerate over each entity that intersected with our attack rectangle, and if they're not us, make them take damage.
            foreach (var attackedEntity in PhysicsSystem.GetEntitiesAtLocation(CreateHitBox()).Reverse())
            {
                //might be a little inefficient because we have to keep searching a list to get the ClassificationComponent.
                var cc = attackedEntity.GetComponent <ClassificationComponent>();
                if (attackedEntity != Parent && cc.Classification == AttackableEntities)
                {
                    var damageComponent = attackedEntity.GetComponent <DamageComponent>();
                    damageComponent.TakeDamage(AttributesComponent);

                    //knockback
                    var mc = attackedEntity.GetComponent <MovementComponent>();
                    mc.Knockback(AttributesComponent.TotalKnockback, CorvusExtensions.GetSign(MovementComponent.CurrentDirection));

                    //When the enemy attacks, apply status effects, if any.
                    if (CombatPropertiesComponent.AppliesEffect)
                    {
                        var seac = Parent.GetComponent <StatusEffectPropertiesComponent>();
                        if (seac == null)
                        {
                            continue;
                        }
                        var enemySEC = attackedEntity.GetComponent <StatusEffectsComponent>();
                        if (enemySEC == null)
                        {
                            continue;
                        }
                        enemySEC.ApplyStatusEffect(seac.StatusEffectAttributes);
                    }
                    if (CombatPropertiesComponent.IsAoE)
                    {
                        AreaOfEffectComponent.CreateAoEEntity(this.Parent);
                    }
                }
            }
        }
コード例 #7
0
ファイル: ProjectileComponent.cs プロジェクト: Octanum/Corvus
        //NOTE: Not tested with enemies yet :p
        /// <summary>
        /// Creates a projectile entity next to the entity calling this function.
        /// The launch direction can be set manually to avoid awkward projectiles, otherwise it uses the movement components current direction.
        /// </summary>
        public static void CreateProjectileEntity(Entity entity, Direction?launchDirection = null)
        {
            var CPComponent         = entity.GetComponent <CombatPropertiesComponent>();
            var AttributesComponent = entity.GetComponent <AttributesComponent>();
            var EquipmentComponent  = entity.GetComponent <EquipmentComponent>();
            var CombatComponent     = entity.GetComponent <CombatComponent>();
            var MovementComponent   = entity.GetComponent <MovementComponent>();
            var SEAComponent        = entity.GetComponent <StatusEffectPropertiesComponent>();

            var projectile = CorvEngine.Components.Blueprints.EntityBlueprint.GetBlueprint("Projectile").CreateEntity();

            projectile.Size = new Vector2(CPComponent.ProjectileSize.X, CPComponent.ProjectileSize.Y);
            var center = entity.Location.Center;

            projectile.Position = new Vector2(center.X + CorvusExtensions.GetSign(MovementComponent.CurrentDirection) * (CPComponent.ProjectileOffset.X),
                                              center.Y + CPComponent.ProjectileOffset.Y);

            entity.Scene.AddEntity(projectile);
            string spriteName = CPComponent.ProjectileName;
            var    sprite     = CorvusGame.Instance.GlobalContent.LoadSprite(spriteName);
            var    sc         = projectile.GetComponent <SpriteComponent>();

            sc.Sprite = sprite;

            //Apply properties
            var ac = projectile.GetComponent <AttributesComponent>();

            ac.Attributes = AttributesComponent.Attributes;
            if (CPComponent.AppliesEffect)
            {
                var seac = projectile.GetComponent <StatusEffectPropertiesComponent>();
                seac.StatusEffectAttributes = (SEAComponent != null) ? SEAComponent.StatusEffectAttributes : EquipmentComponent.CurrentWeapon.Effect;
            }
            if (EquipmentComponent.UseWeaponBonuses)// != null)
            {
                var ec = projectile.GetComponent <EquipmentComponent>();
                ec.UseWeaponBonuses = true;
                ec.EquipWeapon(EquipmentComponent.CurrentWeapon);
            }
            var cpc = projectile.GetComponent <CombatPropertiesComponent>();

            cpc.CombatProperties = CPComponent.CombatProperties;
            var pc = projectile.GetComponent <ProjectileComponent>();

            pc.Classification = CombatComponent.AttackableEntities;
            var physC = projectile.GetComponent <PhysicsComponent>();

            physC.GravityCoefficient        = CPComponent.ProjectileGravityCoefficient;
            physC.HorizontalDragCoefficient = CPComponent.ProjectileHorDragCoefficient;
            var direction = (launchDirection == null) ? MovementComponent.CurrentDirection : launchDirection;

            if (direction == Direction.Right)
            {
                physC.Velocity = new Vector2(CPComponent.CombatProperties.ProjectileVelocity.X, -CPComponent.CombatProperties.ProjectileVelocity.Y);
            }
            else if (direction == Direction.Left)
            {
                physC.Velocity = new Vector2(-CPComponent.CombatProperties.ProjectileVelocity.X, -CPComponent.CombatProperties.ProjectileVelocity.Y);
            }
            var mc = projectile.GetComponent <MovementComponent>();

            mc.CurrentDirection = MovementComponent.CurrentDirection;
        }