Example #1
0
 public void RemoveBalloon(Balloon b)
 {
     balloons.Remove(b);
     if(balloons.Count == 0 && exit == null)
     {
         NextLevel();
     }
 }
Example #2
0
        private void ParseMap(ref Map map, World world, ContentManager content, out Vector2 unoPos, out ExitPortal exit)
        {
            var layerCount = map.Layers.Count;
            Vector2 tempUnoPos = new Vector2();
            ExitPortal tmpExitPortal = null;

            xTile.Layers.Layer platformLayer = map.Layers.First((x) => x.Id == "Platform Layer");
            xTile.Layers.Layer moveablePlatformLayer = map.Layers.First((x) => x.Id == "Movable Platform Layer");
            xTile.Layers.Layer zoneLayer = map.Layers.First((x) => x.Id == "Zones Layer");
            xTile.Layers.Layer zone2Layer = map.Layers.FirstOrDefault((x) => x.Id == "Zones2 Layer");
            xTile.Layers.Layer startLayer = map.Layers.First((x) => x.Id == "Start Position Layer");
            xTile.Layers.Layer balloonLayer = map.Layers.First((x) => x.Id == "Balloon Layer");
            xTile.Layers.Layer speedLayer = map.Layers.First((x) => x.Id == "Speed Modifier Layer");
            xTile.Layers.Layer timeLayer = map.Layers.FirstOrDefault((x) => x.Id == "Time Modifier Layer");
            xTile.Layers.Layer triggerLayer = map.Layers.First((x) => x.Id == "Trigger Groups");
            xTile.Layers.Layer portalLayer = map.Layers.FirstOrDefault((x) => x.Id == "Portal Layer");

            ParseTiles(platformLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                foreach(var aggregate in aggregates)
                {
                    if(aggregate.type == "Wall" || aggregate.type == "Magnetic Wall")
                    {
                        Rectangle rect = aggregate.rect;
                        walls.Add(new Walls(aggregate.color, world, (uint)rect.Width, (uint)rect.Height, new Point(rect.X, rect.Y), true));
                    }
                }
            });

            ParseTiles(startLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                foreach(var aggregate in aggregates)
                {
                    if(aggregate.type == "Uno")
                    {
                        float tileSize = GameManager.TILE_SIZE;
                        Rectangle rect = aggregate.rect;
                        tempUnoPos = new Vector2(rect.X*tileSize, rect.Y*tileSize);
                    }
                }
            });

            Dictionary<Point, TileAggregate> pointToZoneAggregate = null;
            ParseTiles(zoneLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                pointToZoneAggregate = pointToAggregate;
            });

            if(zone2Layer != null)
            {
                ParseTiles(zone2Layer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
                {
                    foreach(var keyPair in pointToAggregate)
                    {
                        pointToZoneAggregate[keyPair.Key] = keyPair.Value;
                    }
                });
            }

            Dictionary<Point, TileAggregate> pointToSpeedAggregate = null;
            ParseTiles(speedLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                pointToSpeedAggregate = pointToAggregate;
            });

            Dictionary<Point, TileAggregate> pointToTimeAggregate = null;
            if(timeLayer != null)
            {
                ParseTiles(timeLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
                {
                    pointToTimeAggregate = pointToAggregate;
                });
            }
            else
            {
                pointToTimeAggregate = new Dictionary<Point, TileAggregate>();
            }

            Dictionary<string, List<IActivateable>> activators = new Dictionary<string, List<IActivateable>>();
            Dictionary<Point, TileAggregate> pointToTriggerAggregate = null;
            ParseTiles(triggerLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                pointToTriggerAggregate = pointToAggregate;
            });

            ParseTiles(moveablePlatformLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                foreach(var aggregate in aggregates)
                {
                    if(aggregate.type == "Wall" || aggregate.type == "Magnetic Wall")
                    {
                        Rectangle rect = aggregate.rect;

                        Point origin = rect.Location;
                        Point destination = origin;
                        TileAggregate zone;
                        if(pointToZoneAggregate.TryGetValue(origin, out zone))
                        {
                            bool zoneIsWide = zone.rect.Width > zone.rect.Height;
                            if(zone.rect.Location == origin)
                            {
                                if(zoneIsWide)
                                    origin = new Point(zone.rect.Right-rect.Width, rect.Y);
                                else
                                    origin = new Point(rect.X, zone.rect.Bottom-rect.Height);
                            }
                            else
                            {
                                if(zoneIsWide)
                                    origin = new Point(zone.rect.X, rect.Y);
                                else
                                    origin = new Point(rect.X, zone.rect.Y);
                            }
                        }

                        TileAggregate speedAggregate;
                        string speedName;
                        float speed = WALL_SPEEDS[0];
                        if(pointToSpeedAggregate.TryGetValue(new Point(rect.X, rect.Y), out speedAggregate)
                                && speedAggregate.type == "Speed Modifier"
                                && speedAggregate.properties.TryGetValue("Speed", out speedName))
                        {
                            switch(speedName)
                            {
                                default:
                                case "Slow":
                                    speed = WALL_SPEEDS[0];
                                    break;
                                case "Med":
                                    speed = WALL_SPEEDS[1];
                                    break;
                                case "Fast":
                                    speed = WALL_SPEEDS[2];
                                    break;
                            }
                        }

                        TileAggregate timeAggregate;
                        string timeName;
                        float time = WALL_TIMES[1];
                        if(pointToTimeAggregate.TryGetValue(new Point(rect.X, rect.Y), out timeAggregate)
                                && timeAggregate.type == "Time Modifier"
                                && timeAggregate.properties.TryGetValue("Time", out timeName))
                        {
                            switch(timeName)
                            {
                                case "Short":
                                    time = WALL_TIMES[0];
                                    break;
                                default:
                                case "Med":
                                    time = WALL_TIMES[1];
                                    break;
                                case "Long":
                                    time = WALL_TIMES[2];
                                    break;
                            }
                        }
                        MovableWall wall = new MovableWall(aggregate.color, world, (uint)rect.Width, (uint)rect.Height, origin, time, destination, speed, content);

                        walls.Add(wall);
                        TileAggregate trigger;
                        if(pointToTriggerAggregate.TryGetValue(rect.Location, out trigger))
                        {
                            string triggerNumber = trigger.properties["Number"];
                            if(!activators.ContainsKey(triggerNumber))
                                    activators[triggerNumber] = new List<IActivateable>();
                            activators[triggerNumber].Add(wall);
                        }
                    }
                }
            });

            ParseTiles(balloonLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
            {
                foreach(var aggregate in aggregates)
                {
                    if(aggregate.type == "Balloon")
                    {
                        Rectangle rect = aggregate.rect;

                        float speed = 0f;
                        int range = 0;

                        Balloon balloon;
                        switch(aggregate.color)
                        {
                            case "g":
                                {
                                    GreenBalloon greenBalloon = new GreenBalloon(new Point(rect.X, rect.Y), content);
                                    List<IActivateable> activatables;
                                    TileAggregate trigger;
                                    if(pointToTriggerAggregate.TryGetValue(rect.Location, out trigger)
                                            && activators.TryGetValue(trigger.properties["Number"], out activatables))
                                    {
                                        foreach(var a in activatables)
                                            greenBalloon.AddToActivatable(a);
                                    }
                                    balloon = greenBalloon;
                                }
                                break;
                            case "b":
                                {
                                    BlueBalloon blueBalloon = new BlueBalloon(new Point(rect.X, rect.Y), world, content, 3f);
                                    balloon = blueBalloon;
                                }
                                break;
                            case "y":
                                {
                                    speed = 1f;
                                    TileAggregate speedAggregate;
                                    string speedName;
                                    if(pointToSpeedAggregate.TryGetValue(new Point(rect.X, rect.Y), out speedAggregate)
                                        && speedAggregate.type == "Speed Modifier"
                                        && speedAggregate.properties.TryGetValue("Speed", out speedName))
                                    {
                                        switch(speedName)
                                        {
                                            default:
                                            case "Slow":
                                                speed = BALLOON_SPEEDS[0];
                                                break;
                                            case "Med":
                                                speed = BALLOON_SPEEDS[1];
                                                break;
                                            case "Fast":
                                                speed = BALLOON_SPEEDS[2];
                                                break;
                                        }
                                    }

                                    TileAggregate zone;
                                    if(pointToZoneAggregate.TryGetValue(new Point(rect.X, rect.Y), out zone)
                                        && zone.color == "r")
                                    {
                                        //Start at left side
                                        rect.X = zone.rect.X;
                                        rect.Y = zone.rect.Y;
                                        //Go for horizontal width of zone
                                        range = zone.rect.Width;
                                    }

                                }
                                goto default;
                            default:
                                balloon = new Balloon(new Point(rect.X, rect.Y), content, aggregate.color, speed, range);
                                break;
                        }

                        GameManager.getInstance().AddBalloon(balloon);
                    }
                }
            });

            if(portalLayer != null)
            {
                ParseTiles(portalLayer, delegate(List<TileAggregate> aggregates, Dictionary<Point, TileAggregate> pointToAggregate)
                {
                    foreach(var aggregate in aggregates)
                    {
                        if(aggregate.type == "Exit")
                        {
                            float tileSize = GameManager.TILE_SIZE;
                            Rectangle rect = aggregate.rect;
                            tmpExitPortal = new ExitPortal(rect.Location);
                        }
                    }
                });
            }

            //Remove Non Static Layers
            if(portalLayer != null)
                map.RemoveLayer(portalLayer);
            map.RemoveLayer(triggerLayer);
            if(timeLayer != null)
                map.RemoveLayer(timeLayer);
            map.RemoveLayer(speedLayer);
            map.RemoveLayer(balloonLayer);
            map.RemoveLayer(startLayer);
            map.RemoveLayer(moveablePlatformLayer);
            if(zone2Layer != null)
                map.RemoveLayer(zone2Layer);
            map.RemoveLayer(zoneLayer);

            unoPos = tempUnoPos;
            exit = tmpExitPortal;
        }
Example #3
0
 public void AddBalloon(Balloon b)
 {
     balloons.Add(b);
 }