GetLayer() public méthode

Gets a layer by name.
public GetLayer ( string name ) : TiledLib.Layer
name string The name of the layer to retrieve.
Résultat TiledLib.Layer
Exemple #1
0
        public TriggerController(Map gameMap)
        {
            Instance = this;

            MapObjectLayer triggerLayer = gameMap.GetLayer("Triggers") as MapObjectLayer;

            foreach (MapObject o in triggerLayer.Objects)
            {
                triggers.Add(new Trigger()
                {
                    Object = o,
                    HasTriggered = false
                });
            }

            triggerLayer = gameMap.GetLayer("Valves") as MapObjectLayer;

            foreach (MapObject o in triggerLayer.Objects)
            {
                valves.Add(new Trigger()
                {
                    Object = o,
                    HasTriggered = false,
                    Position = new Vector2(o.Location.Center.X, o.Location.Center.Y),
                    Speed = new Vector2(3f, 0.1f)
                });
            }
        }
Exemple #2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            blank = new Texture2D(GraphicsDevice, 1, 1);
            blank.SetData(new[] { Color.White });

            // load the map
            map = Content.Load<Map>("Map");

            // find the "Box" and "Point" objects we made in the level
            MapObjectLayer objects = map.GetLayer("Objects") as MapObjectLayer;
            point = objects.GetObject("Point");
            box = objects.GetObject("Box");

            // attempt to read the box color from the box object properties
            try
            {
                boxColor.R = (byte)box.Properties["R"];
                boxColor.G = (byte)box.Properties["G"];
                boxColor.B = (byte)box.Properties["B"];
                boxColor.A = 255;
            }
            catch
            {
                // on failure, default to yellow
                boxColor = Color.Yellow;
            }

            // find one tile from our tile layer
            TileLayer tileLayer = map.GetLayer("Tiles") as TileLayer;
            tile = tileLayer.Tiles[0, 0];
        }
Exemple #3
0
        private void LoadMap(string assetName)
        {
            //List of Portals declared for traveling between World map and scrolling levels
            Statics.Portals = new List<Portal>();
            
            Statics.ClipMap = new Dictionary<Vector2, Rectangle>();

            map = content.Load<Map>(assetName);

            camera = new WorldMapCamera(new Vector2(map.Width, map.Height), new Vector2(map.TileWidth, map.TileHeight), new Vector2(Statics.Game.GraphicsDevice.Viewport.Width, Statics.Game.GraphicsDevice.Viewport.Height));

            MapObjectLayer objects = map.GetLayer("Objects") as MapObjectLayer;
            
            //Read in information about portals from tmx file
            foreach (MapObject obj in objects.Objects)
            {
                switch (obj.Name)
                {
                    case "PlayerStart":
                        if (Statics.WorldPlayer == null)
                        {
                            Statics.WorldPlayer = new WorldPlayer(new Vector2(obj.Location.X + (obj.Location.Width / 2), obj.Location.Y), new Vector2(91f, 91f));
                            Statics.WorldPlayer.LoadContent(content, "Sprites\\Characters\\Warrior1WalkLeft");
                            Statics.WorldPlayer.Map = map;
                        }
                        else
                        {
                            Statics.WorldPlayer.Position = new Vector2(obj.Location.X + (obj.Location.Width / 2), obj.Location.Y);
                        }
                        break;
                    case "Portal1":
                    case "Portal2":
                    case "Portal3":
                    case "Portal4":
                        Portal portal = new Portal();
                        portal.Position = new Vector2(obj.Location.X, obj.Location.Y);
                        portal.Size = new Vector2(obj.Location.Width, obj.Location.Height);
                        portal.LevelName = obj.Properties["LevelName"].Value;
                        string[] tileLoc = obj.Properties["DestinationTileLocation"].Value.Split(',');
                        portal.DestinationTileLocation = new Vector2(Convert.ToInt32(tileLoc[0]), Convert.ToInt32(tileLoc[1]));
                        Statics.Portals.Add(portal);
                        break;
                }
            }

            Statics.WorldPlayer.UpdateBounds(map.TileWidth, map.TileHeight);
    //        camera.FocusOn(Statics.WorldPlayer);

            LoadClipMap();
        }
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            map = content.Load<Map>("map");
            MapObject spawn = ((MapObjectLayer) map.GetLayer("spawn")).Objects[0];

            camera = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map);
            camera.Target = new Vector2(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight)/2f;

            heroPool = new EntityPool(100,
                                      sheet => new Hero(sheet, new Rectangle(0, 0, 10, 10), new Vector2(0, -5)),
                                      content.Load<Texture2D>("testhero"));
            heroPool.CollidesWith.Add(heroPool);

            particleController.LoadContent(content);

            // TimerController.Instance.Create("shake", () => camera.Shake(500, 2f), 3000, true);

            TweenController.Instance.Create("spintext", TweenFuncs.SineEaseInOut, (tween) =>
            {
                textScale = 0.8f+ (tween.Value *0.4f);
            }, 3000, true, true);

            //// More crazy tween examples
            //TweenController.Instance.Create("spincam", TweenFuncs.Linear, (tween) =>
            //{
            //    camera.Rotation = MathHelper.TwoPi * tween.Value;
            //}, 10000, false, true, TweenDirection.Reverse);

            //TweenController.Instance.Create("zoomcam", TweenFuncs.Bounce, (tween) =>
            //{
            //    camera.Zoom = 1f + tween.Value;
            //}, 3000, true, true);

            particleController.Add(new Vector2(195, 150),
                                  Vector2.Zero,
                                  0, 1000, 0,
                                  false, false,
                                  new Rectangle(18, 0, 100, 100),
                                  Color.White,
                                  ParticleFunctions.PermaLight,
                                  1f, 0f,
                                  1, ParticleBlend.Multiplicative);

            base.LoadContent();
        }
Exemple #5
0
        public void UseObject(Map gameMap)
        {
            if (usingValve) return;
            if (teleporting) return;
            if (Dead) return;

            if (TriggerController.Instance.AtValve)
            {
                usingValve = true;
                valveUseTime = 0;

                PromptController.Instance.RemovePrompt("valve1");
                PromptController.Instance.RemovePrompt("valve2");

                return;
            }

            MapObjectLayer portalLayer = gameMap.GetLayer("Portals") as MapObjectLayer;

            foreach (MapObject o in portalLayer.Objects)
            {
                if (o.Location.Contains(Helper.VtoP(Position)))
                {
                    if (Convert.ToInt16(o.Properties["In"]) == Layer)
                    {
                        teleportingDir = Convert.ToInt16(o.Properties["Out"]);
                        teleporting = true;
                        teleportScale = 1f;
                        AudioController.PlaySFX("teleport_in", 0.6f, 0f, 0f);
                        return;
                    }
                    if (Convert.ToInt16(o.Properties["Out"]) == Layer)
                    {
                        teleportingDir = Convert.ToInt16(o.Properties["In"]);
                        teleporting = true;
                        teleportScale = 1f;
                        AudioController.PlaySFX("teleport_in", 0.6f, 0f, 0f);
                        return;
                    }
                }
            }
        }
Exemple #6
0
        public static void Generate(Map gameMap)
        {
            TileLayer layer = (TileLayer)gameMap.GetLayer("fg");

            for(int x=0;x<gameMap.Width;x++)
                for (int y = 0; y < gameMap.Height; y++)
                {
                    layer.Tiles[x, y] = null;
                    if (y == gameMap.Height - 1) layer.Tiles[x, y] = gameMap.Tiles[EDGE_UP];

                }

            int numIslands = Helper.Random.Next(2) == 0 ? Helper.Random.Next(2) == 0 ? 2 : 3 : 5;

            for (int island = 0; island < numIslands; island++)
            {
                int spacing = gameMap.Width/(numIslands + 1);
                int islandwidth = (gameMap.Width/2)/numIslands;

                Point islandCenter = new Point(spacing * (island+1), 16);

                if (island == 0) islandCenter.X -= 5;
                if (island == numIslands-1) islandCenter.X += 5;

                List<Point> cps = new List<Point>();

                cps.Add(new Point(islandCenter.X - (islandwidth/2), islandCenter.Y));

                int numcps = 2 + Helper.Random.Next(2);
                for (int i = 0; i < numcps; i++)
                    cps.Add(new Point(((islandCenter.X - (islandwidth/2)) + ((islandwidth/(numcps + 1))*(i+1)) + (-2 + Helper.Random.Next(4))),
                                  islandCenter.Y - 2 - Helper.Random.Next(10)));

                cps.Add(new Point(islandCenter.X + (islandwidth/2), islandCenter.Y));

                for (int p = 0; p < cps.Count-1; p++)
                {
                    Vector2 pos = Helper.PtoV(cps[p]);
                    for (float d = 0f; d <= 1f; d += 0.02f)
                    {
                        pos = Vector2.Lerp(Helper.PtoV(cps[p]), Helper.PtoV(cps[p + 1]), d);
                        Point thistile = Helper.VtoP(pos);
                        for(int y=thistile.Y;y<=islandCenter.Y;y++)
                            layer.Tiles[thistile.X, y] = gameMap.Tiles[CENTER_BLOCK];
                    }
                }

                cps = new List<Point>();

                cps.Add(new Point(islandCenter.X - (islandwidth / 2), islandCenter.Y));

                numcps = 2 + Helper.Random.Next(2);
                for (int i = 0; i < numcps; i++)
                    cps.Add(new Point(((islandCenter.X - (islandwidth / 2)) + ((islandwidth / (numcps + 1)) * (i + 1)) + (-2 + Helper.Random.Next(4))),
                                  islandCenter.Y + 2 + Helper.Random.Next(8)));

                cps.Add(new Point(islandCenter.X + (islandwidth / 2), islandCenter.Y));

                for (int p = 0; p < cps.Count - 1; p++)
                {
                    Vector2 pos = Helper.PtoV(cps[p]);
                    for (float d = 0f; d <= 1f; d += 0.02f)
                    {
                        pos = Vector2.Lerp(Helper.PtoV(cps[p]), Helper.PtoV(cps[p + 1]), d);
                        Point thistile = Helper.VtoP(pos);
                        for (int y = thistile.Y; y >= islandCenter.Y; y--)
                            layer.Tiles[thistile.X, y] = gameMap.Tiles[CENTER_BLOCK];
                    }
                }

            }

            // Remove stray tiles
            for (int y = 0; y < gameMap.Height; y++)
            {
                for (int x = 0; x < gameMap.Width; x++)
                {
                    if (layer.Tiles[x, y] != null)
                        if (CountSurroundingTiles(gameMap, layer, x, y) <= 3)
                        {
                            layer.Tiles[x, y] = null;
                        }
                }
            }

            for (int y = 0; y < gameMap.Height; y++)
            {
                for (int x = 0; x < gameMap.Width; x++)
                {

                    if (GetTileIndex(gameMap, layer, x, y) == CENTER_BLOCK)
                    {
                        // Edges
                        if (layer.Tiles[x - 1, y] == null)
                            if (layer.Tiles[x, y - 1] != null)
                                if (layer.Tiles[x, y + 1] != null) layer.Tiles[x, y] = gameMap.Tiles[EDGE_LEFT];

                        if (layer.Tiles[x + 1, y] == null)
                            if (layer.Tiles[x, y - 1] != null)
                                if (layer.Tiles[x, y + 1] != null) layer.Tiles[x, y] = gameMap.Tiles[EDGE_RIGHT];

                        if (layer.Tiles[x, y + 1] == null)
                            if (layer.Tiles[x - 1, y] != null)
                                if (layer.Tiles[x + 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[EDGE_DOWN];

                        if (layer.Tiles[x, y - 1] == null)
                            if (layer.Tiles[x - 1, y] != null)
                                if (layer.Tiles[x + 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[Helper.Random.Next(2)==0?EDGE_UP:EDGE_UP_ALT];

                        // Corners - inside
                        if (layer.Tiles[x - 1, y - 1] == null)
                            if (layer.Tiles[x, y - 1] != null)
                                if (layer.Tiles[x - 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_INSIDE_BR];

                        if (layer.Tiles[x - 1, y + 1] == null)
                            if (layer.Tiles[x, y + 1] != null)
                                if (layer.Tiles[x - 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_INSIDE_TR];

                        if (layer.Tiles[x + 1, y - 1] == null)
                            if (layer.Tiles[x, y - 1] != null)
                                if (layer.Tiles[x + 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_INSIDE_BL];

                        if (layer.Tiles[x + 1, y + 1] == null)
                            if (layer.Tiles[x, y + 1] != null)
                                if (layer.Tiles[x + 1, y] != null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_INSIDE_TL];

                        // Corners - outside
                        if (layer.Tiles[x - 1, y - 1] == null)
                            if (layer.Tiles[x, y - 1] == null)
                                if (layer.Tiles[x - 1, y] == null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_OUTSIDE_TL];

                        if (layer.Tiles[x - 1, y + 1] == null)
                            if (layer.Tiles[x, y + 1] == null)
                                if (layer.Tiles[x - 1, y] == null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_OUTSIDE_BL];

                        if (layer.Tiles[x + 1, y - 1] == null)
                            if (layer.Tiles[x, y - 1] == null)
                                if (layer.Tiles[x + 1, y] == null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_OUTSIDE_TR];

                        if (layer.Tiles[x + 1, y + 1] == null)
                            if (layer.Tiles[x, y + 1] == null)
                                if (layer.Tiles[x + 1, y] == null) layer.Tiles[x, y] = gameMap.Tiles[CORNER_OUTSIDE_BR];

                    }

                }
            }
            // Remove stray tiles
            for (int y = 0; y < gameMap.Height; y++)
            {
                for (int x = 0; x < gameMap.Width; x++)
                {
                    if (layer.Tiles[x, y] != null)
                        if (CountSurroundingTiles(gameMap, layer, x, y) <= 3)
                        {
                            layer.Tiles[x, y] = null;
                        }
                }
            }

            // add castles
            for (int x = 0; x < gameMap.Width; x++)
                for (int y = 0; y < gameMap.Height; y++)
                    if ((layer.Tiles[x, y] == gameMap.Tiles[EDGE_UP] ||layer.Tiles[x, y] == gameMap.Tiles[EDGE_UP_ALT]) &&
                        (layer.Tiles[x - 1, y] == gameMap.Tiles[EDGE_UP] || layer.Tiles[x-1, y] == gameMap.Tiles[EDGE_UP_ALT]) &&
                        (layer.Tiles[x + 1, y] == gameMap.Tiles[EDGE_UP] || layer.Tiles[x+1, y] == gameMap.Tiles[EDGE_UP_ALT]) &&
                        Helper.Random.Next(5) == 0 && y>5)
                    {
                        int tile = 0;
                        int type = Helper.Random.Next(2);
                        for(int yy=0;yy<3;yy++)
                            for (int xx = 0; xx < 3; xx++)
                            {
                                layer.Tiles[(x - 1) + xx, (y - 2) + yy] = type == 0 ? gameMap.Tiles[CASTLE_ONE[tile]] : gameMap.Tiles[CASTLE_TWO[tile]];
                                tile++;
                            }
                    }

            for(int x=5;x<gameMap.Width-5;x++)
                layer.Tiles[x, gameMap.Height-1] = gameMap.Tiles[EDGE_UP];
        }
Exemple #7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            AudioController.LoadContent(Content);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            gameMap = Content.Load<Map>("map");

            gameHud = new Hud();
            gameHud.LoadContent(Content);

            gameTriggerController = new TriggerController(gameMap);
            gamePromptController = new PromptController();
            gamePromptController.LoadContent(Content);

            blankTex = Content.Load<Texture2D>("blank");
            skyGradient = Content.Load<Texture2D>("sky-gradient");
            cloudTexture = Content.Load<Texture2D>("cloud-test");
            valveTexture = Content.Load<Texture2D>("valve");

            int layerCount = 0;
            foreach (Layer ml in gameMap.Layers)
                if (ml is TileLayer) layerCount++;

            LayerDepths = new float[layerCount];
            LayerColors = new Color[layerCount];
            float scale = 1f;
            for (int i = 0; i < LayerDepths.Length; i++)
            {
                LayerDepths[i] = scale;
                LayerColors[i] = new Color((1f - (scale * 0.5f)) * 0.4f, (1f - (scale * 0.5f)) * 0.5f, (1f - (scale * 0.5f)) * 0.9f);//Color.White * (scale * 0.5f);
                if (scale > 0f) scale -= 0.33333f;
            }

            gameHero = new Hero(Helper.PtoV((gameMap.GetLayer("Spawn") as MapObjectLayer).Objects[0].Location.Center));
            gameHero.LoadContent(Content, GraphicsDevice);

            gameCamera = new Camera(GraphicsDevice.Viewport, gameMap);
            gameCamera.Position = gameHero.Position;
            gameCamera.Target = gameHero.Position;

            for (scale = 1.5f; scale > -5f; scale -= 0.1f)
            {
                Waters.Add(new Water(GraphicsDevice, gameMap, new Rectangle(-GraphicsDevice.Viewport.Bounds.Width, (gameMap.Height * gameMap.TileHeight) - waterLevel, ((gameMap.Width * gameMap.TileWidth) * 2) + GraphicsDevice.Viewport.Bounds.Width, 400 + waterLevel), new Color(50, 128, 255), Color.Black, scale));

            }

            for (scale = 1.5f; scale > -5f; scale -= 0.1f)
            {
                Clouds.Add(new Vector4(rand.Next(1920), 1000f, scale, 0f));
            }

            ambient1 = Content.Load<SoundEffect>("sfx/ambient1").CreateInstance();
            ambient2 = Content.Load<SoundEffect>("sfx/ambient2").CreateInstance();
            water = Content.Load<SoundEffect>("sfx/water").CreateInstance();

            ambient1.Volume = 0f;
            ambient2.Volume = 0f;
            water.Volume = 0f;
            ambient1.IsLooped = true;
            ambient2.IsLooped = true;
            water.IsLooped = true;
            ambient1.Play();
            ambient2.Play();
            water.Play();
        }
Exemple #8
0
        public void Initialize(Map map, Game game)
        {
            mapa = map;
            _solidos = mapa.GetLayer("Solidos") as TileLayer;
            _listaPlayers = new List<Player>();
            _game = game;

            //Sonidos
            _impacto = _game.Content.Load<SoundEffect>("sound/SFX/Impacto");
        }
Exemple #9
0
        public virtual void Update(GameTime gameTime, Map gameMap, bool[,] mapFog, HeroDude gameHero)
        {
            if (!Dead)
            {
                checkColTime += gameTime.ElapsedGameTime.TotalMilliseconds;

                DoCollisions(gameMap, gameHero);

                Position += Speed;

                Position.X = MathHelper.Clamp(Position.X, 50, (gameMap.Width * gameMap.TileWidth) - 50);
                Position.Y = MathHelper.Clamp(Position.Y, 50, (gameMap.Height * gameMap.TileHeight) - 50);

                if (Speed.Length() > 0f)
                {
                    Animations["feet"].Update(gameTime);
                    Animations["arms"].Update(gameTime);
                    Animations["head"].Update(gameTime);

                    if ((Animations["feet"].CurrentFrame == 0 || Animations["feet"].CurrentFrame == 3) && (Position - gameHero.Position).Length() < 700f && Animations["feet"].CurrentFrameTime==0)
                    {
                        // Footsteps
                        Tile t = ((TileLayer)gameMap.GetLayer("Terrain")).Tiles[(int)(Position.X / gameMap.TileWidth), (int)(Position.Y / gameMap.TileWidth)];
                        if (t.Properties.Contains("fstep"))
                        {
                            footSteps[t.Properties["fstep"]].Volume = 0.2f;
                            footSteps[t.Properties["fstep"]].Pitch = -0.3f + ((float)Helper.Random.NextDouble() * (0.6f));
                            footSteps[t.Properties["fstep"]].Pan = MathHelper.Clamp((Vector2.Transform(Position, Camera.Instance.CameraMatrix).X - (Camera.Instance.Width / 2)) / (Camera.Instance.Width / 2), -1f, 1f);
            #if(OPENGL)
                            if (t.Properties.Contains("fstep")) { footSteps[t.Properties["fstep"]].Stop(); footSteps[t.Properties["fstep"]].Play(); }
            #else
                            AudioController.PlaySFX("fstep-" + t.Properties["fstep"], 0.2f, -0.3f, 0.3f, Position);
            #endif
                        }
                    }
                }
                else
                {
                    Animations["feet"].Reset();
                    Animations["arms"].Reset();
                    Animations["head"].Reset();
                }

                Animations["hands"].CellRect.X = 100 * Animations["hands"].CurrentFrame;
                Animations["gun"].CellRect.X = 100 * Animations["gun"].CurrentFrame;

                Speed = Vector2.Zero;

                foreach (Weapon w in Weapons) w.Update(gameTime);

                if (Weapons[SelectedWeapon] is Knife)
                {
                    if (Weapons[SelectedWeapon].coolDown > 0 && Weapons[SelectedWeapon].coolDown < 100) Animations["hands"].CurrentFrame = 1;
                    else if (Weapons[SelectedWeapon].coolDown >= 100 && Weapons[SelectedWeapon].coolDown < 200) Animations["hands"].CurrentFrame = 2;
                    else if (Weapons[SelectedWeapon].coolDown >= 200 && Weapons[SelectedWeapon].coolDown < 300) Animations["hands"].CurrentFrame = 3;
                    else Animations["hands"].CurrentFrame = 0;

                    Animations["gun"].CurrentFrame = 0;

                }
                else
                {
                    Animations["hands"].CurrentFrame = 3;
                    Animations["gun"].CurrentFrame = Weapons[SelectedWeapon].sortOrder;
                }

            }

            Health = MathHelper.Clamp(Health, 0f, 100f);
            Ammo = (int)MathHelper.Clamp(Ammo, 0, 100);

            if (Dead)
            {
                deadTime -= gameTime.ElapsedGameTime.TotalMilliseconds;

            }

            insideBuilding = null;
            foreach (Compound c in gameMap.Compounds)
                foreach (Building b in c.Buildings)
                    if (b.Type == BuildingType.Building)
                    {
                        Point pos = Helper.VtoP(Position / 100);
                        if (b.Rect.Contains(pos)) insideBuilding = b;
                    }
        }
Exemple #10
0
        public static void Generate(Map gameMap)
        {
            const float deviation = 40f;

            List<Point> trackLine = new List<Point>();
            List<Point> innerTrack = new List<Point>();
            List<Point> outerTrack = new List<Point>();

            List<Point> controlPoints = new List<Point>();

            int mapWidth = gameMap.Width*gameMap.TileWidth;
            int mapHeight = gameMap.Height*gameMap.TileHeight;

            controlPoints.Add(new Point(0, mapHeight / 2) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point((mapWidth / 8) + Helper.Random.Next(mapWidth / 6), (mapHeight / 8) + Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth/2, 0) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point(((mapWidth / 8) * 7) - Helper.Random.Next(mapWidth / 6), (mapHeight / 8) + Helper.Random.Next(mapHeight /6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth, mapHeight/2) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point(((mapWidth / 8) * 7) - Helper.Random.Next(mapWidth / 6), ((mapHeight / 8)*7) - Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));
            controlPoints.Add(new Point(mapWidth/2, mapHeight) + new Point(Helper.Random.Next((int) deviation) - ((int) deviation/2), Helper.Random.Next((int) deviation) - ((int) deviation/2)));
            if (Helper.Random.Next(2) == 0)
                controlPoints.Add(new Point((mapWidth / 8) + Helper.Random.Next(mapWidth / 6), ((mapHeight / 8) * 7) - Helper.Random.Next(mapHeight / 6)) + new Point(Helper.Random.Next((int)deviation) - ((int)deviation / 2), Helper.Random.Next((int)deviation) - ((int)deviation / 2)));

            for (int i = 0; i < controlPoints.Count; i++)
            {
                trackLine.Add(controlPoints[i]);
                for (float d = 0.25f; d <= 0.75f; d += 0.25f)
                {
                    int nextPoint = i + 1;
                    if (nextPoint == controlPoints.Count) nextPoint = 0;
                    Vector2 newPoint = Vector2.Lerp(Helper.PtoV(controlPoints[i]), Helper.PtoV(controlPoints[nextPoint]),d);

                    newPoint.X = Helper.RandomFloat(newPoint.X - deviation, newPoint.X + deviation);
                    newPoint.Y = Helper.RandomFloat(newPoint.Y - deviation, newPoint.Y + deviation);

                    trackLine.Add(Helper.VtoP(newPoint));
                }
            }

            foreach (var p in trackLine)
            {
                float width = Helper.RandomFloat(0.8f, 0.95f);
                Point newP =  p - new Point(mapWidth/2,mapHeight/2);
                newP.X = (int)((float)newP.X * width);
                newP.Y = (int)((float)newP.Y * width);
                newP += new Point(mapWidth / 2, mapHeight / 2);
                innerTrack.Add(newP);
            }

            foreach (var p in trackLine)
            {
                float width = Helper.RandomFloat(1.05f, 1.2f);
                Point newP = p - new Point(mapWidth / 2, mapHeight / 2);
                newP.X = (int)((float)newP.X * width);
                newP.Y = (int)((float)newP.Y * width);
                newP += new Point(mapWidth / 2, mapHeight / 2);
                outerTrack.Add(newP);
            }

            var track = (MapObjectLayer)gameMap.GetLayer("Tris");
            for (int i = 0; i < trackLine.Count; i++)
            {
                float triDev = 5f;

                Vector2 start = Helper.PtoV(outerTrack[i]);
                Vector2 end = Helper.PtoV(i + 1 < outerTrack.Count ? outerTrack[i + 1] : outerTrack[0]);

                List<Point> polyPoints;

                float up = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) - MathHelper.PiOver2;
                float down = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + MathHelper.PiOver2;
                Vector2 startdownvect = Helper.PointOnCircle(start, 3f, down);
                Vector2 enddownvect = Helper.PointOnCircle(end, 3f, down);
                Vector2 startupvect = Helper.PointOnCircle(start, 3f, up);
                Vector2 endupvect = Helper.PointOnCircle(end, 3f, up);
                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startdownvect),
                        Helper.VtoP(startupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startupvect),
                        Helper.VtoP(endupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                for (float d = 0f; d <1f; d += 0.1f)
                {
                    Vector2 p1 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(-0.3f, -0.1f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    Vector2 p2 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(0.1f, 0.3f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    float a = (float) Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) + Helper.RandomFloat((-MathHelper.PiOver2-MathHelper.PiOver4),-MathHelper.PiOver4);
                    Vector2 off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(10f, 60f), a);
                    off += new Vector2(Helper.RandomFloat(-triDev*5f, triDev*5f), Helper.RandomFloat(-triDev*10f, triDev*10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    p1 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(0f, 20f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    p2 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 150f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    //p2 += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat((-MathHelper.PiOver2 - MathHelper.PiOver4), -MathHelper.PiOver4);
                    off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 150f), a);
                    //off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    //track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
                }

                start = Helper.PtoV(innerTrack[i]);
                end = Helper.PtoV(i + 1 < innerTrack.Count ? innerTrack[i + 1] : innerTrack[0]);

                up = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) - MathHelper.PiOver2;
                down = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + MathHelper.PiOver2;
                startdownvect = Helper.PointOnCircle(start, 3f, down);
                enddownvect = Helper.PointOnCircle(end, 3f, down);
                startupvect = Helper.PointOnCircle(start, 3f, up);
                endupvect = Helper.PointOnCircle(end, 3f, up);
                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startdownvect),
                        Helper.VtoP(startupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                polyPoints = new List<Point>
                    {
                        Helper.VtoP(startupvect),
                        Helper.VtoP(endupvect),
                        Helper.VtoP(enddownvect)
                    };
                track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                for (float d = 0f; d < 1f; d += 0.1f)
                {
                    Vector2 p1 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(-0.3f, -0.1f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    Vector2 p2 = Vector2.Lerp(start, end, MathHelper.Clamp(d + Helper.RandomFloat(0.1f, 0.3f), 0f, 1f));// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    float a = (float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) + Helper.RandomFloat(MathHelper.PiOver4, MathHelper.PiOver4+MathHelper.PiOver4);
                    Vector2 off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(10f, 60f), a);
                    off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2-0.1f, MathHelper.PiOver2 + 0.1f);
                    p1 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(0f, 20f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2 - 0.1f, MathHelper.PiOver2 + 0.1f);
                    p2 = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 100f), a);// + new Vector2(Helper.RandomFloat(-triDev, triDev), Helper.RandomFloat(-triDev, triDev));
                    //p2 += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));
                    a = (float)Math.Atan2(end.Y - start.Y, end.X - start.X) + Helper.RandomFloat(MathHelper.PiOver2 - 0.1f, MathHelper.PiOver2 + 0.1f);
                    off = Helper.PointOnCircle(Vector2.Lerp(p1, p2, 0.5f), Helper.RandomFloat(20f, 100f), a);
                    //off += new Vector2(Helper.RandomFloat(-triDev * 5f, triDev * 5f), Helper.RandomFloat(-triDev * 10f, triDev * 10f));

                    polyPoints = new List<Point>
                    {
                        Helper.VtoP(p1),
                        Helper.VtoP(p2),
                        Helper.VtoP(off)
                    };
                    //track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
                }

                //polyPoints = new List<Point>
                //{
                //    trackLine[i],
                //    trackLine[i]+new Point(2,0),
                //    i+1<trackLine.Count?trackLine[i+1]:trackLine[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(trackLine[i].X, trackLine[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                //polyPoints = new List<Point>
                //{
                //    innerTrack[i],
                //    innerTrack[i]+new Point(2,0),
                //    i+1<innerTrack.Count?innerTrack[i+1]:innerTrack[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(innerTrack[i].X, innerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));

                //polyPoints = new List<Point>
                //{
                //    outerTrack[i],
                //    outerTrack[i]+new Point(2,0),
                //    i+1<outerTrack.Count?outerTrack[i+1]:outerTrack[0]
                //};

                //track.Objects.Add(new MapObject("", "", new Rectangle(outerTrack[i].X, outerTrack[i].Y, 0, 0), null, polyPoints, new PropertyCollection()));
            }

            Vector2 spawn = Vector2.Lerp(Helper.PtoV(trackLine[0]), Helper.PtoV(trackLine[1]), 0.5f);
            float spawnDir = (float)Math.Atan2(Helper.PtoV(trackLine[1]).Y - Helper.PtoV(trackLine[0]).Y, Helper.PtoV(trackLine[1]).X - Helper.PtoV(trackLine[0]).X);
            var spawnLayer = ((MapObjectLayer)gameMap.GetLayer("Spawn"));
            PropertyCollection props = new PropertyCollection();
            props.Add("rot", spawnDir.ToString());
            spawnLayer.Objects.Add(new MapObject("","",new Rectangle((int)spawn.X,(int)spawn.Y,0,0), null,null, props));
        }
Exemple #11
0
        private Vector2 FindTileSpawnLoc(Map gameMap)
        {
            TileLayer fg = (TileLayer) gameMap.GetLayer("fg");

            int x = 0;
            while (true)
            {
                x = Helper.Random.Next(gameMap.Width);
                for(int y=0;y<16;y++)
                    if(fg.Tiles[x,y]== gameMap.Tiles[MapGeneration.EDGE_UP]
                        || fg.Tiles[x,y]== gameMap.Tiles[MapGeneration.EDGE_UP_ALT]
                        || fg.Tiles[x, y] == gameMap.Tiles[MapGeneration.CASTLE_ONE[1]]
                        || fg.Tiles[x, y] == gameMap.Tiles[MapGeneration.CASTLE_TWO[1]]) return new Vector2((x * gameMap.TileWidth) + 8, (y * gameMap.TileHeight) + (fg.Tiles[x, y] == gameMap.Tiles[MapGeneration.CASTLE_ONE[1]] || fg.Tiles[x, y] == gameMap.Tiles[MapGeneration.CASTLE_TWO[1]] ? 6 : 0));
            }
        }
Exemple #12
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            blank = new Texture2D(GraphicsDevice, 1, 1);
            blank.SetData(new[] { Color.White });

            // load the map. the map for this demo is 999x999 or 998,001 tiles to showcase
            // the efficient Draw(SpriteBatch, Rectangle) method.
            map = Content.Load<Map>("Map");

            // find the "Box" and "Point" objects we made in the level
            MapObjectLayer objects = map.GetLayer("Objects") as MapObjectLayer;
            point = objects.GetObject("Point");
            box = objects.GetObject("Box");

            // attempt to read the box color from the box object properties
            try
            {
                boxColor.R = (byte)box.Properties["R"];
                boxColor.G = (byte)box.Properties["G"];
                boxColor.B = (byte)box.Properties["B"];
                boxColor.A = 255;
            }
            catch
            {
                // on failure, default to yellow
                boxColor = Color.Yellow;
            }
        }
Exemple #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("font");
            hudTex = Content.Load<Texture2D>("hud");

            tilesSprite = new VoxelSprite(16, 16, 16);
            LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tilesSprite);

            gameMap = Content.Load<Map>("1");
            tileLayer = (TileLayer)gameMap.GetLayer("tiles");
            MapObjectLayer spawnLayer = (MapObjectLayer)gameMap.GetLayer("spawns");

            gameWorld = new VoxelWorld(gameMap.Width, 11, 1);

            for(int yy=0;yy<11;yy++)
                for(int xx=0;xx<12;xx++)
                    if(tileLayer.Tiles[xx,yy]!=null) gameWorld.CopySprite(xx*Chunk.X_SIZE, yy*Chunk.Y_SIZE, 0, tilesSprite.AnimChunks[tileLayer.Tiles[xx,yy].Index-1]);

            scrollColumn = 12;

            gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport);
            gameCamera.Position = new Vector3(0f, gameWorld.Y_SIZE * Voxel.HALF_SIZE, 0f);
            gameCamera.Target = gameCamera.Position;

            gameHero = new Hero();
            gameHero.LoadContent(Content, GraphicsDevice);

            enemyController = new EnemyController(GraphicsDevice);
            enemyController.LoadContent(Content, spawnLayer);
            projectileController = new ProjectileController(GraphicsDevice);
            projectileController.LoadContent(Content);
            particleController = new ParticleController(GraphicsDevice);
            powerupController = new PowerupController(GraphicsDevice);
            powerupController.LoadContent(Content);
            gameStarfield = new Starfield(GraphicsDevice);

            drawEffect = new BasicEffect(GraphicsDevice)
            {
                World = gameCamera.worldMatrix,
                View = gameCamera.viewMatrix,
                Projection = gameCamera.projectionMatrix,
                VertexColorEnabled = true,
            };
        }
Exemple #14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Room" /> class.
        /// </summary>
        /// <param name="color">The color of the map.</param>
        /// <param name="map">The map this room is based on.</param>
        /// <param name="gravity">The gravity of the room.</param>
        public Room(RoomType type, Color color, Map map, GraphicsDevice device, float gravity = DEFAULT_GRAVITY)
        {
            this.color = color;
            Gravity = gravity;
            this.map = map;
            Type = type;
            miniMapIsVisible = GameEngine.ShouldShowMinimap;

            width = map.WidthInPixels();
            height = map.HeightInPixels();
            background = new Background(type, width, height);

            /* Step 1: Load tiles from map. */
            tilesize = new Vector2(map.TileWidth, map.TileHeight);
            Debug.Assert(Math.Abs(map.WidthInPixels()%tilesize.X) < float.Epsilon,
                         "Map doesn't divide evenly into rows of tiles.");
            Debug.Assert(Math.Abs(map.HeightInPixels()%tilesize.Y) < float.Epsilon,
                         "Map doesn't divide evenly into columns of tiles.");

            tiles = new Tile[map.Height,map.Width];
            TileGrid grid = ((TileLayer) map.GetLayer(TILE_LAYER_NAME)).Tiles;
            for (int y = 0; y < map.Height; y++)
                for (int x = 0; x < map.Width; x++)
                {
                    TiledLib.Tile tile = grid[x, y];
                    tiles[y, x] = new Tile(new Vector2(x*tilesize.X, y*tilesize.Y), tilesize, tile, Color.White);
                }

            /* Step 2: Load objects from map. */

            /* Player */
            MapObject playerObj = map.FindObject((layer, obj) => obj.Name == PLAYER_OBJECT_NAME);
            Add(new Player(new Vector2(playerObj.Bounds.X, playerObj.Bounds.Y)));

            /* Ink Generators */
            IEnumerable<MapObject> generatorObjs = map.FindObjects((layer, obj) => obj.Type == GENERATOR_OBJECT_NAME);
            foreach (MapObject generatorObj in generatorObjs)
            {
                // get all the properties of the generator from the map object
                Property directionProperty;
                Debug.Assert(generatorObj.Properties.TryGetValue(DIRECTION_PROPERTY_NAME, out directionProperty),
                             "Generator with no direction.");
                Vector2? genDirection = VectorHelper.FromDirectionString(directionProperty.RawValue);
                Debug.Assert(genDirection != null, "Invalid direction name specified.");

                float genX = genDirection.Value.X > 0 ? generatorObj.Bounds.Right : generatorObj.Bounds.Left;
                float genY = genDirection.Value.Y < 0 ? generatorObj.Bounds.Bottom : generatorObj.Bounds.Top;

                bool isWaterGenerator = false;
                Property colorProperty;
                Color? genColor = Color.Transparent;
                Debug.Assert(generatorObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty),
                             "Generator with no color.");
                if (colorProperty.RawValue == WATER)
                    isWaterGenerator = true;
                else
                {
                    genColor = ColorHelper.FromString(colorProperty.RawValue);
                    Debug.Assert(genColor != null, "Invalid generator color was specified.");
                }

                int genInterval = DEFAULT_GENERATOR_INTERVAL;
                Property intervalProperty;
                if (generatorObj.Properties.TryGetValue(INTERVAL_PROPERTY_NAME, out intervalProperty))
                    genInterval = FloatHelper.ParseIntervalString(intervalProperty.RawValue);

                float genSpeed = DEFAULT_GENERATOR_VELOCITY;
                Property speedProperty;
                if (generatorObj.Properties.TryGetValue(SPEED_PROPERTY_NAME, out speedProperty))
                    genSpeed = FloatHelper.ParseSpeedString(speedProperty.RawValue);

                if (!isWaterGenerator)
                {
                    Debug.Assert(genColor != Color.Transparent, "Invalid generator color specified.");
                    Add(new InkGenerator(new Vector2(genX, genY), genDirection.Value, genColor.Value, genInterval,
                                         genSpeed));
                }
                else
                    Add(new WaterGenerator(new Vector2(genX, genY), genDirection.Value, genInterval, genSpeed));
            }

            /* Portals */
            IEnumerable<MapObject> portalObjs = map.FindObjects((layer, obj) => obj.Type == PORTAL_OBJECT_NAME);
            foreach (MapObject portalObj in portalObjs)
            {
                Property colorProperty;
                Debug.Assert(portalObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty), "Portal found with no color.");
                Color? portalColor = ColorHelper.FromString(colorProperty.RawValue);
                Debug.Assert(portalColor != null, "Invalid portal color was specified.");

                bool isCorrectPortal = false;
                Property correctProperty;
                if (portalObj.Properties.TryGetValue("Correct", out correctProperty))
                    isCorrectPortal = true;

                Vector2 portalPos = new Vector2(portalObj.Bounds.X, portalObj.Bounds.Y);
                Vector2 portalSize = new Vector2(portalObj.Bounds.Width, portalObj.Bounds.Height);

                Add(new Portal(Type, portalPos, portalSize, portalColor.Value, isCorrectPortal));
            }

            /* Spikes */
            IEnumerable<MapObject> spikeObjs = map.FindObjects((layer, obj) => obj.Type == SPIKE_OBJECT_NAME);
            foreach (MapObject spikeObj in spikeObjs)
            {
                Color? spikeColor = Color.White;
                Vector2? spikeDirection;

                Property colorProperty;
                if (spikeObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty))
                    spikeColor = ColorHelper.FromString(colorProperty.RawValue);
                Debug.Assert(spikeColor.HasValue, "Invalid spike color specified.");

                Property directionProperty;
                Debug.Assert(spikeObj.Properties.TryGetValue(DIRECTION_PROPERTY_NAME, out directionProperty), "Spikes without direction");
                spikeDirection = VectorHelper.FromDirectionString(directionProperty.RawValue);
                Debug.Assert(spikeDirection.HasValue, "Invalid spike direction specified.");
                bool alignedHorizontally = (spikeDirection.Value.X == 0);
                bool facingLeft = (spikeDirection.Value.X < 0);
                int numSpikes = alignedHorizontally
                    ? (int)(spikeObj.Bounds.Width / (tilesize.X))
                    : (int)(spikeObj.Bounds.Height / (tilesize.Y));

                for (int i = facingLeft ? 1 : 0; i < (facingLeft ? numSpikes : numSpikes - 1); i++)
                {
                    spikes.Add(new Spike(alignedHorizontally
                        ? new Vector2(spikeObj.Bounds.X + i*tilesize.X, spikeObj.Bounds.Y)
                        : new Vector2(spikeObj.Bounds.X, spikeObj.Bounds.Y + i*tilesize.Y),
                        new Vector2(tilesize.X * 2, tilesize.Y), spikeColor.Value, spikeDirection.Value));
                }
            }

            /* Waves */
            IEnumerable<MapObject> waveObjs = map.FindObjects((layer, obj) => obj.Type == WAVE_OBJECT_NAME);
            foreach (MapObject waveObj in waveObjs)
            {
                Property colorProperty;
                Color? waveColor = Color.White;
                bool isWater = false;
                Debug.Assert(waveObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty), "Found a wave with no color.");

                if (colorProperty.RawValue == WATER)
                    isWater = true;
                else
                {
                    waveColor = ColorHelper.FromString(colorProperty.RawValue);
                    Debug.Assert(waveColor.HasValue, "Invalid wave color specified.");
                }

                Property directionProperty;
                Vector2? direction = new Vector2(1, 0);
                if (waveObj.Properties.TryGetValue(DIRECTION_PROPERTY_NAME, out directionProperty))
                {
                    direction = VectorHelper.FromDirectionString(directionProperty.RawValue);
                }

                Add(new WaveGenerator(new Vector2(waveObj.Bounds.X, waveObj.Bounds.Y + (1f/2f)*waveObj.Bounds.Height),
                    new Vector2(waveObj.Bounds.Width, waveObj.Bounds.Height * 1f/2f),
                    direction.Value.X < 0, isWater ? Color.LightBlue : waveColor.Value,
                    isWater));
            }

            /* Spouts */
            IEnumerable<MapObject> spoutObjs = map.FindObjects((layer, obj) => obj.Type == "Spout");
            foreach (MapObject spoutObj in spoutObjs)
            {
                bool isWater = false;
                Color? spoutColor;
                Property colorProperty;
                Debug.Assert(spoutObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty), "Spout has no color.");
                if (colorProperty.RawValue == "Water")
                {
                    spoutColor = Color.LightBlue;
                    isWater = true;
                }
                else
                {
                    spoutColor = ColorHelper.FromString(colorProperty.RawValue);
                }
                Debug.Assert(spoutColor.HasValue, "Invalid color specified for spout.");

                Vector2? spoutDirection;
                Property directionProperty;
                Debug.Assert(spoutObj.Properties.TryGetValue(DIRECTION_PROPERTY_NAME, out directionProperty), "Spout has no direction.");
                spoutDirection = VectorHelper.FromDirectionString(directionProperty.RawValue);
                Debug.Assert(spoutDirection.HasValue, "Invalid direction specified for spout.");

                Add(new SpoutGenerator(new Vector2(spoutObj.Bounds.X, spoutObj.Bounds.Y), spoutDirection.Value, spoutColor.Value, isWater));
            }

            /* Sections */
            IEnumerable<MapObject> sectionObjs = map.FindObjects((layer, obj) => obj.Type == SECTION_OBJECT_NAME);
            foreach (MapObject sectionObj in sectionObjs)
            {
                Property zoomProperty;
                float zoomLevel = -1;
                bool centered = false;

                if (sectionObj.Properties.TryGetValue(ZOOM_PROPERTY_NAME, out zoomProperty))
                    switch (zoomProperty.RawValue)
                    {
                        case NEAR:
                            zoomLevel = NEAR_ZOOM_LEVEL;
                            break;
                        case MEDIUM:
                            zoomLevel = MEDIUM_ZOOM_LEVEL;
                            break;
                        case FAR:
                            zoomLevel = FAR_ZOOM_LEVEL;
                            break;
                        case VERY_FAR:
                            zoomLevel = VERY_FAR_ZOOM_LEVEL;
                            break;
                        case CENTER:
                            centered = true;
                            break;
                        default:
                            throw new InvalidOperationException("Invalid zoom level.");
                    }

                if (centered)
                    sections.Add(new Section(this, sectionObj.Bounds, centered));
                else
                    sections.Add(new Section(this, sectionObj.Bounds, zoomLevel));
            }

            IEnumerable<MapObject> barrierObjs = Map.FindObjects((layer, obj) => obj.Type == "Barrier");
            foreach (MapObject barrierObj in barrierObjs)
            {
                Property colorProperty;
                Color? barrierColor;
                Debug.Assert(barrierObj.Properties.TryGetValue(COLOR_PROPERTY_NAME, out colorProperty), "No color specified for barrier.");
                barrierColor = ColorHelper.FromString(colorProperty.RawValue);
                Debug.Assert(barrierColor.HasValue, "Invalid color specified for barrier.");

                Property directionProperty;
                Vector2? barrierDirection;
                Debug.Assert(barrierObj.Properties.TryGetValue(DIRECTION_PROPERTY_NAME, out directionProperty), "No direction specified for barrier.");
                barrierDirection = VectorHelper.FromDirectionString(directionProperty.RawValue);
                Debug.Assert(barrierDirection.HasValue, "Invalid direction specified for barrier.");

                Vector2 barrierPos = new Vector2(barrierObj.Bounds.X, barrierObj.Bounds.Y);
                Vector2 barrierSize = new Vector2(barrierObj.Bounds.Width, barrierObj.Bounds.Height);
                Add(new Barrier(barrierPos, barrierSize, barrierDirection.Value, barrierColor.Value));

                Vector2 tilespan = GetTilespan(barrierPos, barrierSize);
                Vector2 startPos = GetTileIndexByPixel(barrierPos);
                for (int y = (int)startPos.Y; y < startPos.Y + tilespan.Y; y++)
                    for (int x = (int)startPos.X; x < startPos.X + tilespan.X; x++)
                    {
                        tiles[y, x] = new Tile(new Vector2(x * tilesize.X, y * tilesize.Y), tilesize, TileType.Solid, barrierColor.Value);
                    }
            }
            inkMap = new InkMap(device, width, height);
            miniMap = new MiniMap(this, new Vector2(device.Viewport.Width - MINIMAP_X_OFFSET, 0 + MINIMAP_Y_OFFSET));

            toolbar = new Toolbar(new Vector2(device.Viewport.Width - TOOLBAR_X_OFFSET, 0 + TOOLBAR_Y_OFFSET),
                new Vector2(TOOLBAR_ICONSIZE_X, TOOLBAR_ICONSIZE_Y), new List<Texture2D>
                    {
                        ResourceManager.GetTexture("Misc_Navigation"),
                        ResourceManager.GetTexture("Misc_Reset")
                    }, Orientation.Vertical);
            GameEngine.FadeIn(FadeSpeed.Fast);
        }
Exemple #15
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            AudioController.LoadContent(Content);

            gameMap = Content.Load<Map>("testmap");

            enemyManager.LoadContent(Content, GraphicsDevice);
            itemManager.LoadContent(Content, GraphicsDevice);
            projectileManager.LoadContent(Content);
            particleManager.LoadContent(Content);
            gameHud = new HUD(GraphicsDevice.Viewport);
            gameHud.LoadContent(Content);

            parallaxManager = new ParallaxManager(GraphicsDevice.Viewport);
            parallaxManager.Layers.Add(new ParallaxLayer(Content.Load<Texture2D>("bg/bg0"), new Vector2(0, 0), 0.25f, false, Color.White * 0.75f));
            parallaxManager.Layers.Add(new ParallaxLayer(Content.Load<Texture2D>("bg/bg1"), new Vector2(0, 0), 0.15f, false, Color.White * 0.75f));

            for (int i = 0; i < NUM_SECTORS; i++)
            {
                WalkableLayers.Add(i, gameMap.GetLayer("Walkable" + i) as MapObjectLayer);
            }

            gameHero = new Robot(Helper.PtoV((gameMap.GetLayer("Spawn") as MapObjectLayer).Objects[0].Location.Center), true);
            gameHero.LoadContent(Content, GraphicsDevice);

            gameCamera = new Camera(GraphicsDevice.Viewport, gameMap);

            skyTex = Content.Load<Texture2D>("sky");
            titleTex = Content.Load<Texture2D>("title");

            font = Content.Load<SpriteFont>("font");

            ResetGame();

            currentSectorColor = sectorColors[0];

            showingTitleScreen = true;
        }
Exemple #16
0
 public void Update(Map map)
 {
     mapa = map;
     _solidos = mapa.GetLayer("Solidos") as TileLayer;
 }
Exemple #17
0
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            map = content.Load<Map>("map");

            TrackGenerator.Generate(map);

            var spawn = ((MapObjectLayer)map.GetLayer("Spawn")).Objects[0];
            racer = new Racer(content.Load<Texture2D>("racer"), new Rectangle(0, 0, 10, 10), new Vector2(0, 0));
            racer.Position = new Vector2(spawn.Location.Center.X, spawn.Location.Center.Y);
            racer.Rotation = float.Parse(spawn.Properties["rot"]);
            racer.Active = true;

            var track = (MapObjectLayer)map.GetLayer("Tris");

            foreach(MapObject o in track.Objects.Where(ob=>ob.PolyPoints!=null && ob.PolyPoints.Count==3))
                tris.Add(new TrackTri(o.PolyPoints[0], o.PolyPoints[1], o.PolyPoints[2]));

            //projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi, ScreenManager.Game.GraphicsDevice.Viewport.AspectRatio, 0.1f, 200f);
            Vector2 center;
            center.X = ScreenManager.Game.GraphicsDevice.Viewport.Width * 0.5f;
            center.Y = ScreenManager.Game.GraphicsDevice.Viewport.Height * 0.5f;
            viewMatrix = Matrix.CreateLookAt(new Vector3(center, -0.1f), new Vector3(center, 10f), new Vector3(0, -1, 0));
            projectionMatrix = Matrix.CreatePerspective(center.X * 2, center.Y * 2, 0.1f, 100f);

            drawEffect = new BasicEffect(ScreenManager.Game.GraphicsDevice) {VertexColorEnabled = true, };
            rastState = new RasterizerState()
            {
                CullMode = CullMode.None
            };

            camera = new Camera(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight, map);

            particleController.LoadContent(content);

            base.LoadContent();
        }
        public static void Initialize()
        {
            _map = Level.CurrentMap;
            //map width and height is measured in tiles.
            _mapSquares = new int[_map.Width, _map.Height];
            //Tile width is measured in pixels
            _tileWidth = _map.TileWidth;
            _tileHeight = _map.TileHeight;

            var colLayer = _map.GetLayer("Collision");
            var tileLayer = colLayer as TileLayer;
            //Iterate through the map. If collision layers tile at index is null then
            //it is marked as no collision in our grid
            for (int x = 0; x < _map.Width; x++)
                for (int y = 0; y < _map.Height; y++)
                {
                    if (tileLayer != null)
                        if(tileLayer.Tiles[x,y] == null)
                        {
                            _mapSquares[x, y] = NonCollision;
                        }
                        else
                        {
                            //Collision is no null so this is a collision tile
                            _mapSquares[x, y] = Collision;
                        }
                }
        }
Exemple #19
0
        public void Spawn(Map gameMap, float floorheight)
        {
            //int numSpawned = 0;
            // Left or right side?
            Dude d;
            foreach (MapObject o in ((MapObjectLayer)gameMap.GetLayer("spawns")).Objects)
            {
                d = new Dude(new Vector2(o.Location.Center.X, o.Location.Bottom), false);
                d.faceDir = 1;
                d.Scale = 2f;
                d.LoadContent(skeletonRenderer, AtlasDict["dude"], JsonDict["dude"]);
                Enemies.Add(d);
            }

            d = new Dude(new Vector2((gameMap.Width * gameMap.TileWidth) - 380f, floorheight-5), false);
            d.Tint = Color.Navy;
            d.faceDir = 1;
            d.Scale = 2f;
            d.IsCoPilot = true;
            d.LoadContent(skeletonRenderer, AtlasDict["dude"], JsonDict["dude"]);
            d.State = AIState.GoingForDoor;
            Enemies.Add(d);
        }
Exemple #20
0
        public int Spawn(Map gameMap, Camera gameCamera, List<int> levelSectors, Robot gameHero)
        {
            int numSpawned = 0;
            // Left or right side?

            bool weaponspawned = false;

            for (int num = 0; num < 1 + rand.Next(gameHero.Sector+2); num++)
            {
                if (numSpawned > largestNumberSpawned) break;

                int side = rand.Next(2);
                if (side == 0) side = -1;

                // Actual X spawn position
                Vector2 spawnPos = new Vector2(gameCamera.Position.X + (((gameCamera.Width / 2) + 50f + ((float)rand.NextDouble() * 100f)) * side), gameCamera.Position.Y - (gameCamera.Width / 2));

                // Detect a Y position
                bool spawned = false;
                for (float y = spawnPos.Y; y < spawnPos.Y + gameCamera.Height; y += 15f)
                {
                    if (!spawned)
                    {
                        for (int i = 0; i < levelSectors.Count; i++)
                        {
                            MapObjectLayer walkableLayer = gameMap.GetLayer("Walkable" + levelSectors[i].ToString()) as MapObjectLayer;
                            foreach (MapObject o in walkableLayer.Objects)
                            {
                                if (!spawned && Helper.IsPointInShape(new Vector2(spawnPos.X - ((gameMap.Width * gameMap.TileWidth) * i), y), o.LinePoints))
                                {
                                    if (rand.Next(3) == 1)
                                    {
                                        numSpawned++;
                                        spawned = true;

                                        Robot r = new Robot(new Vector2(spawnPos.X, y), false);

                                        if ((rand.Next(5) == 0 || spawnsWithoutWeapon == 3) && !weaponspawned)
                                        {
                                            spawnsWithoutWeapon = 0;
                                            ItemManager.Instance.Spawn(r);
                                            weaponspawned = true;
                                        }
                                        else spawnsWithoutWeapon++;

                                        r.LoadContent(skeletonRenderer, blankTex, AtlasDict["robo"], JsonDict["robo"]);
                                        Enemies.Add(r);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (numSpawned > largestNumberSpawned) largestNumberSpawned = numSpawned;

            return numSpawned;
        }
Exemple #21
0
        public static void GenerateTerrain(Map map, LightingEngine lightingEngine, GraphicsDevice gd)
        {
            Generating = true;
            PercentComplete = 0;

            Thread.Sleep(1000);

            bool compoundsOK = false;

            map.Jetties.Clear();

            List<Compound> compounds = new List<Compound>();

            TileLayer terrainLayer = map.GetLayer("Terrain") as TileLayer;
            TileLayer wallLayer = map.GetLayer("Wall") as TileLayer;
            TileLayer waterLayer = map.GetLayer("Water") as TileLayer;
            TileLayer roofLayer = map.GetLayer("Roof") as TileLayer;

            float[][] noise = null;

            while (!compoundsOK)
            {
                compounds.Clear();

                for (int i = lightingEngine.LightSources.Count - 1; i >= 0; i--)
                    if (lightingEngine.LightSources[i].SpotStencil != null) lightingEngine.LightSources.RemoveAt(i);

                for (int y = 0; y < map.Width; y++)
                {
                    for (int x = 0; x < map.Height; x++)
                    {
                        terrainLayer.Tiles[x, y] = null;
                        wallLayer.Tiles[x, y] = null;
                    }
                }

                PercentComplete = 5;

                // Inital terrain
                noise = PerlinNoise.GeneratePerlinNoise(map.Width, map.Height, 8);
                for (int y = 0; y < map.Width; y++)
                {
                    for (int x = 0; x < map.Height; x++)
                        if (noise[y][x] < 0.5f)
                        {
                            terrainLayer.Tiles[x, y] = map.Tiles[WATER];
                            waterLayer.Tiles[x, y] = map.Tiles[WATER];
                        }
                        else if (noise[y][x] < 0.6f)
                        {
                            terrainLayer.Tiles[x, y] = map.Tiles[SAND];
                            waterLayer.Tiles[x, y] = null;

                        }
                        else
                        {
                            terrainLayer.Tiles[x, y] = map.Tiles[GRASS];
                            waterLayer.Tiles[x, y] = null;

                        }
                }

                PercentComplete = 10;

                // Trees
                float[][] treeNoise = PerlinNoise.GeneratePerlinNoise(map.Width, map.Height, 4);

                for (int y = 0; y < map.Width; y++)
                {
                    for (int x = 0; x < map.Height; x++)
                    {
                        if (noise[y][x] > 0.62f)
                            if (treeNoise[y][x] > 0.5f)
                                wallLayer.Tiles[x, y] = map.Tiles[TREE];
                    }
                }

                PercentComplete = 20;

                // Compounds
                CreateCompounds(map, terrainLayer, wallLayer, roofLayer, compounds, noise, 0.65f, 20000f, 20, lightingEngine, gd);
                CreateCompounds(map, terrainLayer, wallLayer, roofLayer, compounds, noise, 0.75f, 12000f, 30, lightingEngine, gd);

                // Test to see if compounds are okay
                int numOKComps = 0;
                foreach (Compound c in compounds)
                {
                    if (c.Buildings.Count(b => b.Type != BuildingType.Carpark && b.Type != BuildingType.Helipad) > 0) numOKComps++;
                }

                if (numOKComps > 5) compoundsOK = true;
            }

            PercentComplete = 35;

            // Remove stray tiles
            for (int y = 0; y < map.Width; y++)
            {
                for (int x = 0; x < map.Height; x++)
                {
                    if (GetTileIndex(map, terrainLayer, x, y) == SAND)
                        if (CountSurroundingTiles(map, terrainLayer, x, y, WATER) >= 5)
                        {
                            terrainLayer.Tiles[x, y] = map.Tiles[WATER];
                            waterLayer.Tiles[x, y] = map.Tiles[WATER];
                        }

                    //if (GetTileIndex(map, terrainLayer, (map.Width-1) - x, (map.Height-1) - y) == SAND)
                    //    if (CountSurroundingTiles(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y, WATER) >= 5) terrainLayer.Tiles[(map.Width - 1) - x, (map.Height - 1) - y] = map.Tiles[WATER];

                    if (GetTileIndex(map, terrainLayer, x, y) == GRASS)
                        if (CountSurroundingTiles(map, terrainLayer, x, y, SAND) >= 5) terrainLayer.Tiles[x, y] = map.Tiles[SAND];

                    //if (GetTileIndex(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y) == GRASS)
                    //    if (CountSurroundingTiles(map, terrainLayer, (map.Width - 1) - x, (map.Height - 1) - y, SAND) >= 5) terrainLayer.Tiles[(map.Width - 1) - x, (map.Height - 1) - y] = map.Tiles[SAND];
                }
            }

            PercentComplete = 45;

            // Jetties!
            for (int y = 40; y < map.Width - 40; y+=2)
            {
                for (int x = 40; x < map.Height - 40; x+=2)
                {
                    if (GetTileIndex(map, terrainLayer, x, y) == SAND)
                    {
                        switch (Helper.Random.Next(4))
                        {
                            case 0:
                                if (GetTileIndex(map, terrainLayer, x, y - 10) == WATER && GetTileIndex(map, terrainLayer, x, y - 4) == WATER && GetTileIndex(map, terrainLayer, x, y - 2) == SAND)
                                    if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(0, -1))) continue;
                                break;
                            case 1:

                                if (GetTileIndex(map, terrainLayer, x, y + 10) == WATER && GetTileIndex(map, terrainLayer, x, y + 4) == WATER && GetTileIndex(map, terrainLayer, x, y + 2) == SAND)
                                    if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(0, 1))) continue;
                                break;

                            case 2:
                                if (GetTileIndex(map, terrainLayer, x - 10, y) == WATER && GetTileIndex(map, terrainLayer, x - 4, y) == WATER && GetTileIndex(map, terrainLayer, x - 2, y) == SAND)
                                    if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(-1, 0))) continue;
                                break;

                            case 3:
                                if (GetTileIndex(map, terrainLayer, x + 10, y) == WATER && GetTileIndex(map, terrainLayer, x + 4, y) == WATER && GetTileIndex(map, terrainLayer, x + 2, y) == SAND)
                                    if (TryMakeJetty(map, terrainLayer, waterLayer, new Point(x, y), new Point(1, 0))) continue;
                                break;
                        }
                    }
                }
            }

            PercentComplete = 55;

            // Detail tiling!
            for (int y = 0; y < map.Width; y++)
            {
                for (int x = 0; x < map.Height; x++)
                {

                    // Sand/Water
                    if (GetTileIndex(map, terrainLayer, x, y) == SAND)
                    {
                        // Edges
                        if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_LEFT];

                        if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_RIGHT];

                        if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_DOWN];

                        if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_EDGE_UP];

                        // Corners - water inside
                        if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_BR];

                        if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_TR];

                        if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_BL];

                        if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) != WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_INSIDE_TL];

                        // Corners - water outside
                        if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_TL];

                        if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_BL];

                        if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) == WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_TR];

                        if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == WATER)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) == WATER)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) == WATER) terrainLayer.Tiles[x, y] = map.Tiles[SAND_CORNER_OUTSIDE_BR];

                    }

                    // Grass/Sand
                    if (GetTileIndex(map, terrainLayer, x, y) == GRASS || GetTileIndex(map, terrainLayer, x, y) == GRASS_ALT1 || GetTileIndex(map, terrainLayer, x, y) == GRASS_ALT2)
                    {
                        // Edges
                        if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_LEFT];

                        if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_RIGHT];

                        if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_DOWN];

                        if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_EDGE_UP];

                        // Corners - water inside
                        if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_BR];

                        if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_TR];

                        if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_BL];

                        if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) != SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) != SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_INSIDE_TL];

                        // Corners - water outside
                        if (GetTileIndex(map, terrainLayer, x - 1, y - 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_TL];

                        if (GetTileIndex(map, terrainLayer, x - 1, y + 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND)
                                if (GetTileIndex(map, terrainLayer, x - 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_BL];

                        if (GetTileIndex(map, terrainLayer, x + 1, y - 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y - 1) == SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_TR];

                        if (GetTileIndex(map, terrainLayer, x + 1, y + 1) == SAND)
                            if (GetTileIndex(map, terrainLayer, x, y + 1) == SAND)
                                if (GetTileIndex(map, terrainLayer, x + 1, y) == SAND) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_CORNER_OUTSIDE_BR];

                    }
                }
            }

            PercentComplete = 75;

            // Alt tiles
            for (int y = 0; y < map.Width; y++)
            {
                for (int x = 0; x < map.Height; x++)
                {
                    if (GetTileIndex(map, terrainLayer, x, y) == GRASS)
                    {
                        int r = rand.Next(50);
                        if (r == 9) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_ALT1];
                        else if (r == 8) terrainLayer.Tiles[x, y] = map.Tiles[GRASS_ALT2];
                    }
                    if (GetTileIndex(map, terrainLayer, x, y) == SAND)
                    {
                        int r = rand.Next(50);
                        if (r == 9) terrainLayer.Tiles[x, y] = map.Tiles[SAND_ALT];
                    }

                    // Tree alts
                    if (GetTileIndex(map, wallLayer, x, y) == TREE)
                    {
                        //if (rand.Next(10) == 0)
                        //{
                            // Big tree
                        if(!TryDrawBigTree(map, wallLayer, x, y)) wallLayer.Tiles[x, y] = map.Tiles[TREES[rand.Next(TREES.Length)]];

                    }
                }
            }

            PercentComplete = 90;

            Rectangle spawnRect = new Rectangle((map.Width / 2) - 5, (map.Height / 2) - 5, 10, 10);
            bool foundspawn = false;
            while (!foundspawn)
            {
                map.HeroSpawn = TryFindSpawn(spawnRect.Left, spawnRect.Top, map, terrainLayer, out foundspawn);
                if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Right, spawnRect.Top, map, terrainLayer, out foundspawn);
                if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Left, spawnRect.Bottom, map, terrainLayer, out foundspawn);
                if (!foundspawn) map.HeroSpawn = TryFindSpawn(spawnRect.Right, spawnRect.Bottom, map, terrainLayer, out foundspawn);

                spawnRect.Inflate(5, 5);
            }

            map.GetAStarData();
            map.Compounds = compounds;

            PercentComplete = 100;
            //Generating = false;
        }
Exemple #22
0
        public override void LoadContent()
        {
            map = Engine.Content.Load<Map>(mapFilePath);

            // loop through the map properties and handle them
            foreach (Property property in map.Properties)
            {
                switch (property.Name)
                {
                    case "BackgroundTrack":
                        Cue backgroundTrack = Engine.Audio.GetCue("Rain");
                        backgroundTrack.Play();
                        break;
                    case "ParticleEffect":
                        CreateParticleEffect(property.RawValue);
                        break;
                    default:
                        throw new Exception("Map property " + property.Name + " not recognized in map file " + mapFilePath);
                }
            }

            // loop through the collision objects and create physics fixtures for them
            MapObjectLayer collisionLayer = map.GetLayer("CollisionObjects") as MapObjectLayer;
            foreach (MapObject collisionObject in collisionLayer.Objects)
            {
                // I don't fully understand why using Vector2.Zero works here. It must have something to do with the Bounds already containing the position information
                CreateCollisionRectangle(collisionObject.Bounds, Engine.Physics.PositionToPhysicsWorld(Vector2.Zero));

                // create the shadow hull for the platform
                CreateRectangleShadowHull(new Vector2(collisionObject.Bounds.Center.X, collisionObject.Bounds.Center.Y), collisionObject.Bounds);
            }

            // loop through the collision tiles and create physics fixtures for them
            TileLayer tileLayer = map.GetLayer("CollisionTiles") as TileLayer;
            if (Global.Configuration.GetBooleanConfig("Debug", "ShowDebugCollisionTiles"))
            {
                tileLayer.Opacity = 100;
            }
            else
            {
                tileLayer.Opacity = 0;
            }
            for (int y = 0; y < tileLayer.Height; ++y)
            {
               for (int x = 0; x < tileLayer.Width; ++x)
               {
                    if (tileLayer.Tiles[x, y] != null)
                    {
                        // create the physics object for the tile
                        CreateCollisionRectangle(tileLayer.Tiles[x, y].Source, Engine.Physics.PositionToPhysicsWorld(new Vector2(x * map.TileWidth, y * map.TileHeight)));

                        // create the shadow for the tile new Vector2(x * map.TileWidth, y * map.TileHeight)
                        CreateRectangleShadowHull(new Vector2(x * map.TileWidth + tileLayer.Tiles[x, y].Source.Width / 2,
                                                              y * map.TileHeight + tileLayer.Tiles[x, y].Source.Height / 2),
                                                  tileLayer.Tiles[x, y].Source);
                    }
                }
            }

            // loop through the light objects and create lights in the game world for them
            MapObjectLayer lightLayer = map.GetLayer("LightObjects") as MapObjectLayer;
            foreach (MapObject lightObject in lightLayer.Objects)
            {
                CreateLight(lightObject);
            }

            // create enemies
            MapObjectLayer enemyLayer = map.GetLayer("EnemyObjects") as MapObjectLayer;
            foreach (MapObject enemyObject in enemyLayer.Objects)
            {
                CreateEnemy(enemyObject);
            }
        }