Exemplo n.º 1
0
        public static void UpdateHelperText()
        {
            if (Systems.scene is EditorScene == false)
            {
                return;
            }
            EditorScene editorScene = (EditorScene)Systems.scene;

            // Tile Tool Helper Text
            if (EditorTools.tileTool != null)
            {
                EditorPlaceholder ph = EditorTools.tileTool.CurrentPlaceholder;

                // Display Tile Helper Text
                if (ph.tileId > 0)
                {
                    // If there's an error here, we need to add the value to TileDict.
                    TileObject tile = Systems.mapper.TileDict[ph.tileId];

                    if (tile.titles != null)
                    {
                        editorScene.editorUI.statusText.SetText(tile.titles[ph.subType], tile.descriptions[ph.subType]);
                        return;
                    }

                    else if (tile.title.Length > 0)
                    {
                        editorScene.editorUI.statusText.SetText(tile.title, tile.description);
                        return;
                    }
                }

                // Display Object Helper Text
                if (ph.objectId > 0)
                {
                    string title = ShadowTile.ObjHelpText[ph.objectId][ph.subType][0];
                    string desc  = ShadowTile.ObjHelpText[ph.objectId][ph.subType][1];

                    editorScene.editorUI.statusText.SetText(title, desc);
                    return;
                }
            }

            editorScene.editorUI.statusText.ClearStatus();
        }
Exemplo n.º 2
0
        // Check if Grid Square is a Blocking Square (Ground, BlockTile, HorizontalWall, etc.)
        public static bool IsBlockingSquare(TilemapLevel tilemap, short gridX, short gridY, DirCardinal dir)
        {
            // Verify that a tile exists at the given location:
            byte[] tileData = tilemap.GetTileDataAtGrid(gridX, gridY);

            // If the tile was removed, never existed, or the main layer has no content:
            if (tileData == null || tileData[0] == 0)
            {
                return(false);
            }

            TileObject tileObj = Systems.mapper.TileDict[tileData[0]];

            // Make sure the tile exists and collides, otherwise there's no point in testing any further:
            if (tileObj == null || !tileObj.collides)
            {
                return(false);
            }

            // Check if the Tile is Blocking:
            if (tileObj is Ground || tileObj is BlockTile || tileObj is HorizontalWall || tileObj is ButtonFixed || tileObj is SpringFixed || tileObj is Cannon || tileObj is Placer)
            {
                return(true);
            }

            if (tileObj is Ledge)
            {
                return(dir == DirCardinal.Down);
            }

            // Tile may be blocking against specific directions:
            if (dir == DirCardinal.Down)
            {
                if (tileObj is PlatformFixedUp)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        // Perform Collision Detection against a designated Grid Square
        public static bool RunGridTest(GameObject actor, short gridX, short gridY, DirCardinal dir)
        {
            // Verify that a tile exists at the given location:
            byte[] tileData = actor.room.tilemap.GetTileDataAtGrid(gridX, gridY);

            // If the tile was removed, never existed, or the main layer has no content:
            if (tileData == null || tileData[0] == 0)
            {
                return(false);
            }

            TileObject tileObj = Systems.mapper.TileDict[tileData[0]];

            // Make sure the tile exists and collides, otherwise there's no point in testing any further:
            if (tileObj == null || !tileObj.collides)
            {
                return(false);
            }

            // Run Tile Collision
            return(tileObj.RunImpact(actor.room, actor, gridX, gridY, dir));
        }
Exemplo n.º 4
0
        public void DrawBlueprintByLayer(LayerEnum layerEnum, short x, short y, short xStart, short yStart)
        {
            // Get the value stored in this blueprint at correct tile position:
            ArrayList bpData = this.gridTrack[(byte)layerEnum, y, x];

            if (bpData == null)
            {
                return;
            }

            // Verify that a TileID (or ObjectID) is present
            byte objOrTileID = byte.Parse(bpData[0].ToString());

            if (objOrTileID == 0)
            {
                return;
            }

            // Drawing Objects
            if (layerEnum == LayerEnum.obj)
            {
                ShadowTile.Draw(objOrTileID, byte.Parse(bpData[1].ToString()), null, (xStart + x) * (byte)TilemapEnum.TileWidth - Systems.camera.posX, (yStart + y) * (byte)TilemapEnum.TileHeight - Systems.camera.posY);
            }

            // Drawing Tiles
            else
            {
                var tileDict = Systems.mapper.TileDict;

                if (tileDict.ContainsKey(objOrTileID))
                {
                    TileObject tgo = tileDict[objOrTileID];
                    tgo.Draw(null, byte.Parse(bpData[1].ToString()), (xStart + x) * (byte)TilemapEnum.TileWidth - Systems.camera.posX, (yStart + y) * (byte)TilemapEnum.TileHeight - Systems.camera.posY);
                }
            }
        }
Exemplo n.º 5
0
        public override void Draw()
        {
            //Systems.timer.stopwatch.Start();

            Camera cam = Systems.camera;

            cam.StayBounded((byte)TilemapEnum.GapLeftPixel, this.Width + (byte)TilemapEnum.GapLeftPixel, (byte)TilemapEnum.GapUpPixel, this.Height + (byte)TilemapEnum.GapUpPixel);

            short startX = Math.Max((short)0, cam.GridX);
            short startY = Math.Max((short)0, cam.GridY);

            // Must adjust for the World Gaps (Resistance Barrier)
            if (startX < (byte)TilemapEnum.GapLeft)
            {
                startX = (byte)TilemapEnum.GapLeft;
            }
            if (startY < (byte)TilemapEnum.GapUp)
            {
                startY = (byte)TilemapEnum.GapUp;
            }

            short gridX = (short)(startX + (byte)TilemapEnum.MinWidth + 1);             // 30 is view size. +1 is to render the edge.
            short gridY = (short)(startY + (byte)TilemapEnum.MinHeight + 1);            // 18 is view size. +1 is to render the edge.

            if (gridX > this.tilemap.XCount)
            {
                gridX = (short)(this.tilemap.XCount + (byte)TilemapEnum.GapLeft);
            }                                                                                                                 // Must limit to room size.
            if (gridY > this.tilemap.YCount)
            {
                gridY = (short)(this.tilemap.YCount + (byte)TilemapEnum.GapUp);
            }                                                                                                               // Must limit to room size.

            // Camera Position
            bool isShaking = cam.IsShaking();
            int  camX      = cam.posX + (isShaking ? cam.GetCameraShakeOffsetX() : 0);
            int  camY      = cam.posY + (isShaking ? cam.GetCameraShakeOffsetY() : 0);
            int  camRight  = camX + cam.width;
            int  camBottom = camY + cam.height + (byte)TilemapEnum.TileHeight;

            // Run Parallax Handler
            this.parallax.Draw();

            var tileMap = Systems.mapper.TileDict;

            // Loop through the tilemap data:
            for (short y = gridY; y-- > startY;)
            {
                short tileYPos = (short)(y * (byte)TilemapEnum.TileHeight - camY);

                for (short x = gridX; x-- > startX;)
                {
                    // Scan the Tiles Data at this grid square:
                    byte[] tileData = tilemap.GetTileDataAtGrid(x, y);

                    // This occurs when there is no data on the tile (removed, etc).
                    if (tileData == null)
                    {
                        continue;
                    }

                    // Draw Background Layer
                    if (tileData[2] != 0)
                    {
                        TileObject tileObj = tileMap[tileData[2]];

                        // Render the tile with its designated Class Object:
                        if (tileObj is TileObject)
                        {
                            tileObj.Draw(this, tileData[3], x * (byte)TilemapEnum.TileWidth - camX, tileYPos);
                        }
                        ;
                    }

                    // Draw Main Layer
                    if (tileData[0] != 0)
                    {
                        TileObject tileObj = tileMap[tileData[0]];

                        // Render the tile with its designated Class Object:
                        if (tileObj is TileObject)
                        {
                            tileObj.Draw(this, tileData[1], x * (byte)TilemapEnum.TileWidth - camX, tileYPos);
                        }
                        ;
                    }

                    // Draw Foreground Layer
                    if (tileData[4] != 0)
                    {
                        TileObject tileObj = tileMap[tileData[4]];

                        // Render the tile with its designated Class Object:
                        if (tileObj is TileObject)
                        {
                            tileObj.Draw(this, tileData[5], x * (byte)TilemapEnum.TileWidth - camX, tileYPos);
                        }
                        ;
                    }
                }
                ;
            }

            // Draw object data:
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.Platform], camX, camY, camRight, camBottom);
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.Enemy], camX, camY, camRight, camBottom);
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.Item], camX, camY, camRight, camBottom);
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.TrailingItem], camX, camY, camRight, camBottom);
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.Character], camX, camY, camRight, camBottom);
            this.DrawObjectGroup(this.objects[(byte)LoadOrder.Projectile], camX, camY, camRight, camBottom);

            // Draw Particles
            this.particleHandler.Draw();

            // Draw Frame Debugging Aid
            if (DebugConfig.DrawDebugFrames)
            {
                this.DrawDebug(camX, camY, camRight, camBottom);
            }

            // Debugging
            //Systems.timer.stopwatch.Stop();
            //System.Console.WriteLine("Benchmark: " + Systems.timer.stopwatch.ElapsedTicks + ", " + Systems.timer.stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 6
0
        public void Draw()
        {
            if (EditorTools.tileTool is TileTool == false)
            {
                return;
            }

            byte tileHeight = (byte)TilemapEnum.TileHeight + 2;

            // Draw Editor Scroller Background
            Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y, this.width, this.height), Color.DarkSlateGray);
            Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x + 2, this.y + 2, (byte)TilemapEnum.TileWidth, this.height - 6), Color.White);

            // Grid Outline
            for (byte i = 1; i < (byte)EScrollerEnum.NumTiles; i++)
            {
                Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y + i * tileHeight, this.width, 2), Color.DarkSlateGray);
            }

            // Draw TileTool Subtype Buttons
            List <EditorPlaceholder[]> placeholders = EditorTools.tileTool.placeholders;

            // Placeholder Loop
            byte len = (byte)placeholders.Count;

            EditorPlaceholder[] pData = placeholders[EditorTools.tileTool.index];

            byte phSubLen = (byte)pData.Length;

            for (byte s = 0; s < phSubLen; s++)
            {
                EditorPlaceholder ph = pData[s];

                byte subType = ph.subType;
                byte tileId  = ph.tileId;

                // Draw Tiles
                if (tileId > 0)
                {
                    if (Systems.mapper.TileDict.ContainsKey(tileId))
                    {
                        TileObject tgo = Systems.mapper.TileDict[tileId];
                        tgo.Draw(null, subType, this.x + 2, this.y + 50 * s + 2);
                    }
                }

                // Draw Objects
                else if (ph.objectId > 0)
                {
                    ShadowTile.Draw(ph.objectId, ph.subType, null, this.x + 2, this.y + 50 * s + 2);
                }
            }

            // Highlight the active color
            short my = (short)Snap.GridFloor(tileHeight, EditorTools.tileTool.subIndex * tileHeight - this.y);

            Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my * tileHeight, this.width, tileHeight), Color.White * 0.5f);

            // Hovering Visual
            if (UIComponent.ComponentWithFocus is EditorScroller)
            {
                short my2 = (short)Snap.GridFloor(tileHeight, Cursor.MouseY - this.y);

                Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my2 * tileHeight, this.width, tileHeight), Color.White * 0.5f);
            }
        }
Exemplo n.º 7
0
        // Initialize Wand Data
        public static bool InitializeWandData(EditorRoomScene scene, short gridX, short gridY)
        {
            // Get Scene References
            WandData.editorScene   = scene;
            WandData.moveParamMenu = WandData.editorScene.scene.editorUI.moveParamMenu;
            WandData.actParamMenu  = WandData.editorScene.scene.editorUI.actParamMenu;
            WandData.levelContent  = WandData.editorScene.levelContent;

            RoomFormat roomData = WandData.levelContent.data.rooms[WandData.editorScene.roomID];

            // Verify that Tile is Valid:
            WandData.validTile = false;

            if (LevelContent.VerifyTiles(roomData.main, gridX, gridY))
            {
                WandData.layerData = roomData.main;
                WandData.isObject  = false;
            }

            else if (LevelContent.VerifyTiles(roomData.fg, gridX, gridY))
            {
                WandData.layerData = roomData.fg;
                WandData.isObject  = false;
            }

            else if (LevelContent.VerifyTiles(roomData.obj, gridX, gridY))
            {
                WandData.layerData = roomData.obj;
                WandData.isObject  = true;
            }

            else
            {
                return(false);
            }

            WandData.validTile = true;

            WandData.gridX = gridX;
            WandData.gridY = gridY;

            // Get Tile Content Data
            WandData.wandTileData = LevelContent.GetTileDataWithParams(WandData.layerData, WandData.gridX, WandData.gridY);

            // Get the Param Set Used
            Params moveParamSet = null;
            Params actParamSet  = null;

            if (WandData.isObject)
            {
                moveParamSet = Systems.mapper.ObjectMetaData[byte.Parse(WandData.wandTileData[0].ToString())].moveParamSet;
                actParamSet  = Systems.mapper.ObjectMetaData[byte.Parse(WandData.wandTileData[0].ToString())].actParamSet;
            }
            else
            {
                TileObject wandTile = Systems.mapper.TileDict[byte.Parse(WandData.wandTileData[0].ToString())];
                moveParamSet = wandTile.moveParamSet;
                actParamSet  = wandTile.actParamSet;
            }

            // If the tile has param sets, it can be used here. Otherwise, return.
            WandData.validTile = (moveParamSet != null || actParamSet != null);
            if (WandData.validTile == false)
            {
                return(false);
            }

            WandData.moveParamSet = moveParamSet;
            WandData.actParamSet  = actParamSet;

            return(true);
        }
Exemplo n.º 8
0
        private void DrawLayer(Dictionary <string, Dictionary <string, ArrayList> > layerData)
        {
            Camera cam = Systems.camera;

            short startX = Math.Max((short)0, cam.GridX);
            short startY = Math.Max((short)0, cam.GridY);

            short gridX = (short)(startX + (byte)TilemapEnum.MinWidth + 1);             // +1 is to render the edge.
            short gridY = (short)(startY + (byte)TilemapEnum.MinHeight + 1);            // +1 is to render the edge.

            if (gridX > this.xCount)
            {
                gridX = this.xCount;
            }                                                            // Must limit to room size.
            if (gridY > this.yCount)
            {
                gridY = this.yCount;
            }                                                            // Must limit to room size.

            // Camera Position
            bool isShaking = cam.IsShaking();
            int  camX      = cam.posX + (isShaking ? cam.GetCameraShakeOffsetX() : 0);
            int  camY      = cam.posY + (isShaking ? cam.GetCameraShakeOffsetY() : 0);

            var tileDict = Systems.mapper.TileDict;

            // Loop through the tilemap data:
            for (short y = gridY; y-- > startY;)
            {
                short tileYPos = (short)(y * (byte)TilemapEnum.TileHeight - camY);

                string yStr = y.ToString();

                // Make sure this Y-line exists, or skip further review:
                if (!layerData.ContainsKey(yStr))
                {
                    continue;
                }
                var yData = layerData[yStr];

                for (short x = gridX; x-- > startX;)
                {
                    // Verify Tile Data exists at this Grid Square:
                    if (!yData.ContainsKey(x.ToString()))
                    {
                        continue;
                    }
                    var  xData   = yData[x.ToString()];
                    byte index   = byte.Parse(xData[0].ToString());
                    byte subType = byte.Parse(xData[1].ToString());

                    // Draw Layer
                    TileObject tileObj = tileDict[index];

                    // Render the tile with its designated Class Object:
                    if (tileObj is TileObject)
                    {
                        tileObj.Draw(null, subType, x * (byte)TilemapEnum.TileWidth - camX, tileYPos);
                    }
                    ;
                }
                ;
            }
        }