/// <summary>
        /// Initializes an enemy on a position. This method can be override to add more functionality
        /// </summary>
        /// <param name="enemy">Initialized enemy</param>
        /// <param name="container">Container when will be added</param>
        /// <param name="initialPosition">Position inside the layer</param>
        public virtual CSKEnemy InitializeEnemy(CSKEnemy enemy, CCNode container, CCPoint initialPosition)
        {
            enemy.Position = initialPosition;
            enemy.ScaleX = -1;
            enemy.actionState = ActionState.Idle;

            enemy.desiredPosition = enemy.Position;
            enemy.idle();

            container.AddChild(enemy);
            Enemies.Add(enemy);
            return enemy;
        }
 public virtual void Step(CSKPlayer player, CSKEnemy enemy, CCSize wSize, float dt)
 {
     throw new NotImplementedException("Custom IA its not instanciated on the Game Layer");
 }
 /// <summary>
 /// Initializes an enemy on a random position map. This method can be override to add more functionality
 /// </summary>
 /// <param name="robot">Initialized enemy</param>
 /// <param name="container">Container when will be added</param>
 public virtual CSKEnemy InitializeEnemy(CSKEnemy enemy, CCNode container)
 {
     return InitializeEnemy(enemy, container, GetRandomPosition(enemy));
 }
Beispiel #4
0
        public override void Step(CSKPlayer player, CSKEnemy enemy, CCSize wSize, float dt)
        {
            if (!enemy.klass.IsIA)
                return;

            //int alive = 0;
            float distanceSQ;
            int randomChoice = 0;
            enemy.Update(dt);

            if (enemy.actionState != ActionState.KnockedOut)
            {
                if (enemy.HasPassedDecisionTime())
                {
                    CCPoint pos = player.Position;
                    //distanceSQ = enemy.Position.DistanceSQ(ref pos);
                    distanceSQ = enemy.DistanceSQ(player);

                    //3
                    if (enemy.DistanceSQ(player, 50 * 50))
                    {
                        enemy.SetNextDecisionTime(1, 5);

                        RandomChoice(rnd =>
                        {
                            if (rnd)
                                enemy.idle();
                            else
                            {
                                if (player.IsOnRight(enemy))
                                    enemy.SetFlip(true);
                                else
                                    enemy.SetFlip(false);

                                //4
                                enemy.attack();
                                if (enemy.actionState == ActionState.Attack)
                                {
                                    if (Math.Abs(player.PositionY - enemy.PositionY) < 10)
                                    {
                                        if (player.AbsoluteHitBoxRect.IntersectsRect(enemy.AbsoluteAttackBoxRect))
                                        {
                                            CCEventCustom eventHurts = new CCEventCustom(EVENT_IA_PLAYER_HURTS, enemy);
                                            if (layer != null)
                                                layer.DispatchEvent(eventHurts);
                                        }
                                    }
                                }
                            }
                        });

                        randomChoice = CCRandom.GetRandomInt(0, 1);
                    }
                    else if (distanceSQ <= wSize.Width * wSize.Width)
                    {
                        //5
                        enemy.SetNextDecisionTime(1, 5);
                        randomChoice = CCRandom.GetRandomInt(0, 2);
                        if (randomChoice == 0)
                        {
                            CCPoint moveDirection = CCPoint.Normalize(player.Position - enemy.Position);
                            enemy.moveWithDirection(moveDirection);
                        }
                        else
                        {
                            enemy.idle();
                        }
                    }
                }
            }
        }
 public virtual string GetEnemyIAInfo(CSKEnemy enemy)
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
 public override string GetEnemyIAInfo(CSKEnemy enemy)
 {
     // return string.Format("{0}{1}", (enemy.IsIA) ? "IA ENABLED" : "IA DISABLED", enemy.IA_INFO);
     return "";
 }
Beispiel #7
0
 public bool IsOnTop(CSKEnemy enemy)
 {
     return PositionY < enemy.PositionX;
 }
Beispiel #8
0
 public bool IsOnRight(CSKEnemy enemy)
 {
     return PositionX > enemy.PositionX;
 }
Beispiel #9
0
 public bool IsOnLeft(CSKEnemy enemy)
 {
     return PositionX < enemy.PositionX;
 }
Beispiel #10
0
 public bool IsOnBottom(CSKEnemy enemy)
 {
     return PositionY > enemy.PositionX;
 }