示例#1
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;
            }
        }
示例#2
0

        
示例#3
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)
                });
            }
        }
示例#4
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];
        }
示例#5
0
        void GenerateSector()
        {
            int sect = rand.Next(NUM_SECTORS);

            levelSectors.Add(sect);

            sectorColors.Add(new Color(0.5f + ((float)rand.NextDouble() * 0.5f), 0.5f + ((float)rand.NextDouble() * 0.5f), 0.5f + ((float)rand.NextDouble() * 0.5f)));

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

            for (int i = 0; i < 4; i++)
            {
                Rectangle trig = triggerLayer.Objects[rand.Next(triggerLayer.Objects.Count)].Location;
                trig.Offset((gameMap.TileWidth * gameMap.Width) * (levelSectors.Count - 1), 0);

                bool found = true;
                while (found)
                {
                    found = false;
                    foreach (Rectangle r in triggerRects)
                    {
                        if (r == trig)
                        {
                            trig = triggerLayer.Objects[rand.Next(triggerLayer.Objects.Count)].Location;
                            trig.Offset((gameMap.TileWidth * gameMap.Width) * (levelSectors.Count - 1), 0);
                            found = true;
                            break;
                        }
                    }
                }

                //if(trig.X>(gameCamera.Width - (gameCamera.Width/3)))
                triggerRects.Add(trig);
            }
        }
        void SetPlayerNewPosition(Map lastMap, Vector2 _doorFromPosition)
        {
            Vector2 fromDoorIndex = lastMap.WorldPointToTileIndex(_doorFromPosition);

            // Change door tile to opened door :P
            int originalID = lastMap.GetTileLayer("Layer 0").Tiles[fromDoorIndex.x, fromDoorIndex.y].OriginalID;

            lastMap.GetTileLayer("Layer 0").SetTile(fromDoorIndex.x, fromDoorIndex.y, originalID + 2);

            int lastMapWidth  = lastMap.Width;
            int lastMapHeight = lastMap.Height;
            // Position player
            MapObjectLayer mol = _currentMap.GetObjectLayer("Doors");

            for (int i = 0; i < mol.Objects.Count; i++)
            {
                // This is a Left Door - X = 0
                if (mol.Objects[i].Bounds.x < 1)
                {
                    // And we came from a Right Door!
                    if (fromDoorIndex.x >= lastMapWidth - 1)
                    {
                        _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(1.5f, mol.Objects[i].Bounds.y + 0.5f);
                    }
                }
                // This is a Right Door - X = _currentMap.Width - 1
                if (mol.Objects[i].Bounds.x >= _currentMap.Width - 1)
                {
                    // And we came from a Left Door!
                    if (fromDoorIndex.x < 1)
                    {
                        _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x - 1, mol.Objects[i].Bounds.y + 0.5f);
                    }
                }
                // This is an Up Door - Y = 0
                if (mol.Objects[i].Bounds.y < 1)
                {
                    // And we came from a Down Door!
                    if (fromDoorIndex.y >= lastMapHeight - 1)
                    {
                        _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x + 0.5f, 1.4f);
                    }
                }
                // This is a Down Door - Y = _currentMap.Height - 1
                if (mol.Objects[i].Bounds.y >= _currentMap.Height - 1)
                {
                    // And we came from an Up Door!
                    if (fromDoorIndex.y < 1)
                    {
                        _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x, mol.Objects[i].Bounds.y - 0.5f);
                    }
                }
            }

            _player.gameObject.GetComponent <X_UniTMX.Utils.SortingOrderAutoCalculator>().SetMap(_currentMap);
        }
        private void InitLayers()
        {
            mapObjectLayer    = new MapObjectLayer();
            boundingAreaLayer = new BoundingAreaLayer();
            attractorLayer    = new WritableLayer();

            edgeLayer            = new WritableLayer();
            edgeRasterizingLayer = new RasterizingLayer(edgeLayer,
                                                        delayBeforeRasterize: 0, renderResolutionMultiplier: 1,
                                                        rasterizer: null, overscanRatio: 2);
        }
示例#8
0
    void LoadMap()
    {
        UnloadCurrentMap();
        TiledMap = new Map(Maps[CurrentMap], true, MapsPath, this.gameObject);
        Debug.Log(TiledMap.ToString());
        MapObjectLayer mol = TiledMap.GetLayer("PropertyTest") as MapObjectLayer;

        if (mol != null)
        {
            Debug.Log(mol.GetPropertyAsBoolean("test"));
        }
    }
示例#9
0
        public List <MapObject> GetLayerObjects(string layerName)
        {
            List <MapObject> mapObjects = new List <MapObject>();

            MapObjectLayer layer = map.GetLayer(layerName) as MapObjectLayer;

            foreach (MapObject mapObject in layer.Objects)
            {
                mapObjects.Add(mapObject);
            }

            return(mapObjects);
        }
示例#10
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;
                    }
                }
            }
        }
示例#11
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();
        }
示例#12
0
        Vector2 MoveToRandomPosition(Map gameMap, List <int> levelSectors, Dictionary <int, MapObjectLayer> walkableLayers)
        {
            for (int i = 0; i < levelSectors.Count; i++)
            {
                MapObjectLayer walkableLayer = walkableLayers[levelSectors[i]];

                foreach (MapObject o in walkableLayer.Objects)
                {
                    if (Helper.IsPointInShape(new Vector2((Position.X + 5f) - ((gameMap.Width * gameMap.TileWidth) * i), landingHeight), o.LinePoints) ||
                        Helper.IsPointInShape(new Vector2((Position.X - 5f) - ((gameMap.Width * gameMap.TileWidth) * i), landingHeight), o.LinePoints) ||
                        Helper.IsPointInShape(new Vector2((Position.X) - ((gameMap.Width * gameMap.TileWidth) * i), landingHeight), o.LinePoints))
                    {
                        int lx = 100000;
                        int ly = 100000;
                        int mx = -100000;
                        int my = -100000;
                        foreach (Point l in o.LinePoints)
                        {
                            if (l.X < lx)
                            {
                                lx = l.X;
                            }
                            if (l.X > mx)
                            {
                                mx = l.X;
                            }
                            if (l.Y < ly)
                            {
                                ly = l.Y;
                            }
                            if (l.Y > my)
                            {
                                my = l.Y;
                            }
                        }

                        Vector2 testPoint = new Vector2(lx + (rand.Next(mx - lx)), ly + (rand.Next(my - ly)));
                        if (Helper.IsPointInShape(testPoint, o.LinePoints))
                        {
                            return(testPoint + new Vector2(((gameMap.Width * gameMap.TileWidth) * i), 0));
                        }
                    }
                }
            }

            return(Position);
        }
示例#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,
            };
        }
示例#14
0
    void LoadMap()
    {
        UnloadCurrentMap();
        TiledMap = new Map(Maps[CurrentMap], true, MapsPath, this.gameObject, defaultMaterial, sortingOrder);
        TiledMap.GenerateCollidersFromLayer("Collider_0");
        TiledMap.GenerateCollidersFromLayer("Colliders");
        Debug.Log(TiledMap.ToString());
        MapObjectLayer mol = TiledMap.GetLayer("PropertyTest") as MapObjectLayer;

        if (mol != null)
        {
            Debug.Log(mol.GetPropertyAsBoolean("test"));
        }
        // Center camera
        _camera.CamPos        = new Vector3(TiledMap.Width / 2.0f, -TiledMap.Height / 2.0f, _camera.CamPos.z);
        _camera.PixelsPerUnit = TiledMap.TileHeight;
    }
    public void GenerateColliders()
    {
        for (int i = 0; i < CollidersLayerName.Length; i++)
        {
            MapObjectLayer collisionLayer = (MapObjectLayer)tiledMap.GetLayer(CollidersLayerName[i]);
            if (collisionLayer != null)
            {
                List <MapObject> colliders = collisionLayer.Objects;
                foreach (MapObject colliderObjMap in colliders)
                {
                    GameObject newColliderObject = null;
                    if ("NoCollider".Equals(colliderObjMap.Type) == false)
                    {
                        newColliderObject = tiledMap.GenerateCollider(colliderObjMap, CollidersIsTrigger[i], is2DCollider, CollidersZDepth[i], CollidersWidth[i], CollidersIsInner[i]);
                    }

                    if (colliderObjMap.GetPropertyAsBoolean("detach prefab"))
                    {
                        newColliderObject = null;
                    }

                    tiledMap.AddPrefabs(colliderObjMap, newColliderObject, is2DCollider, addTileNameToColliderName);

                    // if this colider has transfer, so delete this colider
                    if (colliderObjMap.GetPropertyAsBoolean("transfer collider"))
                    {
                        if (is2DCollider)
                        {
                            Destroy(newColliderObject.GetComponent <Collider2D>());
                        }
                        else
                        {
                            Destroy(newColliderObject.GetComponent <Collider>());
                        }
                    }

                    //Debug.Log (newColliderObject);
                }
            }
            else
            {
                Debug.LogError("There's no Layer \"" + CollidersLayerName[i] + "\" in tile map.");
            }
        }
    }
示例#16
0
        bool CheckCollision(Vector2 pos, float landingHeight, Map gameMap, List <int> levelSectors, Dictionary <int, MapObjectLayer> walkableLayers, int ghs)
        {
            for (int i = 0; i < levelSectors.Count; i++)
            {
                if (i < ghs - 1 || i > ghs + 1)
                {
                    continue;
                }
                MapObjectLayer walkableLayer = walkableLayers[levelSectors[i]];

                for (int o = 0; o < walkableLayer.Objects.Count; o++)
                {
                    if (Helper.IsPointInShape(new Vector2(pos.X - ((gameMap.Width * gameMap.TileWidth) * i), landingHeight), walkableLayer.Objects[o].LinePoints))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#17
0
        bool CheckJump(Map gameMap, List <int> levelSectors, Dictionary <int, MapObjectLayer> walkableLayers)
        {
            for (int i = 0; i < levelSectors.Count; i++)
            {
                MapObjectLayer walkableLayer = walkableLayers[levelSectors[i]];


                for (float y = landingHeight - 20; y > landingHeight - 300; y--)
                {
                    foreach (MapObject o in walkableLayer.Objects)
                    {
                        if (Helper.IsPointInShape(new Vector2((Position.X) - ((gameMap.Width * gameMap.TileWidth) * i), y), o.LinePoints))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
示例#18
0
        bool FallTest(Map gameMap, List <int> levelSectors, Dictionary <int, MapObjectLayer> walkableLayers)
        {
            if (knockbackTime > 0)
            {
                return(false);
            }

            for (int i = 0; i < levelSectors.Count; i++)
            {
                MapObjectLayer walkableLayer = walkableLayers[levelSectors[i]];


                for (float y = landingHeight + 20; y < (gameMap.TileHeight * (gameMap.Height - 5)); y += 5)
                {
                    for (int o = 0; o < walkableLayer.Objects.Count; o++)
                    {
                        if (Helper.IsPointInShape(new Vector2((Position.X + (Speed.X * 10)) - ((gameMap.Width * gameMap.TileWidth) * i), y), walkableLayer.Objects[o].LinePoints))
                        {
                            if (Helper.IsPointInShape(new Vector2((Position.X + (Speed.X * -10)) - ((gameMap.Width * gameMap.TileWidth) * i), Position.Y + 10), walkableLayer.Objects[o].LinePoints))
                            {
                                return(false);
                            }

                            if ((y - landingHeight) > gameMap.TileHeight)
                            {
                                landingHeight = y;
                                falling       = true;
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(false);
        }
示例#19
0
    /// <summary>
    /// Initializes the objects on the map.
    /// </summary>
    private void InitializeObjects()
    {
        MapObjectLayer   mainObjectLayer = map.GetObjectLayer("Objects");
        List <MapObject> validObjects    = mainObjectLayer.Objects.ToList();

        // iterate through all the map objects in the game
        // see if they are units or characters
        // then add them to the mainUnits or mainCharacters Lists
        // and initialize them properly into the scene
        foreach (MapObject o in validObjects)
        {
            Vector2 tileIndices = map.WorldPointToTileIndex(o.Bounds.position);
            tileIndices.y *= -1;

            if (o.Type == "Character")
            {
                int characterId    = o.GetPropertyAsInt("character id");
                int characterOwner = o.GetPropertyAsInt("character owner");

                GameCharacter c = CharacterBuilder.Instance.BuildCharacter(characterId, PlayerManager.Instance.GetPlayer(characterOwner), 0, 0);

                if (c == null)
                {
                    Debug.LogError("Character (ID: " + characterId + ") could not be built.");
                    return;
                }

                c.SetTile((int)tileIndices.x, (int)tileIndices.y);
            }
            else if (o.Type == "SpawnPoint")
            {
                // make a spawn point unit at the location
                spawnTiles.Add(mainGrid[(int)tileIndices.x, (int)tileIndices.y]);
                GameUnit newSpawnPoint = (GameUnit)Instantiate(spawnPointPrefab);
                newSpawnPoint.name = (spawnTiles.Count - 1) + "-spawn";
                newSpawnPoint.SetTile((int)tileIndices.x, (int)tileIndices.y);
            }
        }
    }
示例#20
0
        void OnMapLoaded(Map map)
        {
            TiledMap = map;
            if (TiledMap.GetObjectLayer("Collider_0") != null)
            {
                TiledMap.GenerateCollidersFromLayer("Collider_0");
            }
            if (TiledMap.GetObjectLayer("Colliders") != null)
            {
                TiledMap.GenerateCollidersFromLayer("Colliders");
            }
            Debug.Log(TiledMap.ToString());
            MapObjectLayer mol = TiledMap.GetObjectLayer("PropertyTest");

            if (mol != null)
            {
                Debug.Log(mol.GetPropertyAsBoolean("test"));
            }
            // Center camera
            _camera.CamPos        = TiledMap.TiledPositionToWorldPoint(TiledMap.Width / 2.0f, TiledMap.Height / 2.0f, _camera.CamPos.z);
            _camera.PixelsPerUnit = TiledMap.TileHeight;
        }
    public void GenerateColliders()
    {
        for (int i = 0; i < CollidersLayerName.Length; i++)
        {
            MapObjectLayer collisionLayer = (MapObjectLayer)tiledMap.GetLayer(CollidersLayerName[i]);
            if (collisionLayer != null)
            {
                List <MapObject> colliders = collisionLayer.Objects;
                foreach (MapObject collider in colliders)
                {
                    switch (collider.MapObjectType)
                    {
                    case MapObjectType.Box:
                        tiledMap.GenerateBoxCollider(collider, CollidersZDepth[i], CollidersWidth[i]);
                        break;

                    case MapObjectType.Ellipse:
                        tiledMap.GenerateEllipseCollider(collider, CollidersZDepth[i], CollidersWidth[i]);
                        break;

                    case MapObjectType.Polygon:
                        tiledMap.GeneratePolygonCollider(collider, CollidersZDepth[i], CollidersWidth[i], CollidersIsInner[i]);
                        break;

                    case MapObjectType.Polyline:
                        tiledMap.GeneratePolylineCollider(collider, CollidersZDepth[i], CollidersWidth[i], CollidersIsInner[i]);
                        break;
                    }
                }
            }
            else
            {
                Debug.LogError("There's no Layer \"" + CollidersLayerName[i] + "\" in tile map.");
            }
        }
    }
示例#22
0
        public void LoadContent(ContentManager content, MapObjectLayer spawnLayer)
        {
            VoxelSprite asteroid = new VoxelSprite(16, 16, 16);

            LoadVoxels.LoadSprite(Path.Combine(content.RootDirectory, "enemies", "asteroids.vxs"), ref asteroid);
            spriteSheets.Add("Asteroid", asteroid);
            VoxelSprite omega = new VoxelSprite(15, 15, 15);

            LoadVoxels.LoadSprite(Path.Combine(content.RootDirectory, "enemies", "omega.vxs"), ref omega);
            spriteSheets.Add("Omega", omega);
            VoxelSprite turret = new VoxelSprite(15, 15, 15);

            LoadVoxels.LoadSprite(Path.Combine(content.RootDirectory, "enemies", "turret.vxs"), ref turret);
            spriteSheets.Add("Turret", turret);
            VoxelSprite squid = new VoxelSprite(15, 15, 15);

            LoadVoxels.LoadSprite(Path.Combine(content.RootDirectory, "enemies", "squid.vxs"), ref squid);
            spriteSheets.Add("Squid", squid);

            foreach (MapObject o in spawnLayer.Objects)
            {
                Spawns.Add(o);
            }
        }
示例#23
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);
        }
示例#24
0
        internal Map(ContentReader reader)
        {
            // read in the basic map information
            Version = new Version(reader.ReadString());
            Orientation = (Orientation)reader.ReadByte();
            Width = reader.ReadInt32();
            Height = reader.ReadInt32();
            TileWidth = reader.ReadInt32();
            TileHeight = reader.ReadInt32();
            Properties = new PropertyCollection(reader);
            bool makeTilesUnique = reader.ReadBoolean();

            // create a list for our tiles
            List<Tile> tiles = new List<Tile>();
            Tiles = new ReadOnlyCollection<Tile>(tiles);

            // read in each tile set
            int numTileSets = reader.ReadInt32();
            for (int i = 0; i < numTileSets; i++)
            {
                // get the id and texture
                int firstId = reader.ReadInt32();
                //string tilesetName = reader.ReadString(); // added

                Texture2D texture = reader.ReadExternalReference<Texture2D>();

                // Read in color data for collision purposes
                // You'll probably want to limit this to just the tilesets that are used for collision
                // I'm checking for the name of my tileset that contains wall tiles
                // Color data takes up a fair bit of RAM
                Color[] collisionData = null;
                //if (texture == "ForestTiles")
                //{
                collisionData = new Color[texture.Width * texture.Height];
                texture.GetData<Color>(collisionData);
                //}

                // read in each individual tile
                int numTiles = reader.ReadInt32();
                for (int j = 0; j < numTiles; j++)
                {
                    int id = firstId + j;
                    Rectangle source = reader.ReadObject<Rectangle>();
                    PropertyCollection props = new PropertyCollection(reader);

                    Tile t = new Tile(texture, source, props, collisionData); // modified
                    while (id >= tiles.Count)
                    {
                        tiles.Add(null);
                    }
                    tiles.Insert(id, t);
                }
            }

            // read in all the layers
            List<Layer> layers = new List<Layer>();
            Layers = new ReadOnlyCollection<Layer>(layers);
            int numLayers = reader.ReadInt32();
            for (int i = 0; i < numLayers; i++)
            {
                Layer layer = null;

                // read generic layer data
                string type = reader.ReadString();
                string name = reader.ReadString();
                int width = reader.ReadInt32();
                int height = reader.ReadInt32();
                bool visible = reader.ReadBoolean();
                float opacity = reader.ReadSingle();
                PropertyCollection props = new PropertyCollection(reader);

                // using the type, figure out which object to create
                if (type == "layer")
                {
                    int[] data = reader.ReadObject<int[]>();
                    layer = new TileLayer(name, width, height, visible, opacity, props, this, data, makeTilesUnique);
                }
                else if (type == "objectgroup")
                {
                    List<MapObject> objects = new List<MapObject>();

                    // read in all of our objects
                    int numObjects = reader.ReadInt32();
                    for (int j = 0; j < numObjects; j++)
                    {
                        string objName = reader.ReadString();
                        string objType = reader.ReadString();
                        Rectangle objLoc = reader.ReadObject<Rectangle>();
                        PropertyCollection objProps = new PropertyCollection(reader);

                        objects.Add(new MapObject(objName, objType, objLoc, objProps));
                    }

                    layer = new MapObjectLayer(name, width, height, visible, opacity, props, objects);

                    // read in the layer's color
                    (layer as MapObjectLayer).Color = reader.ReadColor();
                }
                else
                {
                    throw new Exception("Invalid type: " + type);
                }

                layers.Add(layer);
                namedLayers.Add(name, layer);
            }
        }