Beispiel #1
0
        public void UpdateAttackCollisionWithRobot(GameTime gameTime, AttackBox ActiveAttackBox, RobotAnimation TargetRobot)
        {
            if (TargetRobot.HP <= 0 || TargetRobot.Team == ActiveAttackBox.Owner.Team)
            {
                return;
            }

            if (!ActiveAttackBox.ListAttackedRobots.Contains(TargetRobot))
            {
                PolygonCollisionResult FinalCollisionResult = new PolygonCollisionResult(Vector2.Zero, -1);
                Polygon FinalCollisionPolygon = null;

                foreach (CollisionPolygon EnemyCollision in TargetRobot.ListCollisionPolygon)
                {
                    foreach (Polygon CollisionPolygon in ActiveAttackBox.ListCollisionPolygon)
                    {
                        PolygonCollisionResult CollisionResult = Polygon.PolygonCollisionSAT(CollisionPolygon, EnemyCollision.ActivePolygon, ActiveAttackBox.Speed);

                        if (FinalCollisionResult.Distance < 0 || (CollisionResult.Distance >= 0 && CollisionResult.Distance > FinalCollisionResult.Distance))
                        {
                            FinalCollisionResult  = CollisionResult;
                            FinalCollisionPolygon = EnemyCollision.ActivePolygon;
                        }
                    }
                }

                if (FinalCollisionResult.Distance >= 0)
                {
                    if (TargetRobot.RobotAI != null)
                    {
                        TargetRobot.RobotAI.Update(gameTime, "On Hit");
                    }

                    Vector2 CollisionPoint;
                    ActiveAttackBox.OnCollision(FinalCollisionResult, FinalCollisionPolygon, out CollisionPoint);

                    if (ActiveAttackBox.ExplosionAttributes.ExplosionRadius > 0)
                    {
                        CreateExplosion(CollisionPoint, ActiveAttackBox);
                    }

                    ActiveAttackBox.ListAttackedRobots.Add(TargetRobot);

                    if (TargetRobot.HasKnockback)
                    {
                        TargetRobot.Speed.X = Math.Sign(ActiveAttackBox.Speed.X) * 3;
                        TargetRobot.Speed.Y = Math.Sign(ActiveAttackBox.Speed.Y) * 3;
                    }

                    if (Owner.IsOfflineOrServer || Owner.IsServer)
                    {
                        int FinalDamage = (int)ActiveAttackBox.Damage;

                        TargetRobot.HP -= FinalDamage;

                        OnDamageRobot(ActiveAttackBox.Owner, TargetRobot, FinalDamage, FinalCollisionPolygon.Center, Owner.IsMainCharacter(TargetRobot.ID));
                    }
                }
            }
        }
Beispiel #2
0
        public void UpdateAttackCollisionWithWorld(AttackBox ActiveAttackBox)
        {
            PolygonCollisionResult FinalCollisionResult       = new PolygonCollisionResult(Vector2.Zero, -1);
            PolygonCollisionResult FinalCollisionGroundResult = new PolygonCollisionResult(Vector2.Zero, -1);
            Polygon FinalCollisionPolygon = null;

            foreach (Polygon ActivePolygon in ListWorldCollisionPolygon)
            {
                foreach (Polygon CollisionPolygon in ActiveAttackBox.ListCollisionPolygon)
                {
                    PolygonCollisionResult CollisionGroundResult;
                    PolygonCollisionResult CollisionResult = Polygon.PolygonCollisionSAT(CollisionPolygon, ActivePolygon, ActiveAttackBox.Speed, out CollisionGroundResult);

                    if (FinalCollisionResult.Distance < 0 || (CollisionResult.Distance >= 0 && CollisionResult.Distance > FinalCollisionResult.Distance))
                    {
                        FinalCollisionResult       = CollisionResult;
                        FinalCollisionGroundResult = CollisionGroundResult;
                        FinalCollisionPolygon      = ActivePolygon;
                    }
                }
            }

            if (FinalCollisionResult.Distance >= 0)
            {
                Vector2 CollisionPoint;
                ActiveAttackBox.OnCollision(FinalCollisionResult, FinalCollisionPolygon, out CollisionPoint);
                SetAttackContext(ActiveAttackBox, ActiveAttackBox.Owner, (float)Math.Atan2(-FinalCollisionGroundResult.Axis.X, -FinalCollisionGroundResult.Axis.Y), CollisionPoint);
                ActiveAttackBox.UpdateSkills(TripleThunderAttackRequirement.OnGroundCollisionAttackName);

                if (ActiveAttackBox.ExplosionAttributes.ExplosionRadius > 0)
                {
                    CreateExplosion(CollisionPoint, ActiveAttackBox);
                }
                else if (!ActiveAttackBox.FollowOwner)
                {
                    Owner.PlayerSFXGenerator.PlayBulletHitObjectSound();
                }
            }
        }
Beispiel #3
0
        private void CreateExplosion(Vector2 ExplosionCenter, AttackBox ActiveAttackBox)
        {
            foreach (KeyValuePair <uint, RobotAnimation> ActiveRobotPair in DicRobot)
            {
                RobotAnimation TargetRobot = ActiveRobotPair.Value;

                bool IsSelf = TargetRobot == ActiveAttackBox.Owner;

                if (TargetRobot.HP <= 0 || (TargetRobot.Team == ActiveAttackBox.Owner.Team && !IsSelf))
                {
                    continue;
                }

                float DistanceFromCenter = Vector2.Distance(ExplosionCenter, TargetRobot.Position);

                if (DistanceFromCenter <= ActiveAttackBox.ExplosionAttributes.ExplosionRadius)
                {
                    float DistanceRatio = DistanceFromCenter / ActiveAttackBox.ExplosionAttributes.ExplosionRadius;
                    float ExplosionDiff = ActiveAttackBox.ExplosionAttributes.ExplosionDamageAtCenter - ActiveAttackBox.ExplosionAttributes.ExplosionDamageAtEdge;

                    float FinalDamage = ActiveAttackBox.ExplosionAttributes.ExplosionDamageAtCenter + ExplosionDiff * DistanceRatio;
                    if (IsSelf)
                    {
                        FinalDamage *= ActiveAttackBox.ExplosionAttributes.ExplosionDamageToSelfMultiplier;
                    }

                    if (Owner.IsOfflineOrServer || Owner.IsServer)
                    {
                        TargetRobot.HP -= (int)FinalDamage;

                        if (TargetRobot.HasKnockback)
                        {
                            float   WindDiff   = ActiveAttackBox.ExplosionAttributes.ExplosionWindPowerAtCenter - ActiveAttackBox.ExplosionAttributes.ExplosionWindPowerAtEdge;
                            Vector2 WindVector = Vector2.Normalize(TargetRobot.Position - ExplosionCenter);
                            Vector2 FinalWind  = WindVector * (ActiveAttackBox.ExplosionAttributes.ExplosionWindPowerAtCenter + WindDiff * DistanceRatio);

                            if (IsSelf)
                            {
                                FinalWind *= ActiveAttackBox.ExplosionAttributes.ExplosionWindPowerToSelfMultiplier;
                            }

                            TargetRobot.Speed += FinalWind;
                        }

                        OnDamageRobot(ActiveAttackBox.Owner, TargetRobot, (int)FinalDamage, TargetRobot.Position, Owner.IsMainCharacter(TargetRobot.ID));
                    }
                }
            }

            if (!Owner.IsServer && ActiveAttackBox.ExplosionAttributes.ExplosionAnimation.Path != string.Empty)
            {
                if (ActiveAttackBox.ExplosionAttributes.sndExplosion != null)
                {
                    PlayerSFXGenerator.PrepareExplosionSound(ActiveAttackBox.ExplosionAttributes.sndExplosion, ExplosionCenter);
                }

                SimpleAnimation NewExplosion = ActiveAttackBox.ExplosionAttributes.ExplosionAnimation.Copy();
                NewExplosion.IsLooped = false;
                NewExplosion.Position = new Vector2(ExplosionCenter.X, ExplosionCenter.Y - NewExplosion.PositionRectangle.Height / 2);
                ListImages.Add(NewExplosion);
            }
        }
Beispiel #4
0
        public void Update(GameTime gameTime)
        {
            lock (ListDelayedOnlineCommand)
            {
                foreach (DelayedExecutableOnlineScript ActiveCommand in ListDelayedOnlineCommand)
                {
                    ActiveCommand.ExecuteOnMainThread();
                }

                ListDelayedOnlineCommand.Clear();
            }

            for (int A = ListVisualEffects.Count - 1; A >= 0; --A)
            {
                SimpleAnimation ActiveVisualEffect = ListVisualEffects[A];
                ActiveVisualEffect.Update(gameTime);

                if (ActiveVisualEffect.HasEnded)
                {
                    ListVisualEffects.RemoveAt(A);
                }
            }

            for (int A = 0; A < ListAttackCollisionBox.Count; A++)
            {
                AttackBox ActiveAttackBox = (AttackBox)ListAttackCollisionBox[A];
                if (!ActiveAttackBox.IsAlive)
                {
                    continue;
                }

                ActiveAttackBox.Update(gameTime);

                foreach (KeyValuePair <uint, RobotAnimation> ActiveRobot in DicRobot)
                {
                    UpdateAttackCollisionWithRobot(gameTime, ActiveAttackBox, ActiveRobot.Value);
                }

                UpdateAttackCollisionWithWorld(ActiveAttackBox);

                ActiveAttackBox.Move(gameTime);
            }

            for (int A = ListImages.Count - 1; A >= 0; --A)
            {
                SimpleAnimation ActiveAnimation = ListImages[A];
                ActiveAnimation.Update(gameTime);

                if (ActiveAnimation.HasEnded)
                {
                    ListImages.RemoveAt(A);
                }
            }

            for (int P = ListProp.Count - 1; P >= 0; --P)
            {
                if (ListProp[P].HasEnded)
                {
                    ListProp.RemoveAt(P);
                }
                else
                {
                    ListProp[P].Update(gameTime);
                }
            }

            #region Robot Update

            foreach (RobotAnimation ActiveRobot in DicRobot.Values)
            {
                if (!ActiveRobot.IsUpdated)
                {
                    continue;
                }

                if (ActiveRobot.RobotAI != null && !Owner.UsePreview)
                {
                    ActiveRobot.RobotAI.UpdateStep(gameTime);
                }

                ActiveRobot.Update(gameTime, DicRobot);
            }

            foreach (RobotAnimation RobotToAdd in ListRobotToAdd)
            {
                SpawnRobot(RobotToAdd);
            }

            ListRobotToAdd.Clear();

            for (int R = ListRobotToRemove.Count - 1; R >= 0; R--)
            {
                DicRobot.Remove(ListRobotToRemove[R]);
                ListRobotToRemove.RemoveAt(R);

                if (ListRobotToRemove.Count == 0)
                {
                    Owner.CheckIfAllEnemiesAreDead();
                }
            }

            #endregion
        }
Beispiel #5
0
 public void CreateAttackBox(AttackBox NewAttackBox)
 {
     CurrentLayer.AddProjectile(NewAttackBox);
 }