Exemplo n.º 1
0
        /// <summary>
        /// Luo komponentit, alustaa ne ja antaa ne argumenttina saadulle
        /// peliobjektille.
        /// </summary>
        /// <param name="monster">Peliobjekti jolle komponentit lisätään.</param>
        private void CreateComponents(GameObject monster)
        {
            TargetingComponent targetingComponent = new TargetingComponent(monster, new string[] { "monster", "world" })
            {
                RangeX = 32f,
                RangeY = 32f
            };

            HealthComponent healthComponent = new HealthComponent(monster, statSet);

            rotation.Disable();

            FacingComponent facing = new FacingComponent(monster);

            SteeringComponent steeringComponent = new SteeringComponent(monster);

            DamageRenderer r = new DamageRenderer(monster);

            r.Initialize();
            r.Color = Color.Red;

            monster.AddComponent(r);
            monster.AddComponent(statSet);
            monster.AddComponent(targetingComponent);
            monster.AddComponent(healthComponent);
            monster.AddComponent(skillSet);
            monster.AddComponent(rotation);
            monster.AddComponent(facing);
            monster.AddComponent(steeringComponent);
            monster.AddComponent(weaponComponent);

            monster.InitializeComponents();
        }
Exemplo n.º 2
0
        protected override ComponentUpdateResults OnUpdate(GameTime gameTime, IEnumerable <ComponentUpdateResults> results)
        {
            float flip = 1f;

            if (RangeY < 0f)
            {
                flip = -1f;
            }

            FacingComponent facing = owner.FirstComponentOfType <FacingComponent>();

            // ei oteta itteä mukaan areaan,
            // facingnumber palauttaa joko 1f tai -1f, riippuen siitä katsooko oikealla vai vasemmalle
            if (facing.IsFacingLeft)
            {
                queryRegion = new AABB(owner.Position.X - RangeX - 1, owner.Position.Y + flip * Math.Abs(RangeY), RangeX, Math.Abs(RangeY));
            }
            else
            {
                queryRegion = new AABB(owner.Position.X + RangeX + 1, owner.Position.Y, RangeX, RangeY);
            }

            // TODO mites jos ei ookkaan tarpeeksi iso collider?
            List <BroadphaseProxy> proxies = owner.Game.World.QueryAABB(ref queryRegion);

            if (ignoredTags != null && proxies.Count > 0)
            {
                for (int i = 0; i < ignoredTags.Count; i++)
                {
                    proxies.RemoveAll(o => o.Client.Owner.ContainsTag(ignoredTags[i]));
                }
            }

            target = GetClosest(proxies);

            return(new ComponentUpdateResults(this, true));
        }
Exemplo n.º 3
0
        public static SkillSet CreateBlobSkillSet(GameObject blob)
        {
            SkillSet skillSet = new SkillSet(blob);

            Skill attack = new Skill("attack", 5200, () =>
            {
                TargetingComponent targetingComponent = blob.FirstComponentOfType <TargetingComponent>();
                WeaponComponent weaponComponent       = blob.FirstComponentOfType <WeaponComponent>();
                StatSet statSet = blob.FirstComponentOfType <StatSet>();

                if (targetingComponent.HasTarget)
                {
                    bool isCrit = false;

                    float damage = weaponComponent.GenerateAttack(statSet.GetAttackPower(), statSet.GetCritPercent(), ref isCrit);

                    targetingComponent.Target.FirstComponentOfType <HealthComponent>().TakeDamage(damage);

                    SpriterComponent <Texture2D> spriterComponent = blob.FirstComponentOfType <SpriterComponent <Texture2D> >();
                    spriterComponent.ChangeAnimation("Attack");

                    AnimationFinishedEventHandler animationFininshedEventHandler = (animation) =>
                    {
                        spriterComponent.ChangeAnimation("Walk");
                    };

                    spriterComponent.OnAnimationFinished += animationFininshedEventHandler;

                    spriterComponent.OnAnimationChanged += (old, newAnim) =>
                    {
                        if (old.Name == "Attack")
                        {
                            spriterComponent.OnAnimationFinished -= animationFininshedEventHandler;
                        }
                    };

                    blob.FirstComponentOfType <DamageRenderer>().AddText(((int)(damage)).ToString(), isCrit);

                    return(true);
                }

                return(false);
            });

            Skill beam = new Skill("beam", 15200, () =>
            {
                TargetingComponent targetingComponent = blob.FirstComponentOfType <TargetingComponent>();
                WeaponComponent weaponComponent       = blob.FirstComponentOfType <WeaponComponent>();
                StatSet statSet        = blob.FirstComponentOfType <StatSet>();
                FacingComponent facing = blob.FirstComponentOfType <FacingComponent>();

                SpriterComponent <Texture2D> spriterComponent = blob.FirstComponentOfType <SpriterComponent <Texture2D> >();
                spriterComponent.ChangeAnimation("Attack2");

                Texture2D plasma = blob.Game.Content.Load <Texture2D>(@"Animations\Boss\Plasma");

                AABB area = new AABB(blob.Position.X * facing.FacingNumber * -1, blob.Position.Y, plasma.Width, plasma.Height);
                List <BroadphaseProxy> proxies = blob.Game.World.QueryAABB(ref area);

                bool isCrit = false;

                float damage = weaponComponent.GenerateSpecialAttack(25f, 50f, statSet.GetAttackPower(), statSet.GetCritPercent(), ref isCrit);

                foreach (BroadphaseProxy proxy in proxies.Where(p => p.Client.Owner.Name.StartsWith("Player")))
                {
                    proxy.Client.Owner.FirstComponentOfType <HealthComponent>().TakeDamage(damage);

                    blob.FirstComponentOfType <DamageRenderer>().AddText(((int)(damage)).ToString(), isCrit);
                }

                AnimationFinishedEventHandler animationFininshedEventHandler = (animation) =>
                {
                    spriterComponent.ChangeAnimation("Walk");
                };

                spriterComponent.OnAnimationFinished += animationFininshedEventHandler;

                spriterComponent.OnAnimationChanged += (old, newAnim) =>
                {
                    if (old.Name == "Attack2")
                    {
                        spriterComponent.OnAnimationFinished -= animationFininshedEventHandler;
                    }
                };

                return(true);
            });

            Skill smash = new Skill("smash", 10200, () =>
            {
                TargetingComponent targetingComponent = blob.FirstComponentOfType <TargetingComponent>();
                WeaponComponent weaponComponent       = blob.FirstComponentOfType <WeaponComponent>();
                StatSet statSet = blob.FirstComponentOfType <StatSet>();

                if (targetingComponent.HasTarget)
                {
                    Console.WriteLine("SMASH!");

                    bool isCrit = false;

                    float damage = weaponComponent.GenerateAttack(statSet.GetAttackPower(), statSet.GetCritPercent(), ref isCrit);

                    targetingComponent.Target.FirstComponentOfType <HealthComponent>().TakeDamage(damage);

                    SpriterComponent <Texture2D> spriterComponent = blob.FirstComponentOfType <SpriterComponent <Texture2D> >();
                    spriterComponent.ChangeAnimation("Attack");

                    AnimationFinishedEventHandler animationFininshedEventHandler = (animation) =>
                    {
                        spriterComponent.ChangeAnimation("Walk");
                    };

                    spriterComponent.OnAnimationFinished += animationFininshedEventHandler;

                    spriterComponent.OnAnimationChanged += (old, newAnim) =>
                    {
                        if (old.Name == "Attack")
                        {
                            spriterComponent.OnAnimationFinished -= animationFininshedEventHandler;
                        }
                    };

                    blob.FirstComponentOfType <DamageRenderer>().AddText(((int)(damage)).ToString(), isCrit);

                    return(true);
                }

                return(false);
            });

            skillSet.AddSkill(attack);
            skillSet.AddSkill(beam);
            skillSet.AddSkill(smash);

            return(skillSet);
        }