示例#1
0
 public GameState(Player p1, Player p2, float health, List<Platform> platforms, Goal goal)
 {
     this.p1 = p1;
     this.p2 = p2;
     this.health = health;
     this.platforms = platforms;
     this.goal = goal;
 }
        public List<Tuple<GameObject, GameObject>> CombinedPlatformPath(
            Player start1, Player start2, GameObject end1, GameObject end2)
        {
            var cacheKey = Tuple.Create (start1, start2, end1, end2);

            List<Tuple<GameObject, GameObject>> path;

            if (paths.ContainsKey(cacheKey)) {
                path = paths[cacheKey];
            } else {
            //                Debug.Print ("p2: {0}", start2);
            //                Debug.Print("platsBelow 1: {0}", PlatformUtil.PlatListStr(PlatformUtil.platsBelow (Platforms, start1)));
            //                Debug.Print("platsBelow 2: {0}", PlatformUtil.PlatListStr(PlatformUtil.platsBelow (Platforms, start2)));

                var platsBelow1 = PlatformUtil.platsBelow (Platforms, start1);
                var platsBelow2 = PlatformUtil.platsBelow (Platforms, start2);

                var plats1 = platsBelow1.Count () > 0 ? platsBelow1 : Platforms;
                var plats2 = platsBelow2.Count () > 0 ? platsBelow2 : Platforms;

                var startPlat1 = PlatformUtil.nearestReachablePlatform (start1, plats1);
                var startPlat2 = PlatformUtil.nearestReachablePlatform (start2, plats2);

            //                Debug.Print ("startPlat1: {0}", startPlat1);
            //                Debug.Print ("startPlat2: {0}", startPlat2);

            //                Debug.WriteLineIf (endReachablePlatforms1.Count == 0, "No platforms within reach of the 1st goal!");
            //                Debug.WriteLineIf (endReachablePlatforms2.Count == 0, "No platforms within reach of the 2nd goal!");

                path = runAStar (startPlat1, startPlat2, end1, end2).Select (p2g).ToList ();

                path.Add (Tuple.Create (end1, end2));

            //                Debug.Print ("ppls: {0}", PlatformUtil.PlatPairListStr (path));

                paths [cacheKey] = path;
            }

            return path;
        }
        public GameObject NextPlatform(Player player, GameObject end)
        {
            var path = PlatformPath (player, end);

            GameObject next;

            if (path.Count == 1) {
                next = path.First ();
            } else {
                var plat0 = path [0];
                var plat1 = path [1];

                var between0and1 = plat1.Distance(plat0) > plat1.Distance(player);
                var closeEnough = player.Distance(plat0) < (1 * Player.Size.X) && player.Y >= plat0.Y;
                var unreachable1 = PlatformUtil.unreachable (Platforms, player, plat1);
                var bothAbove = plat1.TopBoundary > player.BottomBoundary && plat0.TopBoundary > player.BottomBoundary;

                next = (!bothAbove && !unreachable1 && (between0and1 || closeEnough)) ? plat1 : plat0;
            }

            return next;
        }
        public List<GameObject> PlatformPath(Player start, GameObject end)
        {
            var tup = Tuple.Create (start, end);

            List<GameObject> path;

            if (paths.ContainsKey(tup)) {
                path = paths[tup];
            } else {
                var startPlat = PlatformUtil.nearestReachablePlatform (start, Platforms);

                var endReachablePlatforms = Platforms.FindAll (p => PlatformUtil.adjacent (Platforms, p, end));

                Debug.WriteLineIf (endReachablePlatforms.Count == 0, "No platforms within reach of the goal!");

                var endPlat = PlatformUtil.nearestPlatform (end.Center, endReachablePlatforms);

                path = runAStar (startPlat, endPlat).Concat(end).ToList<GameObject>();

                paths[tup] = path;
            }

            return path;
        }
        public Tuple<GameObject, GameObject> NextPlatform(Player player1, Player player2, GameObject end1, GameObject end2)
        {
            var path = CombinedPlatformPath (player1, player2, end1, end2);

            Tuple<GameObject, GameObject> next;

            if (path.Count == 1) {
                next = path.First ();
            } else {
                next = shouldGoNext(player1, path[0].Item1, path[1].Item1) ||
                       shouldGoNext(player2, path[0].Item2, path[1].Item2) ? path[1] : path[0];
            }

            return next;
        }
        private bool shouldGoNext(Player player, GameObject plat0, GameObject plat1)
        {
            var between0and1 = plat1.Distance(plat0) > plat1.Distance(player);
            var closeEnough = player.Distance(plat0) < (1 * Player.Size.X) && player.Y >= plat0.Y;
            var unreachable1 = PlatformUtil.unreachable (Platforms, player, plat1);
            var bothAbove = plat1.TopBoundary > player.BottomBoundary && plat0.TopBoundary > player.BottomBoundary;

            return !bothAbove && !unreachable1 && (between0and1 || closeEnough);
        }
示例#7
0
 public void DrawPos(Player p, int x, int y)
 {
     var str = String.Format ("coord P{0}: {1:F1}", p.Id, p.Coords);
     spriteBatch.DrawString(SpriteFont, str, new Vector2(x, y), Color.DarkViolet);
 }
示例#8
0
        public void DrawPlayer(Player p)
        {
            Point pt = RasterizeCoords (p);
            Color color1, color2;

            if (p.Id == 1) {
                color1 = Color.DarkSlateGray;
                color2 = Color.LightGray;
            } else { //Id == 2
                color1 = Color.LightGray;
                color2 = Color.DarkSlateGray;
            }

            DrawGameObjectRect (p, color1);
            spriteBatch.DrawString(spriteFont, p.Id.ToString(), pt.ToVector2(), color2, 0, Vector2.Zero,
                                   scale: 2.0f, effects: SpriteEffects.None, layerDepth: 0);
        }
示例#9
0
        public void DrawButtonArrow(Player p, Input input, Color c)
        {
            var size = new Vector2 (1f, 0.5f) * Player.Size;

            double rotation = 0;
            Vector2 offset;

            //            Debug.WriteLine ("{0}: {1}", input.shortString(), input.ToInt);

            switch (input.ToInt) {
            case 1: //Input.Up.ToInt:
                rotation = 0;
                offset = new Vector2 (0, 1);
                break;
            case 2: //Input.Right.ToInt:
                rotation = 0.5;
                offset = new Vector2 (1, 0);
                break;
            case 3: //Input.UpRight.ToInt:
                rotation = 0.25;
                offset = new Vector2 (1, 1);
                break;
            case 4: //Input.Left.ToInt:
                rotation = -.5;
                offset = new Vector2 (-1, 0);
                break;
            case 5: //Input.UpLeft.ToInt:
                rotation = -.25;
                offset = new Vector2 (-1, 1);
                break;
            default: // This can happen when pressing left/right at the same time
                rotation = 1;
                offset = new Vector2 (0, -1);
            //                throw new KeyNotFoundException ();
                break;
            }

            DrawTriangle (size, p.Center + (offset * Player.Size), (float)(Math.PI*rotation), c);
        }
示例#10
0
 private bool inGoal(Player p)
 {
     return Util.euclideanDistance (p.Center, goal.Coords) <= goal.Radius;
 }
示例#11
0
 public bool IsGrounded(Player player)
 {
     return IsGrounded (Platforms, player);
 }
示例#12
0
 public GameState Clone(
     Player p1 = null,
     Player p2 = null,
     float health = float.NegativeInfinity,
     PlayStatus status = null,
     List<Platform> platforms = null,
     Goal goal = null
 )
 {
     return new GameState(
         p1: p1 == null ? this.p1 : p1,
         p2: p2 == null ? this.p2 : p2,
         health: health == float.NegativeInfinity ? this.Health : health,
         platforms: platforms == null ? this.platforms : platforms,
         goal: goal == null ? this.goal : goal
     );
 }
示例#13
0
        public static bool IsGrounded(IEnumerable<Platform> platforms, Player player)
        {
            return platforms.Any (plat => {

                var horizontal =
                    plat.RightBoundary >= player.LeftBoundary &&
                    plat.LeftBoundary <= player.RightBoundary;

                var vertical = Math.Abs (player.BottomBoundary - plat.TopBoundary) < 0.1;

                return horizontal && vertical;
            });
        }