Example #1
0
    void GenerateTunnels(TILE tile, int numOfTunnels, int holeSize, int tMinSize, int tMaxSize, int minDepth, int maxDepth)
    {
        for (int i = 0; i < numOfTunnels; i++)
        {
            int xpos = 0;
            int ypos = 0;

            int tSize = Random.Range(tMinSize, tMaxSize);
            xpos = Random.Range(0, width);
            ypos = Random.Range(minDepth, maxDepth);

            for (int j = 0; j < tSize; j++)
            {
                for (int x = -holeSize; x <= holeSize; x++)
                {
                    for (int y = -holeSize; y <= holeSize; y++)
                    {
                        xpos += x;
                        ypos += y;

                        if (xpos >= 0 && xpos < width && ypos >= minDepth && ypos < maxDepth)                        // Verify borders
                        {
                            data[xpos, ypos].type = tile;
                        }
                    }
                }

                xpos += Mathf.RoundToInt(GetNoise(i, j, 2f, 1f) * Random.Range(-1, 2));
                ypos += Mathf.RoundToInt(GetNoise(i, j, 2f, 1f) * Random.Range(-1, 2));
            }
        }
    }
Example #2
0
    void GenerateMinerals(TILE tile, int numOfMinerals, int mMinSize = 4, int mMaxSize = 4, int minDepth = 0, int maxDepth = 16)
    {
        for (int i = 0; i < numOfMinerals; i++)
        {
                    {
                int xpos = 0;
                int ypos = 0;

                int mSize = Random.Range(mMinSize, mMaxSize);

                xpos = Random.Range(0, width);
                ypos = Random.Range(minDepth, maxDepth);

                            for (int j = 0; j < mSize; j++)
                {
                                {
                        if (xpos >= 0 && xpos < width && ypos >= minDepth && ypos < maxDepth) // Verify borders
                        {
                            if (data[xpos, ypos].type != tile)                                // Verify data
                            {
                                                data[xpos, ypos].type = tile;
                            }
                        }

                                        xpos += Random.Range(-1, 2);

                        ypos += Random.Range(-1, 2);
                                   
                    }
                }
                       
            }
        }
    }
Example #3
0
    void GenerateMines(TILE tile, int numOfMines = 128, int mMinSize = 4, int mMaxSize = 256, int minDepth = 0, int maxDepth = 16)
    {
        int holeSize = 1;

        for (int i = 0; i < numOfMines; i++)
        {
            int mSize = Random.Range(mMinSize, mMaxSize);
            int xpos  = Random.Range(0, width);
            int ypos  = Random.Range(minDepth, maxDepth);
            for (int j = 0; j < mSize; j++)
            {
                for (int x = -holeSize; x <= holeSize; x++)
                {
                    for (int y = -holeSize; y <= holeSize; y++)
                    {
                        if (!(x == 0 && y == 0))
                        {
                            Vector2 tilePos = new Vector2(xpos + x, ypos + y);
                            if (tilePos.x >= 0 && tilePos.x < width && tilePos.y >= minDepth && tilePos.y < maxDepth)
                            {
                                if (data[(int)tilePos.x, (int)tilePos.y].type != TILE.AIR)
                                {
                                    data[(int)tilePos.x, (int)tilePos.y].type = tile;
                                }
                            }
                        }
                    }
                }

                xpos += Random.Range(-1, 2);
                ypos += Random.Range(-1, 2);
            }
        }
    }
Example #4
0
    private void DrawTile(Vector2 pos, TILE type)
    {
        if (type == TILE.NULL)
        {
            return;
        }

        GameObject tile           = new GameObject($"Tile {pos.ToString()}");
        var        spriteRenderer = tile.AddComponent <SpriteRenderer>();

        tile.transform.position   = new Vector3(pos.x, pos.y, 5);
        tile.transform.localScale = new Vector3(0.9f, 0.9f);

        switch (type)
        {
        case TILE.EMPTY:
        case TILE.ENEMY:
        case TILE.PLAYER:
            spriteRenderer.sprite = tileSprite;
            spriteRenderer.color  = new Color(1, 1, 1);
            tile.transform.parent = mapTiles.transform;
            break;

        case TILE.WALL:
            spriteRenderer.sprite = tileSprite;
            spriteRenderer.color  = new Color(0.1f, 0.1f, 0.1f);
            tile.transform.parent = mapTiles.transform;
            break;

        default:
            break;
        }
    }
Example #5
0
        public Bitmap GetTileResource(TileState state, TileColor color)
        {
            TILE tileAdapt = TILE.NormalBlackTile;

            if (color == TileColor.Black)
            {
                switch (state)
                {
                case TileState.Normal: tileAdapt = TILE.NormalBlackTile; break;

                case TileState.Selected: tileAdapt = TILE.SelectBlackTile; break;

                case TileState.LastMove: tileAdapt = TILE.LastMoveBlackTile; break;

                case TileState.AvalableMove: tileAdapt = TILE.AvalBlackTile; break;
                }
            }
            else
            {
                switch (state)
                {
                case TileState.Normal: tileAdapt = TILE.NormalWhiteTile; break;

                case TileState.Selected: tileAdapt = TILE.SelectWhiteTile; break;

                case TileState.LastMove: tileAdapt = TILE.LastMoveWhiteTile; break;

                case TileState.AvalableMove: tileAdapt = TILE.AvalWhiteTile; break;
                }
            }
            return(this.tileStrategy.GetTile(tileAdapt));
        }
Example #6
0
    void generatePlatform()
    {
        generateStart();
        while (holesGenerated < numHoles)
        {
            TILE type = getRandomEnum <TILE> ();
            if (type == lastType)
            {
                continue;
            }
            switch (type)
            {
            case TILE.Hole:
                generateHole();
                break;

            case TILE.Step:
                generateStep();
                break;

            case TILE.Stair:
                generateStair();
                break;

            default:
                generateFloor();
                break;
            }
            lastType = type;
        }
        generateEnd();
    }
Example #7
0
 public Bitmap GetTile(TILE type)
 {
     if (tiles.ContainsKey(type))
     {
         return(tiles[type]);
     }
     return(null);
 }
Example #8
0
        private void GetCHKAll(BinaryWriter bw)
        {
            LoadString();

            DDDTHG2.Clear();
            MTXM = (ushort[])TILE.Clone();
            //Doodad풀기
            for (int i = 0; i < DD2.Count; i++)
            {
                CDD2 cDD2 = DD2[i];

                DoodadPallet pallete = UseMapEditor.Global.WindowTool.MapViewer.tileSet.DoodadPallets[TILETYPE][cDD2.ID];
                DD2ToMTXM(cDD2);

                CTHG2 cTHG2 = new CTHG2();
                cTHG2.FLAG = pallete.dddFlags;
                cTHG2.X    = cDD2.X;
                cTHG2.Y    = cDD2.Y;
                cTHG2.ID   = pallete.dddOverlayID;

                if (((cTHG2.FLAG & (0b1 << 12)) != 0) | ((cTHG2.FLAG & (0b1 << 13)) != 0))
                {
                    DDDTHG2.Add(cTHG2);
                }
            }



            TriggerSave();



            //에디터로부터 CHK데이터를 가져오는 함수
            for (int i = 0; i < cHKTokens.Count; i++)
            {
                if (cHKTokens[i].tokentype == TOKENTYPE.NULL)
                {
                    GetCHK(bw, cHKTokens[i], TOKENTYPE.NULL);
                }
            }


            foreach (TOKENTYPE cHKTYPE in Enum.GetValues(typeof(TOKENTYPE)))
            {
                if (cHKTYPE != TOKENTYPE.NULL)
                {
                    GetCHK(bw, new CHKToken(), cHKTYPE);
                }
            }
        }
Example #9
0
        // 특정한 타입의 타일 중 무작위로 하나를 고른다.
        // 적과 플레이어, 벽을 생성할 때 사용.
        public Vector2 GetRandomTilePos(TILE type)
        {
            List <Vector2> posArray = new List <Vector2>();

            for (var i = 0; i < row; i++)
            {
                for (var j = 0; j < col; j++)
                {
                    if (map[i, j] == type)
                    {
                        posArray.Add(new Vector2(i, j));
                    }
                }
            }
            int randPos = Random.Range(0, posArray.Count);

            return(posArray[randPos]);
        }
Example #10
0
    public void changeType(TILE type)
    {
        this.type = type;

        if (type == TILE.STONE)
        {
            texCoor     = new int[] { 1, 0 };
            hasCollider = true;
        }
        if (type == TILE.MOSSYSTONE)
        {
            texCoor     = new int[] { 0, 0 };
            hasCollider = true;
        }
        if (type == TILE.BLANK)
        {
            texCoor     = new int[] { 63, 63 };
            hasCollider = false;
        }
        if (type == TILE.STONEBG)
        {
            texCoor     = new int[] { 1, 1 };
            hasCollider = false;
        }
        if (type == TILE.MOSSYBG)
        {
            texCoor     = new int[] { 0, 1 };
            hasCollider = false;
        }
        if (type == TILE.BURNEDMOSSY)
        {
            texCoor     = new int[] { 0, 2 };
            hasCollider = true;
        }
        if (type == TILE.BURNEDSTONE)
        {
            texCoor     = new int[] { 1, 2 };
            hasCollider = true;
        }
    }
Example #11
0
 public ArrayList getPath(int fromX, int fromY, int toX, int toY)
 {
     bool localdebug = true;
     //don't forget to marry this up with the actors at some point :P
     //
     srcTile = getTile(fromX, fromY);
     if (localdebug)
     {
         printTile(srcTile);
     }
     if (srcTile.z == 0)
     {
         //this shouldn't happen after it's automated, only with bad user input...
         Console.WriteLine("Bad source tile, returning with no path...");
         return myPath;
     }
     destTile = getTile(toX, toY);
     if (localdebug)
     {
         printTile(destTile);
     }
     if (destTile.z == 0)
     {
         //this means we have an object in the way (unless the coords are really bad, either way looking around for a good square can't hurt)
         //see if we can find a sqaure adjacent to this one that's open...
         TILE tempDest = getTile(toX, toY + 1);
         if (destTile.z == 0)
         {
             tempDest = getTile(toX, toY - 1);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX + 1, toY);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX - 1, toY);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX + 1, toY + 1);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX + 1, toY - 1);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX - 1, toY + 1);
         }
         if (destTile.z == 0)
         {
             tempDest = getTile(toX - 1, toY - 1);
         }
         if (destTile.z == 0)
         {
             Console.WriteLine("Bad destination tile, returning with no path...");
             return myPath;
         }
     }
     for (int gridCount = 0; gridCount < myMapHeader.tile_map_x_len * myMapHeader.tile_map_y_len * 6 * 6; gridCount++)
     {
         TILE myTile = TILE_MAP[gridCount];
         myTile.state = myStates.STATE_NONE;
         myTile.parentX = -1;
         myTile.parentY = -1;
         TILE_MAP[gridCount] = myTile;
     }
     pathCount = 0;
     addToOpenList(new TILE(), srcTile);
     bool pathFound = false;
     while (pathCount < MAXATTEMPTS)
     {
         TILE myTile = getNextOpenTile();
         if (myTile.x == destTile.x && myTile.y == destTile.y)
         {
             pathFound = true;
             //Console.WriteLine("YAY, we found it!");
             //Console.ReadLine();
             break;
         }
         myPathTiles[pathCount] = myTile;
         addToOpenList(myTile, getTile(myTile.x, myTile.y + 1));
         addToOpenList(myTile, getTile(myTile.x + 1, myTile.y + 1));
         addToOpenList(myTile, getTile(myTile.x + 1, myTile.y));
         addToOpenList(myTile, getTile(myTile.x + 1, myTile.y - 1));
         addToOpenList(myTile, getTile(myTile.x, myTile.y - 1));
         addToOpenList(myTile, getTile(myTile.x - 1, myTile.y - 1));
         addToOpenList(myTile, getTile(myTile.x - 1, myTile.y));
         addToOpenList(myTile, getTile(myTile.x - 1, myTile.y + 1));
         pathCount++;
     }
     if (!pathFound  || pathCount == 0)
     {
         myPath = new ArrayList();
         Console.WriteLine("no path returned! :P");
     }
     else
     {
         Console.WriteLine("path returned! :P" + "|" + pathCount);
         finishPath();
     }
     Console.WriteLine("finshed path count:" + myPath.Count);
     return myPath;
 }
Example #12
0
            private void readHeightMap()
            {
                bool localdebug = false;
                //                int tileCount = 0;
                int i;
                heightMap = myReader.ReadChars(myMapHeader.tile_map_x_len * myMapHeader.tile_map_y_len * 6 * 6);
                if (localdebug)
                {
                    Console.WriteLine("height map read..." + heightMap.Length);
                    Console.ReadLine();
                }

                //insert the heights into mymap array
                for (int x = 0; x < myMapHeader.tile_map_x_len * 6; x++)
                {
                    for (int y = 0; y < myMapHeader.tile_map_y_len * 6; y++)
                    {
                        i = y * myMapHeader.tile_map_x_len * 6 + x;
                        TILE myTile = new TILE();
                        myTile.x = x;
                        myTile.y = y;
                        myTile.z = heightMap[i];
                        myTile.state = myStates.STATE_NONE;
                        myTile.parentX = -1;
                        myTile.parentY = -1;
                        TILE_MAP[i] = myTile;
                        TILE_MAPCount++;
                    }
                }

                if (localdebug)
                {
                    Console.WriteLine(TILE_MAPCount);
                    Console.ReadLine();
                }
            }
Example #13
0
            private TILE getNextOpenTile()
            {
                bool localdebug = false;
                if (localdebug)
                {
                    //                    Console.WriteLine("before");
                    //                    printOpenTileList();
                }
                //this will probably look ugly at first, the client code is very hard to understand here
                //so, going to copy it's logic as closely as possible, ignoring the fact that I haven't a clue what it's doing, lol
                TILE retTile = new TILE();
                TILE tempTile = new TILE();
                int i = 0, j = 0;
                bool done = false;
                if (OPEN_LISTCount == 0)
                {
                    return new TILE();
                }
                retTile = OPEN_LIST[1];

                //swapping around tiles for some reason... heh
                retTile.state = myStates.PF_STATE_CLOSED;
                TILE myTempTile = TILE_MAP[retTile.y * myMapHeader.tile_map_x_len * 6 + retTile.x];
                myTempTile.state = myStates.PF_STATE_CLOSED;
                TILE_MAP[retTile.y * myMapHeader.tile_map_x_len * 6 + retTile.x] = myTempTile;
                //this isn't working, let's see what we can replace it with
                OPEN_LIST[1] = OPEN_LIST[OPEN_LISTCount--];

                j = 1;
                while (!done)
                {
                    i = j;
                    if (2 * i + 1 <= OPEN_LISTCount)
                    {
                        if (OPEN_LIST[i].f >= OPEN_LIST[2 * i].f)
                        {
                            j = 2 * i;
                        }
                        if (OPEN_LIST[j].f >= OPEN_LIST[2 * i + 1].f)
                        {
                            j = 2 * i + 1;
                        }
                    }
                    else if (2 * i <= OPEN_LISTCount)
                    {
                        if (OPEN_LIST[i].f >= OPEN_LIST[2 * i].f)
                        {
                            j = 2 * i;
                        }
                    }
                    if (i != j)
                    {
                        tempTile = OPEN_LIST[i];
                        OPEN_LIST[i] = OPEN_LIST[j];
                        OPEN_LIST[j] = tempTile;
                    }
                    else
                    {
                        done = true;
                    }
                }
                if (localdebug)
                {
                    //                    Console.WriteLine("after");
                    //                    printOpenTileList();
                    Console.Write("Choosing tile: ");
                    printTile(retTile);
                    Console.ReadLine();
                }
                return retTile;
            }
Example #14
0
 private int distance(TILE thisGridMark, TILE thatGridMark)
 {
     //this is the heuristic function used to calculate distance
     int theDistance = 0;
     //PF_HEUR(a, b) ((PF_DIFF(a->x, b->x) + PF_DIFF(a->y, b->y)) * 10) //stolen from client code (same in redknight afaik...)
     theDistance = (difference(thisGridMark.x, thatGridMark.x) + difference(thisGridMark.y, thatGridMark.y)) * 10;
     return theDistance;
 }
Example #15
0
 private bool areDiagonal(TILE thisGridMark, TILE thatGridMark)
 {
     bool theyAreDiagonal = true;
     if ((thatGridMark.x == thisGridMark.x) || (thatGridMark.y == thisGridMark.y))
     {
         theyAreDiagonal = false;
     }
     return theyAreDiagonal;
 }
Example #16
0
            private void addToOpenList(TILE current, TILE neighbor)
            {
                TILE nullTile = new TILE();
                TILE tempTile = new TILE();
                bool localdebug = false;
                if (localdebug)
                {
                    printOpenTileList();
                }
                if (neighbor.Equals(nullTile) || neighbor.z == 0 || (!current.Equals(nullTile) && difference(current.z, neighbor.z) > 2))
                {
                    return;
                }

                if (!current.Equals(nullTile))
                {

                    int myG = 0, myF = 0, myH = 0;
                    bool diagonal = (neighbor.x != current.x && neighbor.y != current.y);
                    myG = current.g + (diagonal ? 14 : 10);
                    myH = distance(neighbor, destTile);
                    myF = myG + myH;
                    if (neighbor.state != myStates.STATE_NONE && myF >= neighbor.f)
                    {
                        return;
                    }
                    neighbor.f = myF;
                    neighbor.g = myG;
                    neighbor.parentX = current.x;
                    neighbor.parentY = current.y;
                }
                else
                {
                    neighbor.f = distance(srcTile, destTile);
                    neighbor.g = 0;
                    //can't just assign NULL here like the client is, and can't have pointers, so using -1,-1 to represent the NULL TILE
                    neighbor.parentX = -1;
                    neighbor.parentY = -1;
                }

                if (neighbor.state != myStates.PF_STATE_OPEN)
                {
                    //adding state open here...
                    neighbor.open_pos = ++OPEN_LISTCount;
                    //neighbor.open_pos = OPEN_LIST.Count + 1;
                    OPEN_LIST[neighbor.open_pos] = neighbor;
                }
                if (localdebug)
                {
                    printOpenTileList();
                }
                //sort them by their F value...
                while (neighbor.open_pos > 1)
                {
                    //need to be updating the open_pos it appears...
                    if (OPEN_LIST[neighbor.open_pos].f <= OPEN_LIST[neighbor.open_pos / 2].f)
                    {
                        tempTile = OPEN_LIST[neighbor.open_pos / 2];
                        OPEN_LIST[neighbor.open_pos / 2] = OPEN_LIST[neighbor.open_pos];
                        OPEN_LIST[neighbor.open_pos] = tempTile;
                        neighbor.open_pos /= 2;
                    }
                    else
                    {
                        break;
                    }
                }
                TILE myTempTIle = TILE_MAP[neighbor.y * myMapHeader.tile_map_x_len * 6 + neighbor.x];
                myTempTIle.state = myStates.PF_STATE_OPEN;
                TILE_MAP[neighbor.y * myMapHeader.tile_map_x_len * 6 + neighbor.x] = myTempTIle;
            }
Example #17
0
            public Tile(TILE type, float x, float y, WALL wall)
            {
                this.type = type;
                this.wall = wall;

                switch (type)
                {
                    case TILE.floor:
                        anim = Animation.createSingleFrameAnimation("tiles/floor", new Vector2(x, y), 0.1f);
                        break;
                    case TILE.wall:
                        switch (wall)
                        {
                            case WALL.bounce: anim = Animation.createSingleFrameAnimation("tiles/stickwall", new Vector2(x, y), 0.1f); break;
                            case WALL.destr: anim = Animation.createSingleFrameAnimation("tiles/breakwall", new Vector2(x, y), 0.1f); break;
                            case WALL.pass: anim = Animation.createSingleFrameAnimation("tiles/passwall", new Vector2(x, y), 1.0f); break;
                            default: anim = Animation.createSingleFrameAnimation("tiles/wall", new Vector2(x, y), 0.1f); break;
                        }
                        break;
                }
            }
Example #18
0
 public TileData()
 {
     type      = TILE.AIR;
     amount    = 900;
     endurance = 0;
 }
Example #19
0
            public Tile(TILE type, float x, float y)
            {
                this.type = type;

                switch (type)
                {
                    case TILE.floor:
                        anim = Animation.createSingleFrameAnimation("tiles/floor", new Vector2(x, y), 0.1f);
                        break;
                    case TILE.wall:
                        anim = Animation.createSingleFrameAnimation("tiles/wall", new Vector2(x, y), 0.1f);
                        break;
                }
            }
Example #20
0
 //pathing methods
 public TILE getTile(int x, int y)
 {
     TILE myTile = new TILE();
     if (x >= myMapHeader.tile_map_x_len * 6 || y >= myMapHeader.tile_map_y_len * 6 || x < 0 || y < 0)
     {
         //should probably tell the user about this...
     }
     else
     {
         myTile = (TILE)TILE_MAP[y * myMapHeader.tile_map_x_len * 6 + x];
     }
     return myTile;
 }
Example #21
0
    public void Load(LitJson.JSONNode json)
    {
        int child     = 0;
        int tileIndex = 0;

        foreach (LitJson.JSONNode node in json.Childs)
        {
            if (child == 0)
            {
                width  = JsonReader.Int(node, "width");
                height = JsonReader.Int(node, "height");

                tiles          = new TILE[width * height];
                towerPositions = new List <COORD> ();
            }
            else
            {
                int    y    = child - 1;
                string line = node["line"];

                for (int x = 0; x < width; ++x)
                {
                    string c = line.Substring(x, 1);
                    TILE   t = ParseTile(c);
                    tiles[tileIndex++] = t;

                    if (t == TILE.START)
                    {
                        Assert.assert(startPosition == null);
                        startPosition = new COORD(x, y);
                    }

                    if (t == TILE.A)
                    {
                        Assert.assert(extraPositionA == null);
                        extraPositionA = new COORD(x, y);
                    }
                    if (t == TILE.B)
                    {
                        Assert.assert(extraPositionB == null);
                        extraPositionB = new COORD(x, y);
                    }
                    if (t == TILE.C)
                    {
                        Assert.assert(extraPositionC == null);
                        extraPositionC = new COORD(x, y);
                    }
                    if (t == TILE.D)
                    {
                        Assert.assert(extraPositionD == null);
                        extraPositionD = new COORD(x, y);
                    }

                    if (t == TILE.TOWER)
                    {
                        towerPositions.Add(new COORD(x, y));
                    }
                }
            }

            ++child;
        }

        ValidatePositions();
    }
Example #22
0
 public TileData(TileData tileData)
 {
     type      = tileData.type;
     amount    = tileData.amount;
     endurance = tileData.endurance;
 }
Example #23
0
 public void SetValues(TILE type, int amount, int endurance)
 {
     this.type      = type;
     this.amount    = amount;
     this.endurance = endurance;
 }
Example #24
0
 public void printTile(TILE myTile)
 {
     Console.WriteLine(myTile.x + "," + myTile.y + "," + myTile.f + "," + myTile.g + "," + myTile.parentX + "," + myTile.parentY);
 }
Example #25
0
 public Bitmap GetTile(TILE type)
 {
     return(commonTile.GetTile(type));
 }