コード例 #1
0
    public static void CheckGhostStartThresholds()
    {
        var ghostController = GameObject.Find(ObjectNames.GhostController);

        if (!BlueGhostActive)
        {
            var blueGhost = ghostController.transform.FindChild(ObjectNames.BlueGhost).gameObject;
            if ((Pellets.TotalNumberOfPellets - Pellets.NumberOfPelletsRemaining()) >= 30)
            {
                Debug.Log("BLUE GHOST: At least 30 pellets have been eaten, started moving");
                blueGhost.SetActive(true);
                BlueGhostActive = true;
            }
        }


        if (!OrangeGhostActive)
        {
            int numberOfPelletsEaten   = Pellets.TotalNumberOfPellets - Pellets.NumberOfPelletsRemaining();
            int percentagePelletsEaten = (int)Math.Round((double)(100 * numberOfPelletsEaten) / Pellets.TotalNumberOfPellets);
            if (percentagePelletsEaten >= OrangeGhost.PercentageOfPelletsEaten)
            {
                var orangeGhost = ghostController.transform.FindChild(ObjectNames.OrangeGhost).gameObject;
                Debug.Log("ORANGE GHOST: Pellets eaten has reached threshold, started moving!");
                orangeGhost.SetActive(true);
                OrangeGhostActive = true;
            }
        }
    }
コード例 #2
0
ファイル: GameGrid.cs プロジェクト: ciaran036/ChompMan
        void Start()
        {
            Text = ReadGameGrid();
            Pellets.Load();

            Width  = Text[0].Length;
            Height = Text.Length;
            Grid   = new GridPiece[Width, Height];

            int x = 0;
            int z = 0;

            foreach (var line in Text)
            {
                foreach (char cell in line)
                {
                    switch (cell)
                    {
                    case '-':
                        Grid[x, z] = GridPiece.Pellet;
                        break;

                    case 'P':
                        Grid[x, z] = GridPiece.PowerPellet;
                        break;

                    case 'X':
                        Grid[x, z] = GridPiece.EmptySpace;
                        break;

                    case 'I':
                    case 'i':
                        Grid[x, z] = GridPiece.Intersection;
                        break;

                    case 'W':
                        Grid[x, z] = GridPiece.Wall;
                        break;

                    case 'L':
                        Grid[x, z] = GridPiece.LeftPortal;
                        break;

                    case 'R':
                        Grid[x, z] = GridPiece.RightPortal;
                        break;

                    case 'H':
                        Grid[x, z] = GridPiece.GhostHome;
                        break;
                    }
                    x++;
                }
                x = 0;
                z++;
            }
        }
コード例 #3
0
    public void Play()
    {
        // reset target pellet if pellet not target not exist anymore
        foreach (Pac pa in GetMyPacs().Where(p => p.Action.HasAction).ToList())
        {
            if (!Grid.Map[(int)pa.Action.TargetPosition.X, (int)pa.Action.TargetPosition.Y].HasPellet)
            {
                pa.Action = new Action();
            }
        }

        // IF there is BIG pellets, go get them
        List <Pellet> bigPellets = Pellets.Where(p => p.Value == 10).ToList();

        foreach (Pellet pe in bigPellets)
        {
            Pac pa = GetMyPacs().OrderBy(p => p.Distance(pe)).First();
            if (!pa.Action.HasAction || pe.Distance(pa) < pa.Distance(pa.Action.TargetPosition))
            {
                pa.Move(pe);
            }
        }

        // Else set the nearest not targeted pellet
        foreach (Pac p in GetMyPacs())
        {
//		if (!p.Action.HasAction)
            if (!p.Action.HasAction || (p.Action.TargetEntity is Pellet pel && pel.Value == 1))
            {
                List <Pellet> AlreadyTargeted = GetMyPacs().Select(e => e.Action.TargetEntity).Where(e => e != null).Cast <Pellet>().ToList();

                p.Move(GetVisiblePelletsNearest(p).Except(AlreadyTargeted).FirstOrDefault());

                ///  PROBABLY BETTER WITHOUT WHEN SEVERAL PAC
                if (!p.Action.HasAction)
                {
                    p.Move(GetVisiblePelletsNearest(p).FirstOrDefault());
                }
            }
            // If can't see pellets go where we never go
            if (!p.Action.HasAction)
            {
                List <Entity> AlreadyTargeted = GetMyPacs().Where(e => e.Id != p.Id).Select(e => e.Action.TargetEntity).ToList();

                var target = Grid.Map.Cast <Cell>().Where(e => e.HasPellet).Select(e => e.Inside).Cast <Pellet>()
                             .Except(AlreadyTargeted).OrderBy(e => p.Distance(e.Position)).FirstOrDefault();
                if (target != null)
                {
                    p.Move(target.Position);
                }
            }
        }

        // If speed, be sure to target the second nearest pellet from the first one
        foreach (Pac p in GetMyPacs().FindAll(p => p.SpeedTurnsLeft > 0))
        {
            if (p.Distance(p.Action.TargetPosition) <= 1)
            {
                p.Move(SPEED_GetNearestPelletFromPellet(p.Action.TargetPosition));
            }
        }


        // If can speed, Override and speed
        GetMyPacs().FindAll(p => p.AbilityCooldown == 0).ForEach(p => p.Speed());

        //Say Hi
        foreach (Pac p in GetMyPacs())
        {
            if (GetOpponentPacs().Any(o => this.IsDirectPath(p, o)))
            {
                p.Label = "Hi !";
            }
        }



        if (GetMyPacs().First().Positions.Count() > 2)
        {
            List <Pac> blockedPacs =
                GetMyPacs().Where(e => e.Positions.Last() == e.Positions.TakeLast(2).First() &&
                                  e.PreviousAction.IsMove).ToList();

            Debug(blockedPacs.Count() + "");
            foreach (Pac p in blockedPacs.ToList())
            {
                Debug("Pac " + p.Id + "Blocked");
                blockedPacs.Remove(p);

                List <Pac> otherBlockedNear = blockedPacs.FindAll(e => e.Distance(p) < 1.5);

                otherBlockedNear.ForEach(e => e.Action = new Action(e.Position));
                //blockedPacs.RemoveRange(otherBlockedNear);
            }
        }



        // foreach (Pac p in GetMyPacs())
        // {
        //  p.Label = p.Type.ToString();
        // }


        // foreach (Pac p in GetMyPacs())
        // {
        //  // if (p.Positions.Count() < 3)
        //  //  continue;
        //  List<Vector2> lastPos = p.Positions.TakeLast(3).ToList();

        //  // Debug(lastPos.First().ToString());
        //  // Debug(lastPos.Last().ToString());
        //  Debug( "HERE " + lastPos.Count().ToString());
        //  // Debug(p.Positions.Count().ToString());
        //  if (lastPos.Count() == 3 && p.PreviousAction.Type != eAction.Switch
        //  &&  lastPos.First() == lastPos.Last()
        //  &&  lastPos.First() == lastPos.Skip(1).First()
        //  )
        //      p.SwitchClockwise();
        // }

        this.ExecuteActions();
    }
コード例 #4
0
    public void Play()
    {
        // reset target pellet if pellet not target not exist anymore
        foreach (Pac pa in GetMyPacs().Where(p => p.Action.HasAction).ToList())
        {
            if (!Grid.Map[(int)pa.Action.TargetPosition.X, (int)pa.Action.TargetPosition.Y].HasPellet)
            {
                pa.Action = new Action();
            }
        }

        // IF there is BIG pellets, go get them
        List <Pellet> bigPellets = Pellets.Where(p => p.Value == 10).ToList();

        foreach (Pellet pe in bigPellets)
        {
            Pac pa = GetMyPacs().OrderBy(p => p.Distance(pe)).First();
            if (!pa.Action.HasAction || pe.Distance(pa) < pa.Distance(pa.Action.TargetPosition))
            {
                pa.Move(pe);
            }
        }

        // Else set the nearest not targeted pellet
        foreach (Pac p in GetMyPacs())
        {
            if (!p.Action.HasAction)
            {
                List <Pellet> AlreadyTargeted = GetMyPacs().Select(e => e.Action.TargetEntity).Where(e => e != null).Cast <Pellet>().ToList();

                p.Move(GetVisiblePelletsNearest(p).Except(AlreadyTargeted).FirstOrDefault());

                ///  PROBABLY BETTER WITHOUT WHEN SEVERAL PAC
                if (!p.Action.HasAction)
                {
                    p.Move(GetVisiblePelletsNearest(p).FirstOrDefault());
                }
            }
            // If can't see pellets go where we never go
            if (!p.Action.HasAction)
            {
                List <Entity> AlreadyTargeted = GetMyPacs().Where(e => e.Id != p.Id).Select(e => e.Action.TargetEntity).ToList();

                var target = Grid.Map.Cast <Cell>().Where(e => e.HasPellet).Select(e => e.Inside).Cast <Pellet>()
                             .Except(AlreadyTargeted).OrderBy(e => p.Distance(e.Position)).FirstOrDefault();
                if (target != null)
                {
                    p.Move(target.Position);
                }
            }
        }

        // If speed, be sure to target the second nearest pellet from the first one
        foreach (Pac p in GetMyPacs().FindAll(p => p.SpeedTurnsLeft > 0))
        {
            if (p.Distance(p.Action.TargetPosition) <= 1)
            {
                p.Move(SPEED_GetNearestPelletFromPellet(p.Action.TargetPosition));
            }
        }


        // If can speed, Override and speed
        GetMyPacs().FindAll(p => p.AbilityCooldown == 0).ForEach(p => p.Speed());

        //Say Hi
        foreach (Pac p in GetMyPacs())
        {
            if (GetOpponentPacs().Any(o => this.IsDirectPath(p, o)))
            {
                p.Label = "Hi !";
            }
        }

        this.ExecuteActions();
    }
コード例 #5
0
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            position = parent.CenterPoint;

            for (int i = 0; i < pellet_count; i++)
            {
                if (shotgun_pellets[i].active == true)
                {
                    shotgun_pellets[i].update(parentWorld, currentTime, parent);

                    if (shotgun_pellets[i].hit_enemy && !damage_delay_flag)
                    {
                        damage_delay_flag  = true;
                        damage_delay_timer = 0.0f;
                    }
                }
            }

            if (pellet_count == max_pellets)
            {
                inactive_pellets = 0;
                for (int i = 0; i < pellet_count; i++)
                {
                    if (shotgun_pellets[i].active == false)
                    {
                        inactive_pellets++;
                    }
                }

                if (inactive_pellets == max_pellets)
                {
                    pellet_count = 0;
                }
            }

            if (shotgun_active == false && (parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= 5)
            {
                switch (parent.Direction_Facing)
                {
                case GlobalGameConstants.Direction.Right:
                    pellet_angle_direction = (float)(-1 * Math.PI / 12);
                    break;

                case GlobalGameConstants.Direction.Left:
                    pellet_angle_direction = (float)(Math.PI / 1.09);
                    break;

                case GlobalGameConstants.Direction.Up:
                    pellet_angle_direction = (float)(-1 * Math.PI / 1.74);
                    break;

                default:
                    pellet_angle_direction = (float)(Math.PI / 2.4);
                    break;
                }

                AudioLib.playSoundEffect(shot_gun_sound);
                parentWorld.Particles.pushShotGunCasing(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGun" : "lGun").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGun" : "lGun").WorldY));

                for (int i = 0; i < max_pellets; i++)
                {
                    parent.Animation_Time = 0;
                    float angle = (float)((Game1.rand.Next() % pellet_angle_interval) + pellet_angle_direction);

                    if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Right_Item : GameCampaign.Player2_Item_1) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                    {
                        shotgun_pellets[i]             = new Pellets(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY), angle);
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lShotgun" : "rShotgun");

                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= 1;
                        }
                        else if (parent.Index == InputDevice2.PPG_Player.Player_2)
                        {
                            GameCampaign.Player2_Ammunition -= 1;
                        }
                    }
                    else if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Left_Item : GameCampaign.Player2_Item_2) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                    {
                        shotgun_pellets[i]             = new Pellets(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldY), angle);
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rShotgun" : "lShotgun");

                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= 1;
                        }
                        else if (parent.Index == InputDevice2.PPG_Player.Player_2)
                        {
                            GameCampaign.Player2_Ammunition -= 1;
                        }
                    }

                    pellet_count++;
                }
                shotgun_active       = true;
                shotgun_active_timer = 0.0f;
            }
            parent.State = Player.playerState.Moving;
        }