Пример #1
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();
            }
        }
Пример #2
0
        public World(Random random, int monsterCount)
        {
            this.monsterCount = monsterCount;
            this.random       = random;
            spawner           = new Spawner(random);
            //map = new HardCodedMap();
            //map = new CachedWaveMap(random);
            map        = new MapFromImage("CvmFight/Assets/Maps/CvmMap.png", random);
            spritePool = new SpritePool(currentPlayer);

            sharedConsciousness = new SharedConsciousness(spritePool.Count);

            for (int i = 0; i < monsterCount; i++)
            {
                int randomNumber = random.Next(3);
                if (randomNumber == 0)
                {
                    spritePool.Add(new MonsterStickMan());
                }
                else if (randomNumber == 1)
                {
                    spritePool.Add(new MonsterNutKunDo());
                }
                else
                {
                    spritePool.Add(new MonsterAladdin());
                }
            }

            spawner.TryRespawn(spritePool, map);
        }
Пример #3
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);
        }
Пример #4
0
 public void Update(SpritePool spritePool, SharedConsciousness sharedConsciousness, AbstractHumanoid currentPlayer)
 {
     foreach (AbstractHumanoid sprite in spritePool)
     {
         Update(sprite, spritePool, sharedConsciousness, currentPlayer);
     }
 }
Пример #5
0
        public override void Update(double timeDelta, SpritePool spritePool, AbstractMap map)
        {
            isJustReceivedStrongPunch = false;
            isJustReceivedStrongKick  = false;
            isJustReceivedFastAttack  = false;

            if (spinAttackCycle.IsFired)
            {
                if (spinAttackCycle.IsAtBegining)
                {
                    AngleAtBeginingOfSpinAttackRadian = AngleRadian;
                }
                else if (spinAttackCycle.IsAtParoxism)
                {
                    AngleRadian = AngleAtBeginingOfSpinAttackRadian;
                }
                else
                {
                    AngleRadian = BattlePhysics.BuildSpinAttackRotation(AngleAtBeginingOfSpinAttackRadian, spinAttackCycle.PercentComplete);
                }
            }

            strongAttackCycle.Update(timeDelta);
            fastAttackCycle.Update(timeDelta);
            blockSuccessCycle.Update(timeDelta);
            spinAttackCycle.Update(timeDelta);

            Physics.MakeFall(this, timeDelta);
        }
Пример #6
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;
        }
Пример #7
0
 public void Update(SpritePool spritePool, AbstractHumanoid currentPlayer, AbstractMap map, double timeDelta)
 {
     foreach (AbstractHumanoid sprite in spritePool)
     {
         bool currentSpriteNeedRefreshHud;
         Update(sprite, spritePool, currentPlayer, map, timeDelta, out currentSpriteNeedRefreshHud);
     }
 }
Пример #8
0
 public void TryRespawn(SpritePool spritePool, AbstractMap map)
 {
     foreach (AbstractHumanoid sprite in spritePool)
     {
         if (!sprite.IsAlive)
         {
             Respawn(sprite, map, spritePool);
         }
     }
 }
Пример #9
0
 public void RefreshRanking(SpritePool spritePool)
 {
     ranking = 1;
     foreach (AbstractHumanoid sprite in spritePool)
     {
         if (fragCount < sprite.fragCount)
         {
             ranking++;
         }
     }
 }
Пример #10
0
 /// <summary>
 /// Whether sprite is in collision with sprite pool
 /// </summary>
 /// <param name="sprite">sprite</param>
 /// <param name="spritePool">sprite pool</param>
 /// <returns>Whether sprite is in collision with sprite pool</returns>
 public static bool IsDetectSpriteCollision(AbstractSprite sprite, SpritePool spritePool)
 {
     foreach (AbstractHumanoid otherSprite in spritePool)
     {
         if (sprite != otherSprite)
         {
             if (IsDetectSpriteCollision(sprite, otherSprite))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #11
0
        private void Respawn(AbstractHumanoid fighter, AbstractMap map, SpritePool spritePool)
        {
            if (this.map != map)
            {
                this.map = map;
                emptyMapLocationCache = new EmptyMapLocationCache(this.map);
            }

            Point point;

            do
            {
                point             = emptyMapLocationCache.GetRandomAvailableLocation(map, spritePool, random);
                fighter.PositionX = (double)point.X + 0.5;
                fighter.PositionY = (double)point.Y + 0.5;
            } while (Physics.IsDetectCollision(fighter, spritePool, map));

            fighter.Health      = fighter.DefaultHealth;
            fighter.AngleDegree = random.Next(360);
            fighter.ReceivedAttackCycle.Reset();
        }
Пример #12
0
        public GameViewer3D(Surface mainSurface, int screenWidth, int screenHeight, int columnCount, SpritePool spritePool, int fov, Random random, AbstractMap map, bool isSoundOn, EcholocationCycle echolocationCycle, EcholocationBeeper echolocationBeeper)
        {
            this.mainSurface = mainSurface;
            this.isSoundOn   = isSoundOn;
            this.random      = random;
            minimap          = new MiniMap(screenWidth, screenHeight, map);

            this.screenWidth  = screenWidth;
            this.screenHeight = screenHeight;

            this.gradient = new Gradient(screenWidth, screenHeight * 2);

            columnViewer = new ColumnViewer(this.screenWidth, this.screenHeight, columnCount, heightDistanceRatio, echolocationCycle, echolocationBeeper);
        }
Пример #13
0
 public abstract void Update(double timeDelta, SpritePool spritePool, AbstractMap abstractMap);
Пример #14
0
        private void Update(AbstractHumanoid attacker, SpritePool spritePool, SharedConsciousness sharedConsciousness, AbstractHumanoid currentPlayer)
        {
            bool   IsAttackerAttackAtParoxism;
            double damage;
            bool   isFastAttack = false;

            if (attacker.StrongAttackCycle.IsAtParoxism)
            {
                damage = attacker.AttackPowerStrong;
                IsAttackerAttackAtParoxism = true;
            }
            else if (attacker.FastAttackCycle.IsAtParoxism)
            {
                damage = attacker.AttackPowerFast;
                IsAttackerAttackAtParoxism = true;
                isFastAttack = true;
            }
            else if (attacker.SpinAttackCycle.IsFired)
            {
                damage = attacker.AttackPowerStrong;
                IsAttackerAttackAtParoxism = true;
            }
            else
            {
                return;
            }



            if (IsAttackerAttackAtParoxism && attacker.ReceivedAttackCycle.GetCycleState() <= 0)
            {
                foreach (AbstractHumanoid attacked in spritePool)
                {
                    if (attacked == attacker)
                    {
                        continue;
                    }

                    if (BattlePhysics.IsWithinAttackRange(attacker, attacked))
                    {
                        if (BattlePhysics.IsInAttackOrBlockAngle(attacker, attacked))
                        {
                            if (BattlePhysics.IsInAttackHeight(attacker, attacked))
                            {
                                if (!attacked.IsBlock || !BattlePhysics.IsInAttackOrBlockAngle(attacked, attacker) || !BattlePhysics.IsInBlockingHeight(attacked, attacker))
                                {
                                    //We abort attacked's attack
                                    attacked.FastAttackCycle.Reset();
                                    attacked.StrongAttackCycle.Reset();
                                    attacked.BlockSuccessCycle.Reset();
                                    attacked.SpinChargeAttackCycle.Reset();
                                    attacked.SpinAttackCycle.Reset();

                                    attacked.FastAttackCycle.IsNeedToClickAgain   = true;
                                    attacked.StrongAttackCycle.IsNeedToClickAgain = true;

                                    attacked.ReceivedAttackAngleRadian = attacker.AngleRadian;
                                    attacked.ReceivedAttackCycle.Fire();

                                    if (isFastAttack)
                                    {
                                        attacked.ReceivedAttackCycle.PercentComplete = 0.25;
                                        attacked.ReceivedAttackCycle.IsForward       = false;
                                        attacked.IsJustReceivedFastAttack            = true;
                                    }
                                    else
                                    {
                                        if (attacker.IsCrouch || attacker.PositionZ >= 0)
                                        {
                                            attacked.IsJustReceivedStrongKick = true;
                                        }
                                        else
                                        {
                                            attacked.IsJustReceivedStrongPunch = true;
                                        }
                                    }

                                    attacked.LatestAttacker       = attacker;
                                    attacked.LatestAttackerDamage = damage;

                                    if (!(attacked is Player))
                                    {
                                        attacked.StateJumpCrouch.Reset();
                                        attacked.StateMovement.Reset();
                                        attacked.StateAttackBlock.Reset();
                                        if (attacked.StateAttackBlock.GetCurrentState() == SpriteStates.SpinCharge)
                                        {
                                            attacked.StateAttackBlock.Reset();
                                        }
                                    }

                                    if (!(attacker is Player))
                                    {
                                        attacker.StateJumpCrouch.Renew();
                                        attacker.StateMovement.Renew();
                                        attacker.StateAttackBlock.Renew();
                                    }
                                }
                                else if (attacked.IsBlock)
                                {
                                    attacked.BlockSuccessCycle.Reset();
                                    attacked.BlockSuccessCycle.Fire();
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #15
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));
 }
Пример #16
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));
        }
Пример #17
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));
 }
Пример #18
0
 public Point GetRandomAvailableLocation(AbstractMap map, SpritePool spritePool, Random random)
 {
     return(internalCache[random.Next(internalCache.Count)]);
 }
Пример #19
0
 public override void Update(double timeDelta, SpritePool spritePool, AbstractMap map)
 {
     BattlePhysics.MoveProjectile(this, spritePool, map, timeDelta);
 }
Пример #20
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);
        }