Esempio n. 1
0
        /// <summary>
        /// Initializes a player on a initial position inside a container
        /// </summary>
        /// <param name="player">Instanciated player</param>
        /// <param name="container">Container when will be dropped</param>
        /// <param name="initialPosition">Player initial position</param>
        public virtual CSKPlayer InitializePlayer(CSKPlayer player, CCNode container, CCPoint initialPosition)
        {
            if (Players.Exists((p) => p == player))
            {
                Console.WriteLine("CANNOT ADD PLAYER. ITS ON LAYER");
                return null;
            }

            CCGameSettingsBase.Instance.Player1 = player.klass; //TODO: ARRAY DE PLAYERS

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

            Players.Add(player); //Add to players array

            Player = player;

            container.AddChild(player);

            //AddChild(player, (int)eTAG_DEPTH.PLAYER_LAYER);

            player.Position = initialPosition;

            Console.WriteLine("PLAYER 1 ADDED TO SHIP LAYER");
            return player;
        }
Esempio n. 2
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();
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public virtual void Step(CSKPlayer player, List<CSKEnemy> enemies, CCSize wSize, float dt)
 {
     throw new NotImplementedException("Custom IA its not instanciated on the Game Layer");
 }
Esempio n. 4
0
 public override void Step(CSKPlayer player, List<CSKEnemy> enemies, CCSize wSize, float dt)
 {
     // int alive = 0;
     foreach (CSKEnemy enemy in enemies)
         Step(player, enemy, wSize, dt);
 }