public bool IsSpriteViewable(AbstractHumanoid viewerSprite, AbstractHumanoid viewedSprite, AbstractMap map, int fov)
        {
            Dictionary <AbstractHumanoid, bool> viewedList;

            if (!internalList.TryGetValue(viewerSprite, out viewedList))
            {
                viewedList = new Dictionary <AbstractHumanoid, bool>();
                internalList.Add(viewerSprite, viewedList);
            }

            bool isViewed;

            if (!viewedList.TryGetValue(viewedSprite, out isViewed))
            {
                isViewed = Optics.IsSpriteViewable(viewerSprite, viewedSprite, map, fov);
                viewedList.Add(viewedSprite, isViewed);
            }

            return(isViewed);
        }
Esempio n. 2
0
        /// <summary>
        /// Make walk sprite
        /// </summary>
        /// <param name="sprite">sprite</param>
        /// <param name="angleOffsetRadian">angle offset (default 0) (in radian)</param>
        /// <param name="spritePool">other sprites</param>
        /// <param name="map">map</param>
        /// <param name="timeDelta">time delta</param>
        public static bool TryMakeWalk(AbstractSprite sprite, double angleOffsetRadian, SpritePool spritePool, AbstractMap map, double timeDelta)
        {
            double xMove = Math.Cos(sprite.AngleRadian + angleOffsetRadian) * sprite.DefaultWalkingDistance * timeDelta;
            double yMove = Math.Sin(sprite.AngleRadian + angleOffsetRadian) * sprite.DefaultWalkingDistance * timeDelta;

            if (sprite is AbstractHumanoid)
            {
                AbstractHumanoid humanoid = (AbstractHumanoid)sprite;
                humanoid.WalkCycle.UnFire();
                humanoid.WalkCycle.Fire();
                humanoid.WalkCycle.Update(1);

                if (humanoid.IsCrouch)
                {
                    xMove *= humanoid.CrouchSpeedMultiplier;
                    yMove *= humanoid.CrouchSpeedMultiplier;
                }

                //If is attacking and not jumping
                if (humanoid.StrongAttackCycle.IsFired && humanoid.PositionZ <= 0)
                {
                    xMove *= humanoid.AttackWalkSpeedMultiplier;
                    yMove *= humanoid.AttackWalkSpeedMultiplier;
                }
            }

            //If is jump
            if (sprite.PositionZ > 0)
            {
                xMove *= sprite.JumpSpeedMultiplier;
                yMove *= sprite.JumpSpeedMultiplier;
            }

            sprite.PositionX += xMove;

            bool isDetectCollisionX = IsDetectCollision(sprite, spritePool, map);

            if (isDetectCollisionX)
            {
                sprite.PositionX -= xMove;
            }

            sprite.PositionY += yMove;

            bool isDetectCollisionY = IsDetectCollision(sprite, spritePool, map);

            if (isDetectCollisionY)
            {
                sprite.PositionY -= yMove;
            }

            return(!(isDetectCollisionX || isDetectCollisionY));
        }
Esempio n. 3
0
 /// <summary>
 /// Whether sprite is in collision with another sprite or the map
 /// </summary>
 /// <param name="sprite">sprite</param>
 /// <param name="spritePool">sprite pool</param>
 /// <param name="map">map</param>
 /// <returns>Whether sprite is in collision with another sprite or the map</returns>
 public static bool IsDetectCollision(AbstractSprite sprite, SpritePool spritePool, AbstractMap map)
 {
     return(IsDetectSpriteCollision(sprite, spritePool) || IsDetectMapCollision(sprite, map));
 }
Esempio n. 4
0
        private void Update(AbstractHumanoid sprite, SpritePool spritePool, AbstractHumanoid currentPlayer, AbstractMap map, double timeDelta, out bool isNeedRefreshHud)
        {
            isNeedRefreshHud = false;


            sprite.ReceivedAttackCycle.Update(timeDelta);

            //We manage received attack
            if (sprite.ReceivedAttackCycle.GetCycleState() > 0)
            {
                Physics.TryMakeWalk(sprite, sprite.ReceivedAttackAngleRadian - sprite.AngleRadian, spritePool, map, 1);
                sprite.IsNeedToJumpAgain = false;
                Physics.MakeJump(sprite, timeDelta);
                sprite.Health -= sprite.LatestAttackerDamage;

                if (!sprite.IsAlive)
                {
                    isNeedRefreshHud = true;
                    sprite.LatestAttacker.FragCount++;
                    currentPlayer.RefreshRanking(spritePool);
                }

                if (sprite == currentPlayer)
                {
                    isNeedRefreshHud = true;
                }
            }
            else
            {
                sprite.ReceivedAttackCycle.UnFire();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Make walk sprite
 /// </summary>
 /// <param name="sprite">sprite</param>
 /// <param name="spritePool">other sprites</param>
 /// <param name="map">map</param>
 /// <param name="timeDelta">time delta</param>
 public static bool TryMakeWalk(AbstractSprite sprite, SpritePool spritePool, AbstractMap map, double timeDelta)
 {
     return(TryMakeWalk(sprite, 0, spritePool, map, timeDelta));
 }
Esempio n. 6
0
        public void Animate(AbstractHumanoid predator, AbstractMap map, SpritePool spritePool, SharedConsciousness sharedConsciousness, double timeDelta, int fov, Random random, AbstractHumanoid currentPlayer)
        {
            AbstractHumanoid prey;

            if (random.Next(howManyFrameBeforeChoosingPreyAgain) == 0)
            {
                prey = TryChoosePrey(predator, spritePool, sharedConsciousness, map, fov, currentPlayer);
                predator.LatestSelectedPrey = prey;
            }
            else
            {
                prey = predator.LatestSelectedPrey;
            }


            predator.IsNeedToJumpAgain = false;
            predator.IsBlock           = false;

            byte currentStateJumpCrouch = predator.StateJumpCrouch.GetCurrentState();

            //We manage jumping state
            if (currentStateJumpCrouch == SpriteStates.Jump)
            {
                predator.IsCrouch = false;
                Physics.MakeJump(predator, timeDelta);
            }

            //We manage crouch state
            if (currentStateJumpCrouch == SpriteStates.Crouch)
            {
                predator.IsCrouch = true;
            }


            //We manage standing state
            if (currentStateJumpCrouch == SpriteStates.Stand)
            {
                predator.IsCrouch          = false;
                predator.IsNeedToJumpAgain = false;
            }

            //We manage walking
            if (prey != null)
            {
                if (random.Next(5) == 0 && !predator.SpinAttackCycle.IsFired)
                {
                    predator.AngleRadian = Optics.GetSpriteAngleToSpriteRadian(predator, prey);
                }

                byte currentAttackBlockState = predator.StateAttackBlock.GetCurrentState();
                byte currentAttackTypeState  = predator.StateAttackType.GetCurrentState();
                byte currentMovementState    = predator.StateMovement.GetCurrentState();

                if (currentAttackBlockState == SpriteStates.SpinCharge)
                {
                    predator.StateAttackType.Reset();
                }

                if (predator.SpinChargeAttackCycle.IsFired)
                {
                    currentAttackBlockState = SpriteStates.SpinCharge;
                }


                if (currentMovementState == SpriteStates.Offensive)
                {
                    Physics.TryMakeWalk(predator, spritePool, map, timeDelta);
                }
                else if (currentMovementState == SpriteStates.Defensive)
                {
                    Physics.TryMakeWalk(predator, Math.PI, spritePool, map, timeDelta);
                }
                else if (currentMovementState == SpriteStates.FurtiveLeft)
                {
                    Physics.TryMakeWalk(predator, Math.PI * 1.5, spritePool, map, timeDelta);
                }
                else if (currentMovementState == SpriteStates.FurtiveRight)
                {
                    Physics.TryMakeWalk(predator, Math.PI * 0.5, spritePool, map, timeDelta);
                }



                //We manage attacking,  and blocking
                bool isWithinAttackRange        = BattlePhysics.IsWithinAttackRange(predator, prey);
                bool isWithinAttackOrBlockAngle = BattlePhysics.IsInAttackOrBlockAngle(predator, prey);


                if (currentAttackBlockState == SpriteStates.Block && predator.PositionZ > 0)
                {
                    currentAttackBlockState = SpriteStates.Attack;
                }

                if (isWithinAttackRange || isWithinAttackOrBlockAngle)
                {
                    if (predator.ReceivedAttackCycle.IsAtBegining)
                    {
                        if (currentAttackBlockState == SpriteStates.Attack)
                        {
                            if (currentAttackTypeState == SpriteStates.FastAttack)
                            {
                                if (random.Next(2) == 1)
                                {
                                    if (BattlePhysics.IsWithinAttackRange(predator, prey, 1.5) && isWithinAttackOrBlockAngle)
                                    {
                                        predator.FastAttackCycle.UnFire();
                                        predator.FastAttackCycle.Fire();
                                    }
                                }
                            }
                            else if (currentAttackTypeState == SpriteStates.StrongAttack)
                            {
                                if (random.Next(2) == 1)
                                {
                                    if (BattlePhysics.IsWithinAttackRange(predator, prey, 1.5) && isWithinAttackOrBlockAngle)
                                    {
                                        predator.StrongAttackCycle.UnFire();
                                        predator.StrongAttackCycle.Fire();
                                    }
                                }
                            }
                            predator.SpinChargeAttackCycle.Reset();
                        }
                        else if (currentAttackBlockState == SpriteStates.SpinCharge)
                        {
                            if (IsReadyToSpin(predator) && BattlePhysics.IsWithinAttackRange(predator, prey, 1.5))
                            {
                                if (random.Next(3) == 1)
                                {
                                    predator.SpinAttackCycle.Reset();
                                    predator.SpinAttackCycle.Fire();
                                    predator.SpinChargeAttackCycle.Reset();
                                    predator.StateAttackBlock.Reset();
                                }
                            }
                            else if (!predator.SpinAttackCycle.IsFired)
                            {
                                if (predator.SpinChargeAttackCycle.IsFired)
                                {
                                    predator.SpinChargeAttackCycle.Update(timeDelta);
                                }
                                else
                                {
                                    predator.SpinChargeAttackCycle.Fire();
                                }
                            }
                        }
                        else if (currentAttackBlockState == SpriteStates.Block && !predator.SpinAttackCycle.IsFired)
                        {
                            predator.StrongAttackCycle.UnFire();
                            predator.SpinAttackCycle.UnFire();
                            predator.SpinChargeAttackCycle.Reset();
                            predator.FastAttackCycle.UnFire();
                            predator.IsBlock = true;
                        }
                        else
                        {
                            predator.SpinChargeAttackCycle.Reset();
                        }
                    }
                }


                predator.StateAttackBlock.Update(timeDelta, random);
                predator.StateAttackType.Update(timeDelta, random);
                predator.StateMovement.Update(timeDelta, random);
            }
            else
            {
                if (!predator.SpinAttackCycle.IsFired && !Physics.TryMakeWalk(predator, spritePool, map, timeDelta))
                {
                    predator.AngleDegree = (double)random.Next(360);
                }
            }

            predator.StateJumpCrouch.Update(timeDelta, random);
        }
Esempio n. 7
0
        private AbstractHumanoid TryChoosePrey(AbstractHumanoid predator, SpritePool spritePool, SharedConsciousness sharedConsciousness, AbstractMap map, int fov, AbstractHumanoid currentPlayer)
        {
            AbstractHumanoid closestPrey     = null;
            double           closestDistance = -1;

            foreach (AbstractHumanoid prey in spritePool)
            {
                if (prey == predator)
                {
                    continue;
                }

                //if (!Physics.IsWithinAttackRange(predator, prey) && !sharedConsciousness.IsSpriteViewable(predator, prey, map, fov))
                //    continue;


                if (sharedConsciousness.IsSpriteViewable(predator, prey, map, fov) || (sharedConsciousness.IsSpriteViewable(prey, predator, map, fov) && predator.LatestAttacker == prey))
                {
                    double currentDistance = Physics.GetSpriteDistance(predator, prey);

                    if (closestPrey == null || currentDistance < closestDistance)
                    {
                        closestPrey     = prey;
                        closestDistance = currentDistance;
                    }
                }
            }

            return(closestPrey);
        }
Esempio n. 8
0
 public override void Update(double timeDelta, SpritePool spritePool, AbstractMap map)
 {
     BattlePhysics.MoveProjectile(this, spritePool, map, timeDelta);
 }
 public Point GetRandomAvailableLocation(AbstractMap map, SpritePool spritePool, Random random)
 {
     return(internalCache[random.Next(internalCache.Count)]);
 }
Esempio n. 10
0
        /// <summary>
        /// Throw a projectile sprite
        /// </summary>
        /// <param name="projectile">projectile sprite</param>
        /// <param name="spritePool">sprite pool</param>
        /// <param name="map">map</param>
        /// <param name="timeDelta">time delta</param>
        public static void MoveProjectile(AbstractProjectile projectile, SpritePool spritePool, AbstractMap map, double timeDelta)
        {
            double xMove = Math.Cos(projectile.AngleRadian) * projectile.DefaultWalkingDistance * timeDelta;
            double yMove = Math.Sin(projectile.AngleRadian) * projectile.DefaultWalkingDistance * timeDelta;

            projectile.PositionX += xMove;
            projectile.PositionY += yMove;
        }