public void Draw(Graphics g)
        {
            if (isDirty)
            {
                isDirty = false;
                if (cachImage != null)
                {
                    cachImage.Dispose();
                }
                cachImage = new Bitmap(stageWidth, stageHeight);
                Graphics cg = Graphics.FromImage(cachImage);

                foreach (var memMapPoint in Cells)
                {
                    cg.DrawImage(TileBook.GetTileImage(memMapPoint.Tile, CardSize, CardSize), memMapPoint.X, memMapPoint.Y, CardSize, CardSize);

                    var tileConfig = ConfigData.GetTileConfig(memMapPoint.Tile);
                    if (tileConfig.ShowBorder)
                    {
                        Pen pen = new Pen(Brushes.DarkRed, 1);
                        cg.DrawRectangle(pen, memMapPoint.X, memMapPoint.Y, CardSize - 1, CardSize);
                        pen.Dispose();
                    }

#if DEBUG
                    Font font = new Font("Arial", 7 * 1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
                    g.DrawString(memMapPoint.Owner.ToString(), font, Brushes.White, memMapPoint.X, memMapPoint.Y + 10);
                    font.Dispose();
#endif
                }
                cg.Dispose();
            }
            g.DrawImageUnscaled(cachImage, 0, 0, stageWidth, stageHeight);
        }
Exemple #2
0
    private void DetectClick()
    {
        // Get mouse position
        Vector3 clickPosition;

        clickPosition = cam.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward * 10.0f;
        if (Input.GetMouseButton(0))
        {
            // Get tile map index of mouse position
            Vector3Int mapIndex   = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0);
            float      dstToClick = (clickPosition - transform.position).magnitude;
            // Check if mouse position is in range of player
            if (dstToClick <= clickReach && StaticMaps.worldMap.GetTile(mapIndex) != TileBook.GetTileByName("Space"))
            {
                breakTimer += Time.deltaTime;
                // Once break timer has exceeded value remove tile
                if (breakTimer >= 1.0f)
                {
                    if (StaticMaps.objectMap.GetTile(mapIndex) != TileBook.GetTileByName("NullObject") &&
                        StaticMaps.objectMap.GetTile(mapIndex) != null)
                    {
                        StaticMaps.SetTile(StaticMaps.MapType.Object, mapIndex, TileBook.GetTileByName("NullObject"));
                    }
                    else
                    {
                        StaticMaps.SetTile(StaticMaps.MapType.World, mapIndex, TileBook.GetTileByName("Space"));
                    }
                    breakTimer = 0.0f;
                    // Check for change in air seal
                    DetectSeal.CheckSeal();
                }
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            // If click detected check if within place range
            float dstToClick = (clickPosition - transform.position).magnitude;
            if (dstToClick <= clickReach && canPlace && Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile != null)
            {
                // Set tile at index to current tile
                if (TileBook.GetTileDataByName(Toolbar.GetItemByIndex(Toolbar.currentIndex).itemName).GetTileType() == TileData.TileType.WorldTile)
                {
                    Vector3Int mapIndex = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0);
                    StaticMaps.SetTile(StaticMaps.MapType.World, mapIndex, Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile);
                }
                else if (TileBook.GetTileDataByName(Toolbar.GetItemByIndex(Toolbar.currentIndex).itemName).GetTileType() == TileData.TileType.ObjectTile)
                {
                    Vector3Int mapIndex = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0);
                    StaticMaps.SetTile(StaticMaps.MapType.Object, mapIndex, Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile);
                }
                DetectSeal.CheckSeal();
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            breakTimer = 0.0f;
        }

        StaticMaps.breakTimer = breakTimer;
    }
Exemple #3
0
    void Start()
    {
        cam = Camera.main;
        Toolbar.InitToolBar(10);

        // Fill toolbar with debug items
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Floor"), 1), 0);
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Wall"), 1), 1);
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Object"), 1), 2);
    }
Exemple #4
0
        public void Init()
        {
            //50每格子
            Width     = Height = 30;
            tileArray = new TileInfo[Width, Height];
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    if ((i + j) % 5 == 1)
                    {
                        tileArray[i, j] = new TileInfo {
                            CId = 3
                        }
                    }
                    ;
                    else
                    {
                        tileArray[i, j] = new TileInfo {
                            CId = 4
                        }
                    };
                }
            }

            MapPixelWidth  = CellSize * Width;
            MapPixelHeight = CellSize * Height;
            cachedMap      = new Bitmap(MapPixelWidth, MapPixelHeight);
            Graphics g = Graphics.FromImage(cachedMap);

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    Rectangle destRect = new Rectangle(CellSize * i, CellSize * j, CellSize, CellSize);

                    var tileImg = TileBook.GetTileImage(tileArray[i, j].CId, CellSize, CellSize);
                    g.DrawImage(tileImg, destRect, 0, 0, CellSize, CellSize, GraphicsUnit.Pixel);
                }
            }

            Pen myPen = new Pen(Brushes.DarkGoldenrod, 6); //描一个金边

            g.DrawRectangle(myPen, 0 + 3, 0 + 3, MapPixelWidth - 6, MapPixelHeight - 6);
            myPen.Dispose();
            g.DrawRectangle(Pens.DarkRed, 0 + 5, 0 + 5, MapPixelWidth - 10, MapPixelHeight - 10);

            g.Dispose();
        }
    private void Start()
    {
        // Get world grid object and get stored size
        grid = GameObject.FindObjectOfType <WorldGrid>();
        Vector3Int mapSize = new Vector3Int(grid.width, grid.height, 1);

        // Set tile map sizes to match world grid
        worldMap.size  = mapSize;
        objectMap.size = mapSize;
        // Placement map will display a single tile preview therefore is of size 1
        placementMap.size = new Vector3Int(1, 1, 1);

        // Initialise static tile maps
        StaticMaps.worldMap     = worldMap;
        StaticMaps.objectMap    = objectMap;
        StaticMaps.placementMap = placementMap;

        // Detect and initialise static tile map renderers
        StaticMaps.DetectMapRenderers();

        // Set placement map transform for moving tile placement preview
        StaticMaps.placementTransform = placementMap.gameObject.transform;

        StaticMaps.worldTileData = new TileData[grid.width, grid.height];
        for (int y = 0; y < grid.height; y++)
        {
            for (int x = 0; x < grid.width; x++)
            {
                StaticMaps.worldTileData[x, y] = new TileData();
            }
        }

        StaticMaps.objectTileData = new TileData[grid.width, grid.height];
        for (int y = 0; y < grid.height; y++)
        {
            for (int x = 0; x < grid.width; x++)
            {
                StaticMaps.objectTileData[x, y] = new TileData();
            }
        }

        Debug.Log("Tile Count: " + TileBook.GetTileCount());
        SetGridToSpace();
        CreateStartRoom();
        DetectSeal.CheckSeal();
    }
    public static void SetTile(MapType mapType, Vector3Int position, Tile tile)
    {
        switch (mapType)
        {
        case MapType.World:
            worldMap.SetTile(position, tile);
            worldTileData[position.x, position.y] = new TileData(TileBook.GetTileDataByName(tile.name));
            break;

        case MapType.Object:
            objectMap.SetTile(position, tile);
            objectTileData[position.x, position.y] = new TileData(TileBook.GetTileDataByName(tile.name));
            break;

        case MapType.Placement:
            placementMap.SetTile(position, tile);
            break;
        }
    }
 // Create debug room
 private void CreateStartRoom()
 {
     for (int y = 4; y < 10; y++)
     {
         for (int x = 4; x < 10; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Wall"));
         }
     }
     for (int y = 5; y < 9; y++)
     {
         for (int x = 5; x < 9; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Floor"));
         }
     }
 }
 // Initialise whole grid to space tiles
 public void SetGridToSpace()
 {
     for (int y = 0; y < grid.height; y++)
     {
         for (int x = 0; x < grid.width; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Space"));
         }
     }
 }
Exemple #9
0
        public void NextAction(float pastRound)
        {
            LeftCount  = 0;
            RightCount = 0;
            List <int> removeMids = new List <int>();

            foreach (var mon in monsters)
            {
                var rival = mon.Rival as Player;
                if (rival.DirectDamage > 0)
                {
                    HitDamage damage = new HitDamage(rival.DirectDamage, rival.DirectDamage, 0, DamageTypes.Magic);
                    mon.HpBar.OnDamage(damage);
                }
                if (!mon.IsAlive)
                {
                    if (!mon.IsGhost)
                    {
                        mon.OnDie();
                    }
                    else
                    {
                        if (mon.OwnerPlayer.SpikeManager.HasSpike("grave") || (mon.Rival as Player).SpikeManager.HasSpike("grave"))
                        {
                            mon.GhostTime += 0.005f;
                        }
                        else
                        {
                            mon.GhostTime += 0.01f;
                        }
                        if (mon.GhostTime >= 1)
                        {
                            removeMids.Add(mon.Id);
                        }
                    }
                }
                else
                {
                    if (!mon.IsLeft)
                    {
                        RightCount = RightCount + 1;
                    }
                    else
                    {
                        LeftCount = LeftCount + 1;
                    }
                }
            }
            BattleManager.Instance.PlayerManager.LeftPlayer.DirectDamage  = 0;//伤害清除
            BattleManager.Instance.PlayerManager.RightPlayer.DirectDamage = 0;

            foreach (int mid in removeMids)
            {
                Remove(mid);
            }


            foreach (var roundMonster in monsters)
            {
                if (roundMonster.IsGhost)
                {
                    continue;
                }

                int tile  = BattleManager.Instance.MemMap.GetMouseCell(roundMonster.Position.X, roundMonster.Position.Y).Tile;
                var match = TileBook.IsTileMatch(tile, roundMonster.Avatar.MonsterConfig.Attr);
                roundMonster.Next(pastRound, match);
            }

            foreach (var lm in toAdd)//添加延时怪
            {
                Add(lm);
            }
            toAdd.Clear();
        }