public TileSheetDeleteCommand(Map map, TileSheet tileSheet, MapTreeView mapTreeView)
 {
     m_map = map;
     m_tileSheet = tileSheet;
     m_mapTreeView = mapTreeView;
     m_description = "Delete tile sheet \"" + tileSheet.Id + "\"";
 }
Exemple #2
0
        xTile.Dimensions.Rectangle _viewport; //camera

        #endregion Fields

        #region Constructors

        public Level(int levelNumber, ProgressData progressData)
        {
            //set camera size based on screen size
            _viewport = new xTile.Dimensions.Rectangle(
                new xTile.Dimensions.Size(
                    Game1.SCREEN_WIDTH, Game1.SCREEN_HEIGHT));

            //load the map for the specified level
            _tileMap = Content.Load<Map>("Maps\\Level" + levelNumber.ToString());
            //load tile sheet
            _tileMap.LoadTileSheets(MapDisplayDevice);

            scanMapLayers();
            //_instructionScreen = Content.Load
            _progressData = progressData;
            _progressData.CurrentLevel = levelNumber;

            Weapon.Initialize();
            _gino.addHealth(progressData.addHealth);
            _gino.SetWeapon(new Weapon(progressData.shopWeapon, _gino));
            _gino.addAmmo(progressData.addAmmo);

            //_gino.SetWeapon(new Weapon("Revolver", _gino));

            _endTimer = TimeSpan.FromSeconds(TIME_AFTER_LOSS);
        }
 public CollisionLayers(Game game, World world, Map map)
 {
     layerVertices = new List<Vertices>();
     //Creates the collision boxes
     CreateStaticCollidables(GetLayers(map), world);
     line = game.Content.Load<Texture2D>("line");
 }
        public void Load(ContentManager cm)
        {
            _map = cm.Load<Map>("Maps\\Level1");

            // Figure out map rows/cols
            TileSheet ts = _map.GetTileSheet("Front");
            Vector2 tileSize = new Vector2(ts.TileWidth, ts.TileHeight);

            int mapSizeX = (int) (_map.DisplayWidth / tileSize.X);
            int mapSizeY = (int) (_map.DisplayHeight / tileSize.Y);

            TileArray tiles = _map.GetLayer("StaticCollidable").Tiles;

            // Get all static objects
            for (int row = 0; row < mapSizeY; ++row)
            {
                for (int col = 0; col < mapSizeX; ++col)
                {
                    if (tiles[col, row] == null)
                        continue;

                    Tile tile = tiles[col, row];

                    // Calculate origin-based position
                    Vector2 oPos = new Vector2(col, row);
                    oPos.X = oPos.X * tileSize.X;
                    oPos.Y = oPos.Y * tileSize.Y;

                    // Create MapTile
                    MapTile mTile = new MapTile(_world, tileSize, oPos);
                    _tiles.Add(mTile);
                }
            }
        }
Exemple #5
0
        public MapPropertiesDialog(Map map, bool isNewMap)
        {
            InitializeComponent();

            m_map = map;
            m_isNewMap = isNewMap;
        }
Exemple #6
0
        public MapStatisticsDialog(Map map, xTile.Dimensions.Rectangle viewport)
        {
            InitializeComponent();

            m_map = map;
            m_viewport = viewport;
        }
Exemple #7
0
 public TileSheetNewCommand(Map map, TileSheet newTileSheet, MapTreeView mapTreeView)
 {
     m_map = map;
     m_newTileSheet = newTileSheet;
     m_mapTreeView = mapTreeView;
     m_description = "Add new tile sheet \"" + newTileSheet.Id + "\"";
 }
Exemple #8
0
        public TileAnimationDialog(Map map, Layer layer, Location tileLocation)
        {
            InitializeComponent();

            m_map = map;
            m_layer = layer;
            m_tileLocation = tileLocation;
        }
Exemple #9
0
 public LayerDeleteCommand(Map map, Layer layer, MapTreeView mapTreeView)
 {
     m_map = map;
     m_layer = layer;
     m_layerIndex = map.Layers.IndexOf(layer);
     m_mapTreeView = mapTreeView;
     m_description = "Delete layer \"" + layer.Id + "\"";
 }
Exemple #10
0
        public TileBrushDialog(Map map, TileBrushCollection tileBrushCollection)
        {
            InitializeComponent();

            m_map = map;
            m_tileBrushCollection = tileBrushCollection;
            m_newTileBrush = null;
            m_selectedTileBrush = null;
        }
Exemple #11
0
        public virtual void update(GameTime gameTime, Map map)
        {
            if (collisionCD <= 0 && mAI.mHero.isAlive)
            {
                mAI.update(gameTime);
            }

            if (collisionCD > 0)
            {
                collisionCD--;
                Color tempTrans = new Color(mSprite.getColor().R, mSprite.getColor().G, mSprite.getColor().B, 0.75f);
                mSprite.setColor(tempTrans);
            }
            else
            {
                Color tempTrans = new Color(mSprite.getColor().R, mSprite.getColor().G, mSprite.getColor().B, 1.0f);
                mSprite.setColor(tempTrans);
            }

            if ((Math.Abs(mVelocity.X) > 30 || Math.Abs(mVelocity.Y) > 30) && collisionCD > 0)
            {
                int rotationDirection;

                if (random.Next(0, 1) == 0)
                {
                    rotationDirection = -1;
                }
                else
                {
                    rotationDirection = 1;
                }

                mSprite.setRotation(mSprite.getRotation() + (rotationDirection * ((mVelocity.X / 500) + (mVelocity.Y / 500)) / 2));
            }

            mVelocity *= 0.985f;

            Vector2 mNewPos = mPosition;
            mNewPos.X += (float)(mVelocity.X * gameTime.ElapsedGameTime.TotalSeconds);
            mNewPos.Y += (float)(mVelocity.Y * gameTime.ElapsedGameTime.TotalSeconds);

            checkCollision(ref mNewPos, map);
            mPosition = mNewPos;

            mSprite.setPosition(mPosition);

            mCurrentRect = new Microsoft.Xna.Framework.Rectangle((int)mPosition.X, (int)mPosition.Y,
                    (int)mSprite.getSourceRect().Width, (int)mSprite.getSourceRect().Height);

            mSprite.update(gameTime);
            mEffect.mOrigin = mSprite.getPosition();
            mEffect.update(gameTime);
        }
        public EditTileBrushesCommand(
            Map map,
            TileBrushCollection currentTileBrushCollection,
            TileBrushCollection newTileBrushCollection)
        {
            m_map = map;
            m_currentTileBrushCollection = currentTileBrushCollection;
            m_oldTileBrushCollection = new TileBrushCollection(currentTileBrushCollection);
            m_newTileBrushCollection = new TileBrushCollection(newTileBrushCollection);

            m_description = "Manage tile brushes";
        }
        public EditTileBrushesCommand(
            Map map,
            TileBrushCollection currentTileBrushCollection,
            TileBrush newTileBrush)
        {
            m_map = map;
            m_currentTileBrushCollection = currentTileBrushCollection;
            m_oldTileBrushCollection = new TileBrushCollection(currentTileBrushCollection);
            m_newTileBrushCollection = new TileBrushCollection(currentTileBrushCollection);
            m_newTileBrushCollection.TileBrushes.Add(newTileBrush);

            m_description = "Make new tile brush";
        }
Exemple #14
0
        public MapPropertiesCommand(Map map, string newId, string newDescription,
            PropertyCollection newProperties)
        {
            m_map = map;

            m_oldId = map.Id;
            m_oldDescription = map.Description;
            m_oldProperties = new PropertyCollection(map.Properties);

            m_newId = newId;
            m_newDescription = newDescription;
            m_newProperties = newProperties;

            m_description = "Change map properties";
        }
Exemple #15
0
        xTile.Dimensions.Rectangle _viewport; //camera

        #endregion Fields

        #region Constructors

        public Level(int levelNumber)
        {
            //set camera size based on screen size
            _viewport = new xTile.Dimensions.Rectangle(
                new xTile.Dimensions.Size(
                    Game1.SCREEN_WIDTH, Game1.SCREEN_HEIGHT));

            //load the map for the specified level
            _tileMap = Content.Load<Map>("Maps\\" + levelNumber);

            //load tile sheet
            _tileMap.LoadTileSheets(MapDisplayDevice);

            _collisionLayer = _tileMap.Layers[0];
        }
Exemple #16
0
        public InLevel(int levelNumber, ContentManager content)
        {
            //general purpose hit detection rectangle
            _hitRect = new Rectangle(0, 0, 0, 0);

            _sprite = new Sprite(content.Load<Texture2D>("character"), 48, 48, 2, 2, TimeSpan.FromSeconds(0.2), 4);
            _sprite.SetLocation(60, Game1.SCREEN_HEIGHT - 2 * Tile.TILE_WIDTH);

            _tileMap = content.Load<Map>("Maps/level1");
            _tileMap.LoadTileSheets(MapDisplayDevice);
            _viewport = new xTile.Dimensions.Rectangle(
                new xTile.Dimensions.Size(
                    Game1.SCREEN_WIDTH, Game1.SCREEN_HEIGHT));

            _collisionLayer = _tileMap.Layers[0];
        }
Exemple #17
0
        public CompatibilityReport DetermineCompatibility(Map map)
        {
            List<CompatibilityNote> compatibilityNotes = new List<CompatibilityNote>();

            if (map.Layers.Count != 1)
            {
                compatibilityNotes.Add(new CompatibilityNote(CompatibilityLevel.None,
                    "The map must contain exactly one layer"));
            }

            bool mixedTileSheets = false;
            bool nullTiles = false;
            bool animationTiles = false;
            foreach (Layer layer in map.Layers)
            {
                for (int tileY = 0; tileY < layer.LayerHeight; tileY++)
                {
                    for (int tileX = 0; tileX < layer.LayerWidth; tileX++)
                    {
                        Tile tile = layer.Tiles[tileX, tileY];
                        if (tile == null)
                            nullTiles = true;
                        else if (tile is AnimatedTile)
                            animationTiles = true;

                        // no need to test further?
                        if (mixedTileSheets && nullTiles && animationTiles)
                            goto CompatibilityTestEnd;
                    }
                }
            }
            CompatibilityTestEnd: // label to shorten compatibility test

            if (mixedTileSheets)
                compatibilityNotes.Add(new CompatibilityNote(CompatibilityLevel.None, "Cannot have multiple tile sheets per layer"));

            if (nullTiles)
                compatibilityNotes.Add(new CompatibilityNote(CompatibilityLevel.Partial, "Null tiles will be converted to the zero tile index"));

            if (animationTiles)
                compatibilityNotes.Add(new CompatibilityNote(CompatibilityLevel.Partial, "Animated tiles will be converted to static tiles"));

            CompatibilityReport compatibilityReport = new CompatibilityReport(compatibilityNotes);
            return compatibilityReport;
        }
        public TileSheetRemoveDependencyCommand(Map map, TileSheet tileSheet)
        {
            m_map = map;
            m_tileSheet = tileSheet;
            m_description = "Remove dependencies on tile sheet \"" + tileSheet.Id + "\"";

            m_tileSheetDependencies = new List<TileSheetDependency>();
            foreach (Layer layer in m_map.Layers)
            {
                Size layerSize = layer.LayerSize;
                Location location;
                for (location.Y = 0; location.Y < layerSize.Height; location.Y++)
                    for (location.X = 0; location.X < layerSize.Width; location.X++)
                    {
                        Tile tile = layer.Tiles[location];
                        if (tile != null && tile.DependsOnTileSheet(m_tileSheet))
                            m_tileSheetDependencies.Add(new TileSheetDependency(layer, location, tile));
                    }
            }
        }
Exemple #19
0
        /// <summary>
        /// Loads a map from a tbin file from the mod's asset folder.
        /// </summary>
        /// <param name="MapName"></param>
        /// <returns></returns>
        public static KeyValuePair <string, xTile.Map> LoadMap(string MapName)
        {
            // load the map file from your mod folder
            string pathToMaps = Path.Combine("Content", "Minigames", "SeasideScramble", "Maps", MapName);

            xTile.Map map = ModCore.ModHelper.Content.Load <Map>(pathToMaps, ContentSource.ModFolder);
            for (int index = 0; index < map.TileSheets.Count; ++index)
            {
                string imageSource = map.TileSheets[index].ImageSource;
                string fileName    = Path.GetFileName(imageSource);
                string path1       = Path.GetDirectoryName(imageSource);
                map.TileSheets[index].ImageSource = Path.Combine(path1, fileName);
            }
            map.LoadTileSheets(Game1.mapDisplayDevice);

            // get the internal asset key for the map file
            string mapAssetKey = ModCore.ModHelper.Content.GetActualAssetKey(MapName, ContentSource.ModFolder);

            return(new KeyValuePair <string, Map>(mapAssetKey, map));
        }
Exemple #20
0
        private void WriteChunkBGFX(Stream stream, Map map)
        {
            TileImageCache tileImageCache = TileImageCache.Instance;
            TileSheet tileSheet = map.TileSheets[0];
            xTile.Dimensions.Size tileSize = tileSheet.TileSize;
            int tileCount = tileSheet.TileCount;
            Rectangle tileRectangle = new Rectangle(0, 0, tileSize.Width, tileSize.Height);

            // assume 32bpp
            int blockSizeBytes = tileSize.Area * 4;

            WriteSequence(stream, "BGFX");
            // assume 32bpp gfx
            WriteMsb(stream, (long)(blockSizeBytes * tileCount));

            for (int tileIndex = 0; tileIndex < tileCount; tileIndex++)
            {
                Bitmap tileBitmap = tileImageCache.GetTileBitmap(tileSheet, tileIndex);

                for (int pixelY = 0; pixelY < tileSize.Height; pixelY++)
                {
                    for (int pixelX = 0; pixelX < tileSize.Width; pixelX++)
                    {
                        Color color = tileBitmap.GetPixel(pixelX, pixelY);
                        Write(stream, color.A);
                        Write(stream, color.R);
                        Write(stream, color.G);
                        Write(stream, color.B);
                    }
                }
            }
        }
Exemple #21
0
        private void WriteChunkATHR(Stream stream, Map map)
        {
            // ATHR chunk
            string[] authorLines = map.Description.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int athrChunkLength = 0;
            foreach (string authorLine in authorLines)
                athrChunkLength += authorLine.Length + 1;

            bool athrPadding = false;
            if (athrChunkLength % 2 != 0)
            {
                ++athrChunkLength;
                athrPadding = true;
            }

            WriteSequence(stream, "ATHR");
            WriteMsb(stream, (long)athrChunkLength);
            foreach (string authorLine in authorLines)
                WriteNullTerminatedString(stream, authorLine);
            if (athrPadding)
                Write(stream, (byte)0);
        }
Exemple #22
0
        public Map Load(Stream stream)
        {
            ReadHeader(stream);

            MphdRecord mphdRecord = null;
            string[] authorLines = null;
            Color[] colourMap = null;
            BlockRecord[] blockRecords = null;
            AnimationRecord[] animationRecords = null;
            Image imageSource = null;
            short[][] layers = new short[8][];

            Dictionary<string, Chunk> chunks = MapChunks(stream);

            if (!chunks.ContainsKey("MPHD"))
                throw new Exception("Header chunk MPHD missing");
            Chunk mphdChunk = chunks["MPHD"];
            mphdRecord = ReadChunkMPHD(stream, mphdChunk);

            if (mphdRecord.BlockDepth == 8)
            {
                if (!chunks.ContainsKey("CMAP"))
                    throw new Exception("Colour map chuck CMAP is required for 8bit graphics blocks");
                Chunk cmapChunk = chunks["CMAP"];
                colourMap = ReadChunkCMAP(stream, cmapChunk);
            }

            if (chunks.ContainsKey("ATHR"))
                authorLines = ReadChunkATHR(stream, chunks["ATHR"]);

            if (!chunks.ContainsKey("BKDT"))
                throw new Exception("Block data chunk BKDT missing");
            Chunk bkdtChunk = chunks["BKDT"];
            blockRecords = ReadChunkBKDT(stream, bkdtChunk, mphdRecord);

            // optional ?
            if (chunks.ContainsKey("ANDT"))
            {
                Chunk andtChunk = chunks["ANDT"];
                animationRecords = ReadChunkANDT(stream, andtChunk, mphdRecord);
            }

            if (!chunks.ContainsKey("BGFX"))
                throw new Exception("Block graphics chunk BGFX missing");
            Chunk bgfxChunk = chunks["BGFX"];
            imageSource = ReadChunkBGFX(stream, bgfxChunk, mphdRecord, colourMap);

            if (!chunks.ContainsKey("BODY"))
                throw new Exception("Body chunk BODY missing");
            Chunk bodyChunk = chunks["BODY"];
            layers[0] = ReadChunkLayer(stream, bodyChunk, mphdRecord);

            // additional layers
            for (int layer = 1; layer <= 7; layer++)
            {
                string chunkId = "LYR" + layer;
                if (chunks.ContainsKey(chunkId))
                {
                    Chunk layerChuck = chunks[chunkId];
                    layers[layer] = ReadChunkLayer(stream, layerChuck, mphdRecord);
                }
            }

            // new map
            Map map = new Map();

            // attach ATHR lines as description
            if (authorLines != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string authorLine in authorLines)
                    stringBuilder.AppendLine(authorLine);
                map.Description = stringBuilder.ToString();
            }

            // prompt user to save tilesheet image source
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.CheckPathExists = true;
            saveFileDialog.Filter = "Portable Network Geaphics (*.png)|*.png";
            saveFileDialog.OverwritePrompt = true;
            saveFileDialog.Title = "Save tile sheet image source as";
            saveFileDialog.ValidateNames = true;
            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
                throw new Exception("Mappy FMAP file import aborted");

            string tileSheetImageSource = saveFileDialog.FileName;

            imageSource.Save(tileSheetImageSource, ImageFormat.Png);

            // determine global tile size
            xTile.Dimensions.Size tileSize = new xTile.Dimensions.Size(mphdRecord.BlockWidth, mphdRecord.BlockHeight);

            // add tilesheet
            TileSheet tileSheet = new TileSheet("BGFX", map, tileSheetImageSource,
                new xTile.Dimensions.Size(1, mphdRecord.NumBlockGfx), tileSize);
            map.AddTileSheet(tileSheet);

            // determine global map size
            xTile.Dimensions.Size mapSize = new xTile.Dimensions.Size(mphdRecord.MapWidth, mphdRecord.MapHeight);

            // create layers
            for (int layerIndex = 0; layerIndex < 8; layerIndex++)
            {
                if (layers[layerIndex] == null)
                    continue;

                string layerId = layerIndex == 0 ? "BODY" : "LYR" + layerIndex;
                Layer layer = new Layer(layerId, map, mapSize, tileSize);
                map.AddLayer(layer);
                for (int tileY = 0; tileY < mapSize.Height; tileY++)
                {
                    for (int tileX = 0; tileX < mapSize.Width; tileX++)
                    {
                        int layerOffset = tileY * mapSize.Width + tileX;
                        int tileIndex = layers[layerIndex][layerOffset];
                        if (tileIndex >= 0)
                        {
                            layer.Tiles[tileX, tileY] = new StaticTile(layer, tileSheet, BlendMode.Alpha, tileIndex);
                        }
                        else
                        {
                            AnimationRecord animationRecord = animationRecords[-tileIndex - 1];
                            StaticTile[] tileFrames = new StaticTile[animationRecord.Frames.Length];

                            for (int frameIndex = 0; frameIndex < animationRecord.Frames.Length; frameIndex++)
                                tileFrames[frameIndex] = new StaticTile(layer, tileSheet, BlendMode.Alpha, animationRecord.Frames[frameIndex]);

                            // process loop types
                            switch (animationRecord.Type)
                            {
                                case 2: // LOOPR: loop backward
                                    Array.Reverse(tileFrames);
                                    break;
                                case 5: // PPFF -+
                                case 6: // PPRR  | - different states for ping-pong animation
                                case 7: // PPRF  | - treat all the same
                                case 8: // PPFR -+
                                    StaticTile[] pingPongFrames = new StaticTile[tileFrames.Length * 2 - 1];
                                    Array.Copy(tileFrames, pingPongFrames, tileFrames.Length);
                                    Array.Copy(tileFrames, 0, pingPongFrames, tileFrames.Length, tileFrames.Length - 1);
                                    Array.Reverse(pingPongFrames, tileFrames.Length, tileFrames.Length - 1);
                                    tileFrames = pingPongFrames;
                                    break;
                                default: // treat all other cases as LOOPF
                                    // 0 = NONE
                                    // 1 = LOOPF: loop forward
                                    // 3 = ONCE, 4 = ONCEH: one-off animations
                                    // 9 = ONCES: one-off animations
                                    break;
                            }

                            AnimatedTile animatedTile = new AnimatedTile(layer, tileFrames, (long)animationRecord.Delay * 20);
                            layer.Tiles[tileX, tileY] = animatedTile;
                        }
                    }
                }
            }

            return map;
        }
Exemple #23
0
        private AnimatedTile[] WriteChunkANDT(Stream stream, Map map)
        {
            // build list of unique animations
            List<AnimatedTile> animatedTiles = new List<AnimatedTile>();
            foreach (Layer layer in map.Layers)
            {
                for (int tileY = 0; tileY < layer.LayerHeight; tileY++)
                {
                    for (int tileX = 0; tileX < layer.LayerWidth; tileX++)
                    {
                        Tile tile = layer.Tiles[tileX, tileY];
                        if (tile == null || !(tile is AnimatedTile))
                            continue;
                        AnimatedTile newAnimatedTile = (AnimatedTile)tile;

                        bool matches = false;
                        foreach (AnimatedTile animatedTile in animatedTiles)
                            if (AnimationsMatch(animatedTile, newAnimatedTile))
                            {
                                matches = true;
                                break;
                            }
                        if (!matches)
                            animatedTiles.Add(newAnimatedTile);
                    }
                }
            }

            // if there are no animations, do not write ANDT chunk at all
            if (animatedTiles.Count == 0)
                return null;

            // determine offsets length
            int offsetsLength = 0;
            foreach (AnimatedTile animatedTile in animatedTiles)
                offsetsLength += (animatedTile.TileFrames.Length + 1) * 4; // +1 is for anim ref tile

            // chunk length is space for offsets + termination ani record + all ani records
            int chunkLength = offsetsLength + (animatedTiles.Count + 1) * AnimationRecord.SIZE;

            // write chunk header
            WriteSequence(stream, "ANDT");
            WriteMsb(stream, (long)chunkLength);

            long chunkStart = stream.Position;

            // write animation offsets
            List<long> animationPositions = new List<long>();
            foreach (AnimatedTile animatedTile in animatedTiles)
            {
                // animation ref tile
                WriteLsb(stream, (long)(animatedTile.TileFrames[0].TileIndex * 32));

                // keep track of stream pos to compute anim offsets
                animationPositions.Add(stream.Position - chunkStart);

                // animation indices * block struct size
                foreach (StaticTile tileFrame in animatedTile.TileFrames)
                    WriteLsb(stream, (long) (tileFrame.TileIndex * 32));
            }

            // write termination animation record
            Write(stream, (sbyte)-1);    // type = end of animations
            Write(stream, (sbyte)0);     // delay
            Write(stream, (sbyte)0);     // counter
            Write(stream, (sbyte)0);     // user info
            WriteLsb(stream, (long)0);   // current offset
            WriteLsb(stream, (long)0);   // start offset
            WriteLsb(stream, (long)0);   // end offset

            // write animation records
            for (int index = 0; index < animatedTiles.Count; index++)
            {
                AnimatedTile animatedTile = animatedTiles[index];
                long animationPosition = animationPositions[index];

                sbyte delay = (sbyte)(animatedTile.FrameInterval / 20);
                long animationOffsetStart = animationPosition - chunkLength;
                long animationOffsetend = animationOffsetStart + animatedTile.TileFrames.Length * 4;

                Write(stream, (byte)1);                   // type = LOOPF
                Write(stream, delay);                     // delay
                Write(stream, (sbyte)0);                  // counter
                Write(stream, (sbyte)0);                  // user info
                WriteLsb(stream, animationOffsetStart);   // current offset
                WriteLsb(stream, animationOffsetStart);   // start offset
                WriteLsb(stream, animationOffsetend);     // end offset
            }

            return animatedTiles.ToArray();
        }
Exemple #24
0
        public void Store(Map map, Stream stream)
        {
            // main file header
            WriteHeader(stream);

            // ATHR chunk
            WriteChunkATHR(stream, map);

            // MPHD chunk
            WriteChunkMPHD(stream, map);

            // no CMAP chunk

            // BKDT chunk
            WriteChunkBKDT(stream, map);

            // ANDT chunk
            AnimatedTile[] animatedTiles = WriteChunkANDT(stream, map);

            // BGFX chunk
            WriteChunkBGFX(stream, map);

            // BODY chunk
            WriteChunkLayer(stream, map.Layers[0], "BODY", animatedTiles);

            // LYR? chunks
            for (int layerIndex = 1; layerIndex < map.Layers.Count; layerIndex++)
            {
                string chunkId = "LYR" + layerIndex;
                WriteChunkLayer(stream, map.Layers[layerIndex], chunkId, animatedTiles);
            }

            // update header
            long dataEnd = stream.Position;
            long contentLength = dataEnd - 8;
            stream.Position = 4;
            WriteMsb(stream, contentLength);
            stream.Position = dataEnd;
        }
Exemple #25
0
        private void WriteChunkMPHD(Stream stream, Map map)
        {
            WriteSequence(stream, "MPHD");

            // write dummy length
            long chunkLengthPosition = stream.Position;
            WriteMsb(stream, (long)0);

            long chunkDataStart = stream.Position;

            // write version (1.0)
            Write(stream, (sbyte)1);
            Write(stream, (sbyte)0);

            // write LSB (true)
            Write(stream, (sbyte)1);

            // write map type (0)
            Write(stream, (sbyte)0);

            // write map dimensions
            short mapWidth = (short)map.Layers[0].LayerWidth;
            short mapHeight = (short)map.Layers[0].LayerHeight;
            WriteLsb(stream, mapWidth);
            WriteLsb(stream, mapHeight);

            // write 2 reserved shorts (0)
            WriteLsb(stream, (short)0);
            WriteLsb(stream, (short)0);

            // write tile dimensions
            short blockWidth = (short)map.TileSheets[0].TileWidth;
            short blockHeight = (short)map.TileSheets[0].TileHeight;
            WriteLsb(stream, blockWidth);
            WriteLsb(stream, blockHeight);

            // write blockdepth (forced to 32bpp)
            WriteLsb(stream, (short)32);

            // write block struct size (forced to 32 bytes)
            WriteLsb(stream, (short)32);

            // write num blocks and gfx blocks (= tile count)
            short blockCount = (short)map.TileSheets[0].TileCount;
            WriteLsb(stream, blockCount);
            WriteLsb(stream, blockCount);

            // do not write colour key indices/values, block gaps/staggers
            // and click mask, pillars

            long chunkDataEnd = stream.Position;
            long chunkLength = chunkDataEnd - chunkDataStart;

            // update chunk length
            stream.Position = chunkLengthPosition;
            WriteMsb(stream, chunkLength);

            // restore stream to end of chunk
            stream.Position = chunkDataEnd;
        }
Exemple #26
0
        private void WriteChunkBKDT(Stream stream, Map map)
        {
            short blockCount = (short) map.TileSheets[0].TileCount;

            WriteSequence(stream, "BKDT");
            // block records asumed 32 bytes
            WriteMsb(stream, blockCount * 32);

            // block size assumes 32bpp
            xTile.Dimensions.Size blockSize = map.TileSheets[0].TileSize;
            int blockByteSize = blockSize.Width * blockSize.Height * 4;

            for (int index = 0; index < blockCount; index++)
            {
                // bg, f2, bg2, fg2 offsets
                WriteLsb(stream, (long) (index * blockByteSize));
                WriteLsb(stream, (long) 0);
                WriteLsb(stream, (long) 0);
                WriteLsb(stream, (long) 0);

                // user1, user2 ulongs
                WriteLsb(stream, (ulong)0);
                WriteLsb(stream, (ulong)0);

                // user3, user4 ushorts
                WriteLsb(stream, (ushort)0);
                WriteLsb(stream, (ushort)0);

                // user5 - user7, flags unsigned bytes
                Write(stream, (byte)0);
                Write(stream, (byte)0);
                Write(stream, (byte)0);
                Write(stream, (byte)0);
            }
        }
Exemple #27
0
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // dispose map resoures
            m_map.DisposeTileSheets(m_xnaDisplayDevice);
            m_map = null;

            // dispose other objects
            m_spriteFontDemo = null;
            m_texturePanel = null;
        }
Exemple #28
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.
            m_spriteBatch = new SpriteBatch(GraphicsDevice);
            m_xnaDisplayDevice = new XnaDisplayDevice(Content, GraphicsDevice);

            // load font for help text
            m_spriteFontDemo = Content.Load<SpriteFont>("Fonts/Demo");

            m_textureLeaf = Content.Load<Texture2D>("Graphics/Leaf");

            // load map from content pipeline and initialise it
            m_map = Content.Load<Map>("Maps\\Map01");
            m_map.LoadTileSheets(m_xnaDisplayDevice);

            m_map.Layers[3].BeforeDraw += OnBeforeLayerDraw;

            // prepare translucent panel for help text
            m_texturePanel = new Texture2D(GraphicsDevice, 1, 1);
            m_texturePanel.SetData<Color>(new Color[] { new Color(0, 0, 0, 128) });
        }
        /// <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);

            map = Content.Load<Map>("Maps\\Map01");
            // TODO: use this.Content to load your game content here
        }
Exemple #30
0
 public SeasideScrambleMap(Map Map)
 {
     this.map = Map;
     //this.map.LoadTileSheets(Game1.mapDisplayDevice);
 }
Exemple #31
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);
            Spritesheet = Content.Load<Texture2D>(@"SpriteSheet");
            map = Content.Load<Map>("pacmanmap");
            menuMusic = Content.Load<Song>("introMusic");
            map.LoadTileSheets(xnaDisplayDevice);
            MediaPlayer.Play(menuMusic);

            pizzaguy = new PizzaGuy(new Vector2(32, 32), Spritesheet, new Rectangle(300, 300, 32, 32), Vector2.Zero, map.GetLayer("untitled layer"));
            ghost = new Ghost(new Vector2(32, 32*10), Spritesheet, new Rectangle(500, 300, 32, 32), Vector2.Zero, map.GetLayer("untitled layer"), pizzaguy);

            // TODO: use this.Content to load your game content here
        }
Exemple #32
0
 public LayerNewCommand(Map map, Layer newLayer)
 {
     m_map = map;
     m_newLayer = newLayer;
     m_description = "Add new layer \"" + newLayer.Id + "\"";
 }