Beispiel #1
0
        private WallDir AmountOfWalls(float x, float y)
        {
            WallDir walls = new WallDir();

            walls.amount = 0; walls.North = false;
            walls.East   = false; walls.South = false;
            walls.West   = false;
            if (board.GetTile(x, y).isWallRight())
            {
                walls.amount++;
                walls.East = true;
            }
            if (board.GetTile(x - 1, y).isWallRight())
            {
                walls.amount++;
                walls.West = true;
            }
            if (board.GetTile(x, y - 1).isWallTop())
            {
                walls.amount++;
                walls.South = true;
            }
            if (board.GetTile(x, y).isWallTop())
            {
                walls.amount++;
                walls.North = true;
            }
            return(walls);
        }
 void RemoveWallsAlongPath(Maze maze, List <Cell> path, List <Cell> visitedCells, List <Cell> remainingCells)
 {
     path.Reverse();
     for (int i = 0; i < path.Count - 1; i++)
     {
         Cell A = path[i];
         Cell B = path[i + 1];
         if (!visitedCells.Contains(B))
         {
             int     dx  = B.x - A.x;
             int     dy  = B.y - A.y;
             WallDir dir = WallDir.Horizontal;
             if (dx != 0)
             {
                 dir = WallDir.Vertical;
             }
             if (dx < 0 || dy < 0)
             {
                 maze.walls.Remove(new Wall(A, dir));
             }
             else
             {
                 maze.walls.Remove(new Wall(B, dir));
             }
             remainingCells.Remove(B);
             visitedCells.Add(B);
         }
     }
 }
Beispiel #3
0
    private void AddQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, WallDir dir)
    {
        int vertexIndex = verties.Count;

        verties.Add(v1);
        verties.Add(v2);
        verties.Add(v3);
        verties.Add(v4);
        triangles.Add(vertexIndex); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 2);
        triangles.Add(vertexIndex); triangles.Add(vertexIndex + 2); triangles.Add(vertexIndex + 3);
        AddQuadUV(dir);
    }
    public void SetWallProperties(Vector3 centerPos, float width, float height, WallDir dir)
    {
        transform.position         = centerPos;
        ScaledWallPiece.localScale = new Vector3(width, height, 1);
        Direction = dir;
        Width     = width;
        Height    = height;

        if (OnWallPropertiesChanged != null)
        {
            OnWallPropertiesChanged.Invoke();
        }
    }
Beispiel #5
0
 /// <summary>
 /// Add a new wall
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="direction"></param>
 /// <param name="cutOut"></param>
 public void Add(string filename, WallDir direction, Rectangle cutOut, Backend.Coords offset = null, Backend.Coords crop = null, Backend.WallType subtype = Backend.WallType.Normal)
 {
     if (offset == null) offset = Backend.Coords.Zero;
     if (crop == null) crop = Backend.Coords.Zero;
     if ((int)direction + (int)subtype * 100 < _textures.Count)
     {
         // _textures[(int)direction].width = cutOut.Width;
         // _textures[(int)direction].height = cutOut.Height;
         _textures[(int)direction + (int)subtype * 100].AddAnimation(filename, new Backend.Coords(cutOut.Left, cutOut.Top), 1, 1, null, null, false);
         _textures[(int)direction + (int)subtype * 100].cropX = crop.x;
         _textures[(int)direction + (int)subtype * 100].cropY = crop.y;
         _textures[(int)direction + (int)subtype * 100].offsetX = offset.x;
         _textures[(int)direction + (int)subtype * 100].offsetY = offset.y;
     }
 }
Beispiel #6
0
 private void ShowArrows(bool show)
 {
     if (!onPause)
     {
         WallDir walls = AmountOfWalls(transform.localPosition.x, transform.localPosition.y);
         if (!show)
         {
             NArrowSprite.enabled = false;
             DArrowSprite.enabled = false;
             RArrowSprite.enabled = false;
             LArrowSprite.enabled = false;
         }
         else
         {
             NArrowSprite.enabled = !walls.North;
             DArrowSprite.enabled = !walls.South;
             RArrowSprite.enabled = !walls.East;
             LArrowSprite.enabled = !walls.West;
         }
     }
 }
Beispiel #7
0
    private void AddQuadUV(WallDir dir)
    {
        float   delta     = 1f / 3f;
        Vector2 basePoint = Vector2.zero;
        float   RandX     = Mathf.Floor(Random.Range(0, 4)) * 0.25f;

        switch (dir)
        {
        case WallDir.Forward:
            basePoint = new Vector2(RandX, delta);
            break;

        case WallDir.Up:
            basePoint = new Vector2(RandX, delta * 2f);
            break;

        case WallDir.Down:
            basePoint = new Vector2(RandX, 0f);
            break;

        case WallDir.Right:
            basePoint = new Vector2(RandX, delta * 2f);
            break;

        case WallDir.Left:
            basePoint = new Vector2(RandX, delta * 2f);
            break;

        default:
            break;
        }
        UVs.Add(basePoint);
        UVs.Add(basePoint + new Vector2(0, delta));
        UVs.Add(basePoint + new Vector2(0.25f, delta));
        UVs.Add(basePoint + new Vector2(0.25f, 0));
    }
Beispiel #8
0
        void Update()
        {
            if (!onPause)
            {
                if (board.GetTile(transform.localPosition.x, transform.localPosition.y).isGoal() && !goal)
                {
                    levelManager.LevelComplete();
                    goal         = true;
                    endPoint.end = board.GetTile(transform.localPosition.x, transform.localPosition.y).transform.localPosition;
                }
                else if (!board.GetTile(transform.localPosition.x, transform.localPosition.y).isGoal())
                {
                    goal = false;
                }

                actualTime = Time.time;
                if (moving)
                {
                    //transform.Translate(time * dirX, time * dirY, 0, Space.Self);
                    //transform.localPosition += new Vector3(time * dirX, time * dirY);
                    //Debug.Log(count);
                    // count -= time;
                    if (!showArrow)
                    {
                        ShowArrows(showArrow);
                        showArrow = true;
                    }


                    // Distance moved equals elapsed time times speed..
                    float distCovered = (actualTime - startTime) * speed;

                    // Fraction of journey completed equals current distance divided by total distance.
                    float fractionOfJourney = distCovered / journeyLength;



                    // Set our position as a fraction of the distance between the markers.
                    transform.localPosition = Vector3.Lerp(startMarker, endPoint.end, fractionOfJourney);
                    if (transform.localPosition == endPoint.end)
                    {
                        WallDir walls = AmountOfWalls(transform.localPosition.x, transform.localPosition.y);
                        if (walls.amount == 2 && !board.GetTile(transform.localPosition.x, transform.localPosition.y).isIce() && !goal)
                        {
                            int dirX = 0, dirY = 0;
                            if (endPoint.dirX != 0)
                            {
                                if (walls.North)
                                {
                                    dirY = -1;
                                }
                                else
                                {
                                    dirY = 1;
                                }
                            }
                            else
                            {
                                if (walls.East)
                                {
                                    dirX = -1;
                                }
                                else
                                {
                                    dirX = 1;
                                }
                            }
                            startTime     = Time.time;
                            startMarker   = transform.localPosition;
                            endPoint      = searchLinePath(dirX, dirY);
                            journeyLength = endPoint.lenght;
                        }
                        else
                        {
                            moving        = false;
                            endPoint.dirX = 0;
                            endPoint.dirY = 0;
                        }
                    }
                }
                else if (showArrow)
                {
                    ShowArrows(showArrow);
                    showArrow = false;
                }
            }
        }
Beispiel #9
0
 public GameObject GetWall(WallDir direction)
 {
     return(_walls[direction]);
 }
Beispiel #10
0
 public bool ContainsWall(WallDir direction)
 {
     return(_walls.ContainsKey(direction));
 }
Beispiel #11
0
 public void RemoveWall(WallDir direction)
 {
     _walls.Remove(direction);
 }
Beispiel #12
0
 public void AddWall(WallDir direction, GameObject wall)
 {
     _walls.Add(direction, wall);
 }
Beispiel #13
0
        /// <summary>
        /// Display a wall
        /// </summary>
        /// <param name="dir">Squares the wall connects to</param>
        /// <param name="x">Horizontal position</param>
        /// <param name="y">Vertical position</param>
        /// <param name="transparent"></param>
        private void _drawWall(WallDir dir, Rectangle target, bool transparent, bool active, Backend.WallType special = Backend.WallType.Normal)
        {
            if ((special != Backend.WallType.Normal) && (dir != WallDir.LeftRight) && (dir != WallDir.UpDown) && (dir != WallDir.UpLeftDiag)) special = Backend.WallType.Normal;

            switch (dir)
            {

                case WallDir.DiagUpDownClose: // Done
                    _drawWall(WallDir.DiagUpClose, target, transparent, active);
                    _drawWall(WallDir.DiagDownClose, target, transparent, active);
                    break;

                case WallDir.DiagUpDownClose2: // Done
                    _drawWall(WallDir.DiagUpClose2, target, transparent, active);
                    _drawWall(WallDir.DiagDownClose2, target, transparent, active);
                    break;

                case WallDir.DiagLeftRightClose: // Done
                    _drawWall(WallDir.DiagRightClose, target, transparent, active);
                    _drawWall(WallDir.DiagLeftClose, target, transparent, active);
                    break;

                case WallDir.DiagLeftRightClose2: // Done
                    _drawWall(WallDir.DiagRightClose2, target, transparent, active);
                    _drawWall(WallDir.DiagLeftClose2, target, transparent, active);
                    break;

                case WallDir.None:
                    break;

                default:
                    Color color = active ? Color.Red : Color.White;
                    if ((dir == WallDir.UpLeftDiag) && (special != Backend.WallType.Normal))
                    {

                        // 32 PIXEL LINKS
                        // 32 PIXEL RECHTS
                        _spriteBatch.Draw(_walls[(int)dir].animationTexture, new Rectangle(
                            target.Left + _walls[(int)dir].offsetX,
                            target.Top + _walls[(int)dir].offsetY,
                            target.Width - _walls[(int)dir].offsetX - _walls[(int)dir].cropX - 96,
                            target.Height - _walls[(int)dir].offsetY - _walls[(int)dir].cropY),
                            new Rectangle(_walls[(int)dir].animationRect.Left, _walls[(int)dir].animationRect.Top, _walls[(int)dir].animationRect.Width - 96, _walls[(int)dir].animationRect.Height), transparent ? new Color(color, (float)0.5) : color);
                        _spriteBatch.Draw(_walls[(int)dir].animationTexture, new Rectangle(
            target.Left + _walls[(int)dir].offsetX + 96,
            target.Top + _walls[(int)dir].offsetY,
            target.Width - _walls[(int)dir].offsetX - _walls[(int)dir].cropX - 96,
            target.Height - _walls[(int)dir].offsetY - _walls[(int)dir].cropY),
            new Rectangle(_walls[(int)dir].animationRect.Left, _walls[(int)dir].animationRect.Top, _walls[(int)dir].animationRect.Width - 96, _walls[(int)dir].animationRect.Height), transparent ? new Color(color, (float)0.5) : color);

                    }

                    _spriteBatch.Draw(_walls[(int)dir + (int)special * 100].animationTexture, new Rectangle(
                        target.Left + _walls[(int)dir + (int)special * 100].offsetX,
                        target.Top + _walls[(int)dir + (int)special * 100].offsetY,
                        target.Width - _walls[(int)dir + (int)special * 100].offsetX - _walls[(int)dir + (int)special * 100].cropX,
                        target.Height - _walls[(int)dir + (int)special * 100].offsetY - _walls[(int)dir + (int)special * 100].cropY),
                        _walls[(int)dir + (int)special * 100].animationRect, transparent ? new Color(color, (float)0.5) : color);
                    break;

            }
        }
 public Wall(Cell cell, WallDir dir)
 {
     this.cell = cell;
     this.dir  = dir;
 }