Esempio n. 1
0
    //------------------------------------------------------------------------------------------------------------------------
    //														spawnBackgroundTiles()
    //------------------------------------------------------------------------------------------------------------------------
    public void SpawnOverlapTiles(Map levelData)
    {
        // Check if there are layers
        if (levelData.Layers == null || levelData.Layers.Length == 0)
        {
            return;
        }

        // Setting the mainlayer to the first layer
        Layer mainLayer = levelData.Layers[2];

        short[,] tileNumbers = mainLayer.GetTileArray();

        for (int row = 0; row < mainLayer.Height; row++)
        {
            for (int col = 0; col < mainLayer.Width; col++)
            {
                int tileNumber = tileNumbers[col, row];
                if (tileNumber > 0)
                {
                    bgTile = new BackgroundTile(BgSpriteSheet, BgCols, BgRows);
                    bgTile.SetFrame(tileNumber - 4);
                    bgTile.x = col * bgTile.width + bgTile.width / 2;
                    bgTile.y = row * bgTile.height + bgTile.height / 2;
                    AddChild(bgTile);
                }
            }
        }

        AddActivityBoxes();
    }
Esempio n. 2
0
 public ActiveTile(BackgroundTile Parent, int x, int y, GameObject Sprite)
 {
     X      = x;
     Y      = y;
     parent = Parent;
     sprite = Sprite;
 }
        public void UpdateTile(Theme theme, byte tileId, byte properties)
        {
            Tile2bpp tileModel = theme.Background.Tileset[tileId];

            this.tile.Dispose();
            this.tile = new BackgroundTile(tileModel.Graphics, tileModel.Palettes, properties, this.Front);

            int width  = this.Width;
            int height = this.Height;

            if (this.BorderStyle == BorderStyle.Fixed3D)
            {
                width  -= SystemInformation.Border3DSize.Width * 2;
                height -= SystemInformation.Border3DSize.Height * 2;
            }

            Bitmap zoomedBitmap = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            using (Graphics g = Graphics.FromImage(zoomedBitmap))
            {
                g.PixelOffsetMode   = PixelOffsetMode.Half;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;
                g.Clear(theme.BackColor);
                g.DrawImage(this.tile.Bitmap, 0, 0, width, height);
            }

            this.image.Dispose();
            this.image = zoomedBitmap;

            this.Refresh();
        }
Esempio n. 4
0
    private void turnHexagons(bool rightOrLeft, int dotIndex)
    {
        HexCell tempHexagon;

        StartCoroutine(WaitUntilCurrentHexSetParent(dotIndex));
        if (right == true)
        {
            tempTile    = grid.allTiles[_hex3X, _hex3Y];
            tempHexagon = allHexagons[_hex3X, _hex3Y];

            allHexagons[_hex3X, _hex3Y]   = allHexagons[_hex2X, _hex2Y];
            grid.allTiles[_hex3X, _hex3Y] = grid.allTiles[_hex2X, _hex2Y];

            grid.allTiles[_hex3X, _hex3Y].coordinateX = _hex3X;
            grid.allTiles[_hex3X, _hex3Y].coordinateY = _hex3Y;

            allHexagons[_hex2X, _hex2Y]   = allHexagons[_hex1X, _hex1Y];
            grid.allTiles[_hex2X, _hex2Y] = grid.allTiles[_hex1X, _hex1Y];

            grid.allTiles[_hex2X, _hex2Y].coordinateX = _hex2X;
            grid.allTiles[_hex2X, _hex2Y].coordinateY = _hex2Y;

            allHexagons[_hex1X, _hex1Y]   = tempHexagon;
            grid.allTiles[_hex1X, _hex1Y] = tempTile;

            grid.allTiles[_hex1X, _hex1Y].coordinateX = _hex1X;
            grid.allTiles[_hex1X, _hex1Y].coordinateY = _hex1Y;
            //Debug.Log("Coordinates are Hex "+ _hex1X + "," + _hex1Y + " ->>>>>>>>>>>>>>>>>  x = " +grid.allTiles[_hex1X, _hex1Y].coordinateX + "   y = " + grid.allTiles[_hex1X, _hex1Y].coordinateY);
            //Debug.Log("Coordinates are Hex "+ _hex2X + "," + _hex2Y + " ->>>>>>>>>>>>>>>>>  x = " +grid.allTiles[_hex2X, _hex2Y].coordinateX + "   y = " + grid.allTiles[_hex2X, _hex2Y].coordinateY);
            //Debug.Log("Coordinates are Hex "+ _hex3X + "," + _hex3Y + " ->>>>>>>>>>>>>>>>>  x = " +grid.allTiles[_hex3X, _hex3Y].coordinateX + "   y = " + grid.allTiles[_hex3X, _hex3Y].coordinateY);


            StartCoroutine(rotateHexs(right, dotIndex));

            rotateCounter++;
        }
        else
        {
            tempTile = grid.allTiles[_hex2X, _hex2Y];
            grid.allTiles[_hex2X, _hex2Y]             = grid.allTiles[_hex3X, _hex3Y];
            grid.allTiles[_hex2X, _hex2Y].coordinateX = _hex2X;
            grid.allTiles[_hex2X, _hex2Y].coordinateY = _hex2Y;
            grid.allTiles[_hex3X, _hex3Y]             = grid.allTiles[_hex1X, _hex1Y];
            grid.allTiles[_hex3X, _hex3Y].coordinateX = _hex3X;
            grid.allTiles[_hex3X, _hex3Y].coordinateY = _hex3Y;
            grid.allTiles[_hex1X, _hex1Y]             = tempTile;
            grid.allTiles[_hex1X, _hex1Y].coordinateX = _hex1X;
            grid.allTiles[_hex1X, _hex1Y].coordinateY = _hex1Y;

            tempHexagon = allHexagons[_hex2X, _hex2Y];
            allHexagons[_hex2X, _hex2Y] = allHexagons[_hex3X, _hex3Y];
            allHexagons[_hex3X, _hex3Y] = allHexagons[_hex1X, _hex1Y];
            allHexagons[_hex1X, _hex1Y] = tempHexagon;


            StartCoroutine(rotateHexs(right, dotIndex));

            rotateCounter++;
        }
    }
Esempio n. 5
0
        /// <summary>
        /// Checks if the move meets the following requirements:
        /// 1. New placement is within the bounds of the game grid
        /// 2. New placement is not overlapping with another set piece
        /// </summary>
        /// <param name="piece">The piece we're moving.</param>
        /// <param name="newPlacement">The requested placement of the next piece.</param>
        /// <param name="gameGrid">The game grid.</param>
        /// <returns>True/False as to whether the given move is valid</returns>
        public bool CheckIfMoveIsValid(Placement newPlacement, TableLayoutPanel gameGrid)
        {
            var defaultBackgroundColour = new BackgroundTile().Default().BackColor;

            // Check we're within our bounds
            var moveIsValid = newPlacement.ActiveCells.None(p => p.X <0 || p.X >= MaxX || p.Y> MaxY);

            if (!moveIsValid)
            {
                return(false);              // We're out out of bounds, no need to check the rest
            }
            // We're in bounds, let's check if we're colliding with another piece
            foreach (var focusedPanel in newPlacement.ActiveCells.Select(newPoint => GetGridPoint(newPoint.X, newPoint.Y, gameGrid)))
            {
                // Check if the focused panel is the default background colour
                // if it's not then we know we've hit another piece
                moveIsValid = focusedPanel.BackColor == defaultBackgroundColour;

                if (!moveIsValid)
                {
                    break; // Move isn't valid, no need to continue
                }
            }

            return(moveIsValid);
        }
Esempio n. 6
0
 private void UpdateSpritePositions()
 {
     foreach (GameObject go in pool.available)
     {
         BackgroundTile tile = go.GetComponent <BackgroundTile>();
         go.transform.localPosition = new Vector3(tile.x * tile.size.x, tile.y * tile.size.y, 1);
     }
 }
        public TileBase CreateTileView()
        {
            var view = new BackgroundTile()
            {
                DataContext = this
            };

            return(view);
        }
Esempio n. 8
0
        public void loadDefaultMapTest()
        {
            IMapTile[][] expected = new IMapTile[5][];
            expected[0]    = new IMapTile[6];
            expected[1]    = new IMapTile[6];
            expected[2]    = new IMapTile[6];
            expected[3]    = new IMapTile[6];
            expected[4]    = new IMapTile[6];
            expected[0][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][0] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][1] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][2] = new RoadTile(RoadTile.RoadType.TopRight);
            expected[1][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][2] = new RoadTile(RoadTile.RoadType.Vertical);
            expected[2][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][2] = new RoadTile(RoadTile.RoadType.BottomLeft);
            expected[3][3] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][4] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][5] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[4][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);

            IMapTile[][] actual = MapLoader.loadDefaultMap();

            Assert.IsTrue(actual.Length > 0 && actual[0].Length > 0, "Map has not a valid dimension");
            Assert.AreEqual(expected.Length, actual.Length, "Constructed map has a different height");
            Assert.AreEqual(expected[0].Length, actual[0].Length, "Constructed map has a different width");

            for (int i = actual.Length; i-- > 0;)
            {
                for (int j = actual[0].Length; j-- > 0;)
                {
                    int hashA = expected[i][j].GetHashCode();
                    int hashB = actual[i][j].GetHashCode();
                    Assert.AreEqual(expected[i][j], actual[i][j], "Constructed map got a different tile at (" + i + "," + j + ")");
                }
            }
        }
Esempio n. 9
0
        public void loadDefaultMapTest()
        {
            IMapTile[][] expected = new IMapTile[5][];
            expected[0] = new IMapTile[6];
            expected[1] = new IMapTile[6];
            expected[2] = new IMapTile[6];
            expected[3] = new IMapTile[6];
            expected[4] = new IMapTile[6];
            expected[0][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][0] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][1] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][2] = new RoadTile(RoadTile.RoadType.TopRight);
            expected[1][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][2] = new RoadTile(RoadTile.RoadType.Vertical);
            expected[2][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][2] = new RoadTile(RoadTile.RoadType.BottomLeft);
            expected[3][3] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][4] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][5] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[4][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);

            IMapTile[][] actual = MapLoader.loadDefaultMap();

            Assert.IsTrue(actual.Length > 0 && actual[0].Length > 0, "Map has not a valid dimension");
            Assert.AreEqual(expected.Length, actual.Length, "Constructed map has a different height");
            Assert.AreEqual(expected[0].Length, actual[0].Length, "Constructed map has a different width");

            for (int i = actual.Length; i-- > 0; )
            {
                for (int j = actual[0].Length; j-- > 0; )
                {
                    int hashA = expected[i][j].GetHashCode();
                    int hashB = actual[i][j].GetHashCode();
                    Assert.AreEqual(expected[i][j], actual[i][j], "Constructed map got a different tile at (" + i + "," + j + ")");
                }
            }
        }
        public BackgroundTilePanel()
        {
            // Initializing fields to avoid null checks before disposing

            if (Context.Game != null) // Avoid designer issues
            {
                Tile2bpp tile = Context.Game.Themes[0].Background.Tileset[0];
                this.tile = new BackgroundTile(tile.Graphics, null);
            }

            this.image = new Bitmap(1, 1, PixelFormat.Format32bppPArgb);
        }
Esempio n. 11
0
 private static void convertBackgroundTiles(Map map, SceneGraph sceneGraph)
 {
     foreach (BackgroundTileMap backgroundMapTile in map.getBackgroundTileList())
     {
         BackgroundTile backgroundTile = new BackgroundTile();
         backgroundTile.setObjectPosition(backgroundMapTile.getObjectPosition());
         backgroundTile.setScale(backgroundMapTile.getScale());
         Texture2D texture2D = StringToGraphicsConverter.convertBackgroundTile(backgroundMapTile.getTileType(), sceneGraph);
         backgroundTile.setTexture2D(texture2D);
         sceneGraph.addBackgroundTile(backgroundTile);
     }
 }
Esempio n. 12
0
 //Generates grid.
 void CreateGrid()
 {
     for (int xx = 0; xx < xSize; xx++)
     {
         for (int yy = 0; yy < ySize; yy++)
         {
             if (grid [xx, yy])
             {
                 Vector2        myPos = PosToVector2(xx, yy);
                 BackgroundTile bg    = Instantiate(GameManager.Instance.bg);
                 Color          col   = bg.render.color;
                 if (xx % 2 == 0)
                 {
                     if (yy % 2 == 0)
                     {
                         col.a = Mathf.InverseLerp(0, 255, GameManager.Instance.bg1);
                     }
                     else
                     {
                         col.a = Mathf.InverseLerp(0, 255, GameManager.Instance.bg2);
                     }
                 }
                 else
                 {
                     if (yy % 2 == 0)
                     {
                         col.a = Mathf.InverseLerp(0, 255, GameManager.Instance.bg2);
                     }
                     else
                     {
                         col.a = Mathf.InverseLerp(0, 255, GameManager.Instance.bg1);
                     }
                 }
                 bg.render.color       = col;
                 bg.transform.position = myPos;
                 bg.pos.x = xx;
                 bg.pos.y = yy;
             }
         }
     }
     for (int xx = 0; xx < startingTiles;)
     {
         int randX = Random.Range(0, xSize);
         int randY = Random.Range(0, ySize);
         int type  = Random.Range(0, GameManager.Instance.colors.Length);
         if (tiles [randX, randY] == null)
         {
             StartCoroutine(CreateTile(randX, randY, type));
             xx++;
         }
     }
     ResetGrid();
 }
Esempio n. 13
0
        /// <summary>
        /// Creates the grid on which the game will take place.
        /// </summary>
        private void CreateGrid()
        {
            var panel = new BackgroundTile();

            for (var x = 0; x <= 10; x++)
            {
                for (var y = 0; y <= 20; y++)
                {
                    tlpGameGrid.Controls.Add(panel.Default(), x, y);
                }
            }
        }
Esempio n. 14
0
    private GameObject createTile(string name, Vector3 position)
    {
        GameObject bg = new GameObject(name);

        BackgroundTile bgTile = bg.AddComponent(typeof(BackgroundTile)) as BackgroundTile;

        bgTile.image = backgroundImage;
        bgTile.transform.position = position;

        bg.transform.parent = this.transform;

        return(bg);
    }
Esempio n. 15
0
    void ReAllocateCenter(GameObject new_center)
    {
        BackgroundTile center_bt      = new_center.GetComponent <BackgroundTile>();
        Position       new_center_pos = center_bt.Pos;

        Renderer old_center = center;

        center = new_center.GetComponent <Renderer>();

        clones.Remove(new_center);
        clones.Add(old_center.gameObject);

        foreach (GameObject clone in clones)
        {
            //Debug.Log("===========");
            BackgroundTile bt = clone.GetComponent <BackgroundTile>();
            if (bt.Pos.ShouldMove(new_center_pos))
            {
                // Modify clone position to oppoiste
                //Debug.Log("old position " + bt.Pos.ToString());
                Position pos = bt.Pos;
                pos.ShiftOpposite();
                bt.Pos = pos;
                TeleportTo(clone, pos);
                //Debug.Log("new position " + bt.Pos.ToString());
                //Destroy(clone);
            }
            else
            {
                // just modifiy position kept if tile not moved
                // can just mmodifiy the reference, don't need to use SetPos
                //Debug.Log("old position "+bt.Pos.ToString());
                Position pos = bt.Pos;
                pos.ShiftString(Position.OppositeDir(new_center_pos.GetDir()));
                bt.Pos = pos;
                //Debug.Log("new position " + bt.Pos.ToString());
            }
        }


        // center tile never moved just position reallocated
        //BackgroundTile old_center_bt = old_center.gameObject.GetComponent<BackgroundTile>();
        //old_center_bt.Pos.ShiftString(Position.OppositeDir(new_center_pos.GetDir()));

        center_bt.Pos = new Position("CC");
    }
Esempio n. 16
0
        private static BackgroundTileset GetBackgroundTileset(Palettes palettes, byte[][] tileGfx)
        {
            BackgroundTile[] tiles = new BackgroundTile[BackgroundTileset.TileCount];

            for (int i = 0; i < Math.Min(tileGfx.Length, tiles.Length); i++)
            {
                tiles[i] = new BackgroundTile(tileGfx[i], palettes);
            }

            // If the tileset isn't full, fill in the rest of the tileset with empty tiles
            for (int i = tileGfx.Length; i < BackgroundTileset.TileCount; i++)
            {
                tiles[i] = new BackgroundTile(new byte[16], palettes);
            }

            return(new BackgroundTileset(tiles));
        }
Esempio n. 17
0
    // Update is called once per frame
    void Update()
    {
        if (lvl == null)
        {
            lvl = WorldController.Instance.lvl;
        }
        //       currFramePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //        currFramePosition.z = .5f;
        // Do a raycast to find position on field
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        currFramePosition   = ray.origin - (ray.origin.z / ray.direction.z) * ray.direction;
        currFramePosition.z = .5f;

        UpdateCursor();

        lastFramePosition   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        lastFramePosition.z = .5f;
        // Press left mouse button
        // TODO: Probably move this code to another controller to enable different interfaces
        if (Input.GetMouseButtonDown(0))
        {
            if (WorldController.Instance.locked == false)
            {
                Vector3        Absoluteposition = new Vector3(Mathf.Round(currFramePosition.x), Mathf.Round(currFramePosition.y), .5f);
                BackgroundTile tile             = WorldController.Instance.GetTileAt((int)Absoluteposition.x, (int)Absoluteposition.y);
//                Debug.Log(tile.GetChild());
                if ((tile != null) && (tile.GetChild() == null))
                {
                    tile.CreateChild();
                    Debug.Log("Clicked at (" + tile.X + "," + tile.Y + ")");
                    // TODO: Only recognizes black tile moves by now!
                    WorldController.Instance.moves[0]--;
                    StartCoroutine(WorldController.Instance.UpdateTiles());
                }
                else
                {
                    Debug.Log("Out of boundaries");
                }
            }
        }
        if (Input.GetMouseButton(1))
        {
            StartCoroutine(WorldController.Instance.Restart());
        }
    }
Esempio n. 18
0
            public TileSwallower swallow(string line)
            {
                // '\d' represents a single so that we can extract a single
                Regex           tileExtractor = new Regex(@"(\d+)-(\d+)-(\d+)-(\d+)");
                MatchCollection tileMatchs    = tileExtractor.Matches(line);

                foreach (Match tileMatch in tileMatchs)
                {
                    //read tile code, house flag and garbage amount
                    var backgroundCode = Int32.Parse(tileMatch.Groups[1].Value);
                    var roadCode       = Int32.Parse(tileMatch.Groups[2].Value);
                    var houseCode      = Int32.Parse(tileMatch.Groups[3].Value);
                    var garbageAmount  = Int32.Parse(tileMatch.Groups[4].Value);

                    var hasRoad  = roadCode > 0;
                    var hasHouse = houseCode > 0;

                    IMapTile tile;                                 //empty tile
                    if (hasRoad)                                   //Plain
                    {
                        var roadType = RoadCorrespondor(roadCode); //tile orientation
                        tile = new RoadTile(roadType);
                        if (hasHouse)
                        {
                            var houseType = HouseCorrespondor(houseCode);
                            tile = new HouseTile(
                                roadType,
                                houseType,
                                TrashType.Paper,
                                garbageAmount);
                        }
                    }
                    else
                    {
                        var backgroundType = BackgroundCorrespondor(backgroundCode); //tile orientation
                        tile = new BackgroundTile(backgroundType);
                    }
                    AddTile(tile);
                    //decrease remaining needed item
                    remainingTilesToComplete--;
                }

                //chained call so return yourself
                return(this);
            }
Esempio n. 19
0
    public void LoadBackgroundTiles(string bkgType, int width, int height)
    {
        for (int x = 0 - widthThresold; x < width + widthThresold; x++)
        {
            for (int y = 0 - heightThresold; y < height + heightThresold; y++)
            {
                BackgroundTile bgTile = Instantiate(backgroundTilePrefab).GetComponent <BackgroundTile>();
                bgTile.transform.position = new Vector3(x, y);
                bgTile.transform.parent   = gameObject.transform;
                bgTile.type = bkgType;

                bgTile.GetComponent <SpriteRenderer>().sprite =
                    SpriteDictionary.Instance.bkgSpriteDictionary.GetSprite(bkgType);
                bgTile.GetComponent <SpriteRenderer>().sortingOrder = -1;
                GameStateManager.Instance.bkgTiles.Add(bgTile);
            }
        }
    }
Esempio n. 20
0
    // Use this for initialization
    void Start()
    {
        /*
         *      if (isLooping) {
         *              // Get all children of the layer with a renderer
         *              backgroundPart = new List<Transform> ();
         *              for (int i = 0; i < transform.childCount; i++) {
         *                      Transform child = transform.GetChild (i);
         *                      if (child.GetComponent<Renderer>() != null)
         *                              backgroundPart.Add (child);
         *              }
         *      }
         * /**/

        isReAllocatingCenter = false;


        rb2d = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D> ();

        width  = center.bounds.size.x;
        height = center.bounds.size.y;


        List <string> dirsArray = new List <string> {
            "SW", "SC", "SE", "CW", "CE", "NW", "NC", "NE"
        };

        //List<Transform> clones;
        foreach (string dir in dirsArray)
        {
            Position   pos   = new Position(dir);
            GameObject clone = CreateBackgroundClone(center.gameObject, pos);
            clone.transform.parent = gameObject.transform;
            BackgroundTile bt = clone.AddComponent <BackgroundTile>();
            bt.Pos = pos;
            clones.Add(clone);
        }

        BackgroundTile center_bt = center.gameObject.AddComponent <BackgroundTile>();

        center_bt.Pos = new Position("CC");

        lastTimePlayerInCenter = 0f;
    }
Esempio n. 21
0
    IEnumerator DoNextGenerationStep(ArrayList activeList)
    {
        int                 currentIndex = activeList.Count - 1;
        BackgroundTile      currentTile  = (BackgroundTile)activeList[currentIndex];
        GeneratorDirections direction    = CellDirection.getRandomDirection;
        Vector2             coordinates  = currentTile.mapCoordinate + CellDirection.toVector(direction);

        if (ContainsCoordinates(coordinates) && mapGameObjects[(int)coordinates.x, (int)coordinates.y] == null)
        {
            activeList.Add(CreateCell(coordinates));
            cellCount++;
        }
        else
        {
            activeList.RemoveAt(currentIndex);
        }

        yield return(new WaitForSeconds(1.0f));
    }
Esempio n. 22
0
    /// <summary>
    /// Spawns tiles to their positions
    /// </summary>
    /// <param name="leveldata"> This needs a leveldata map to read out of to get the data of the tiles </param>
    private void SpawnTiles(Map leveldata)
    {
        foreach (Layer _layer in leveldata.Layers)
        {
            if (leveldata.Layers == null || leveldata.Layers.Length == 0)
            {
                continue;
            }

            short[,] _tileNumbers = _layer.GetTileArray();

            for (int row = 0; row < _layer.Height; row++)
            {
                for (int col = 0; col < _layer.Width; col++)
                {
                    bool _isBackgroundTile = _layer.GetBoolProperty("Background");

                    int     _tileNumber = _tileNumbers[col, row];
                    TileSet _tiles      = leveldata.GetTileSet(_tileNumber);

                    string _filenameTiles = _tiles.Image.FileName;
                    _filenameTiles = _filenameTiles.Remove(0, 3);
                    if (_tileNumber > 0 && _isBackgroundTile == false)
                    {
                        CollisionTile _tile = new CollisionTile(_filenameTiles, _tiles.Columns, _tiles.Rows);
                        _tile.SetFrame(_tileNumber - _tiles.FirstGId);
                        _tile.x = col * _tile.width;
                        _tile.y = row * _tile.height;
                        AddChild(_tile);
                    }
                    else if (_tileNumber > 0 && _isBackgroundTile == true)
                    {
                        BackgroundTile _backgroundTile = new BackgroundTile(_filenameTiles, _tiles.Columns, _tiles.Rows);
                        _backgroundTile.SetFrame(_tileNumber - _tiles.FirstGId);
                        _backgroundTile.x = col * _backgroundTile.width;
                        _backgroundTile.y = row * _backgroundTile.height;
                        AddChild(_backgroundTile);
                    }
                }
            }
        }
    }
Esempio n. 23
0
    BackgroundTile CreateCell(Vector2 coordinate)
    {
        Vector3        gameWorldPlacementPos = new Vector3(coordinate.x * tileWidth, coordinate.y * tileHeight, 20);
        BackgroundTile newTile = Instantiate(backgroundTile, gameWorldPlacementPos, Quaternion.identity) as BackgroundTile;

        mapObjects.Add(newTile.gameObject);
        newTile.mapCoordinate = new Vector2(coordinate.x, coordinate.y);

        mapGameObjects[(int)coordinate.x, (int)coordinate.y] = newTile;
        mapCoordinates[(int)coordinate.x, (int)coordinate.y] = 1;
        int spawnEnemy = Random.Range(0, 100);

        if (spawnEnemy < game.currentSpawnRate)
        {
            spawnPoints[(int)coordinate.x, (int)coordinate.y] = 1;
            spawnWorldPositions.Add(new Vector3((int)coordinate.x * tileWidth, (int)coordinate.y * tileHeight, 0));
        }

        return(newTile);
    }
Esempio n. 24
0
    private IEnumerator WaitUntilPrevHexReset(bool right)
    {
        tempTile = grid.allTiles[_hex1X, _hex1Y];
        if (rotateCounter % 3 == 1 && right == false || rotateCounter % 3 == 2 && right == true)//if rotate clockwise once or counterclocwise twice
        {
            grid.allTiles[_hex1X, _hex1Y]             = grid.allTiles[_hex2X, _hex2Y];
            grid.allTiles[_hex1X, _hex1Y].coordinateX = _hex1X;
            grid.allTiles[_hex1X, _hex1Y].coordinateY = _hex1Y;

            grid.allTiles[_hex2X, _hex2Y]             = grid.allTiles[_hex3X, _hex3Y];
            grid.allTiles[_hex2X, _hex2Y].coordinateX = _hex2X;
            grid.allTiles[_hex2X, _hex2Y].coordinateY = _hex2Y;


            grid.allTiles[_hex3X, _hex3Y]             = tempTile;
            grid.allTiles[_hex3X, _hex3Y].coordinateX = _hex3X;
            grid.allTiles[_hex3X, _hex3Y].coordinateY = _hex3Y;
            Debug.Log("Clockwise 1 time");
        }
        else if (rotateCounter % 3 == 2 && right == false || rotateCounter % 3 == 1 && right == true)//if rotate clockwise twice or counterclockwise once
        {
            grid.allTiles[_hex1X, _hex1Y]             = grid.allTiles[_hex3X, _hex3Y];
            grid.allTiles[_hex1X, _hex1Y].coordinateX = _hex1X;
            grid.allTiles[_hex1X, _hex1Y].coordinateY = _hex1Y;

            grid.allTiles[_hex3X, _hex3Y]             = grid.allTiles[_hex2X, _hex2Y];
            grid.allTiles[_hex3X, _hex3Y].coordinateX = _hex3X;
            grid.allTiles[_hex3X, _hex3Y].coordinateY = _hex3Y;

            grid.allTiles[_hex2X, _hex2Y]             = tempTile;
            grid.allTiles[_hex2X, _hex2Y].coordinateX = _hex2X;
            grid.allTiles[_hex2X, _hex2Y].coordinateY = _hex2Y;
            Debug.Log("Clockwise 2 time");
        }


        rotateCounter = 0;
        grid.dotHolder.transform.GetChild(previndex).transform.rotation = Quaternion.Euler(Vector3.zero);
        //Debug.Log("Coordinates of hexagons previous " + _hex1X +","+_hex1Y+"      " +_hex2X +"," +_hex2Y +"       " +_hex3X +","+ _hex3Y);
        yield return(StartCoroutine(WaitUntilCurrentHexParentReset()));
    }
Esempio n. 25
0
    public override void Initialize()
    {
        for (int i = 1; i < NumberOfTileRepeats; i++)
        {
            // Make a clone of the tile object which gets picked up by the layout group - creates the infinite scroll effect
            Instantiate(BackgroundTile, transform);
        }

        backgroundHeight = BackgroundTile.GetComponent <RectTransform>().rect.height;
        if (!ScrollBottomToTop)
        {
            float angle = Mathf.Deg2Rad * transform.localEulerAngles.z + Mathf.PI / 2;

            // We need to move the whole thing up so that the cloned tile appears at the bottom
            transform.position += new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0)
                                  * backgroundHeight
                                  * (NumberOfTileRepeats - 1);
        }
        startPosition      = transform.position;
        backgroundElements = transform.GetComponentsInChildren <IBackgroundElement>().ToList();
    }
Esempio n. 26
0
 public TileGenerator(int w = 10, int h = 10)
 {
     //       Generate Tiles
     Width  = w;
     Height = h;
     map    = new BackgroundTile[Width, Height];
     Debug.Log("Created map with dimensions " + Width + "x" + Height);
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             //Debug.Log("Created BGTile at (" + x + "," + y);
             map[x, y] = new BackgroundTile(x, y);
         }
     }
     // Fill Neighbours Array
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             if (x > 0)
             {
                 map[x, y].AddNeighbor("East", map[x - 1, y]);
             }
             if (x < Width - 1)
             {
                 map[x, y].AddNeighbor("West", map[x + 1, y]);
             }
             if (y > 0)
             {
                 map[x, y].AddNeighbor("South", map[x, y - 1]);
             }
             if (y < Height - 1)
             {
                 map[x, y].AddNeighbor("North", map[x, y + 1]);
             }
         }
     }
 }
Esempio n. 27
0
        private void RebuildSprites()
        {
            // Release all pool sprites
            pool.ReleaseAll();

            // Disable sprite on main
            sr.enabled = false;

            // Determine how many sprites you need for scrolling
            Vector2 size   = sr.bounds.size;
            int     width  = Mathf.CeilToInt(camWidth * 2f / size.x);
            int     height = Mathf.CeilToInt(camHeight * 2f / size.y);

            // Create those sprites in the right locations
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (pool.Size == pool.maxSize)
                    {
                        Debug.Log("Pool at max size");
                    }
                    GameObject go = pool.TryGet();
                    go.ThrowIfNull();
                    go.transform.parent   = transform;
                    go.transform.rotation = transform.rotation;
                    BackgroundTile tile = go.AddComponent <BackgroundTile>();
                    tile.x    = x;
                    tile.y    = y;
                    tile.size = size;
                }
            }

            // Update sprite positions
            UpdateSpritePositions();
        }
Esempio n. 28
0
        /// <summary>
        /// Moves the active piece in the given direction.
        /// </summary>
        private void MovePiece(MovementHelper.Direction direction)
        {
            var defaultPanel = new BackgroundTile().Default().BackColor;
            var newPlacement = _movementHelper.CalculateMovement(direction, _piece.CurrentPlacement);

            // Clear the current piece from the game grid
            // so we don't interfere with collision detection
            DrawPlacement(_piece.CurrentPlacement, defaultPanel);

            // Ensure next placement is valid
            if (_movementHelper.CheckIfMoveIsValid(newPlacement, tlpGameGrid))
            {
                // Paint piece in new location
                DrawPlacement(newPlacement, _piece.Color);

                // Piece moved successfully, so update the piece
                _piece.CurrentPlacement = newPlacement;
            }
            else
            {
                DrawPlacement(_piece.CurrentPlacement, _piece.Color);
                SpawnNewPiece();
            }
        }
Esempio n. 29
0
    private void CreateBoard()
    {
        _rotation = Quaternion.Euler(90, 0, 0);

        for (int row = 0; row < GameManager.instance.rows; row++)           //Create cell by selected row and height
        {
            for (int col = 0; col < GameManager.instance.cols; col++)
            {
                //position.x = (z%2)*Hexagon.innerRadius+x * (Hexagon.innerRadius*2f); ////// If we rotate hexagon 60 degrees, we should use these calculations
                //position.y = z * (Hexagon.outerRadius*1.5f);/////////////////////////////// If we rotate hexagon 60 degrees, we should use these calculations
                _position.x      = row * Hexagon.outerRadius * 1.5f;                                                                         // row counter * outerRadius
                _position.y      = col * Hexagon.innerRadius * 2f + Mathf.Cos(Mathf.PI * (Mathf.Pow(row, 2) + 1) / 2) * Hexagon.innerRadius; //column counter * innerRadius + (0 or -1 * innerRadius)
                _position.z      = 0f;
                _positionUp.x    = _position.x + Hexagon.outerRadius * 0.5f;
                _positionUp.y    = _position.y + Hexagon.innerRadius;
                _positionUp.z    = 0f;
                _positionRight.x = _position.x + Hexagon.outerRadius;
                _positionRight.y = _position.y;
                _positionRight.z = 0f;
                BackgroundTile backgroundTile = Instantiate(tilePrefab, _position, _rotation);
                backgroundTile.transform.parent = GameManager.instance.grid.transform;
                backgroundTile.name             = row + "," + col;
                backgroundTile.coordinateX      = row;
                backgroundTile.coordinateY      = col;
                allTiles[row, col] = backgroundTile;
                if (row != (GameManager.instance.rows - 1))
                {
                    if (row % 2 == 0)
                    {
                        if (col != (GameManager.instance.cols - 1))
                        {
                            DotTouch dotright =
                                Instantiate(dotPrefab, _positionRight, Quaternion.Euler(Vector3.zero));
                            dotright.transform.parent = dotHolder.transform;
                            dotright.index            = dotCounter++;
                            dotright.name             = row + "," + col + "." + (row + 1) + "," +
                                                        (col + 1) + "." + (row + 1) + "," + col;
                            allDots.Add(dotright);
                            DotTouch dotup = Instantiate(dotPrefab, _positionUp, Quaternion.Euler(Vector3.zero));
                            dotup.transform.parent = dotHolder.transform;
                            dotup.name             = row + "," + col + "." + row + "," + (col + 1) + "." + (row + 1) + "," +
                                                     (col + 1);
                            dotup.index = dotCounter++;
                            allDots.Add(dotup);
                        }
                    }
                    else
                    {
                        if (col != (GameManager.instance.cols - 1))
                        {
                            DotTouch dotup = Instantiate(dotPrefab, _positionUp, Quaternion.Euler(Vector3.zero));
                            dotup.transform.parent = dotHolder.transform;
                            dotup.name             = row + "," + col + "." + row + "," + (col + 1) + "." + (row + 1) + "," + col;
                            dotup.index            = dotCounter++;
                            allDots.Add(dotup);
                        }

                        if (col != 0)
                        {
                            DotTouch dotright =
                                Instantiate(dotPrefab, _positionRight, Quaternion.Euler(Vector3.zero));
                            dotright.transform.parent = dotHolder.transform;
                            dotright.name             = row + "," + col + "." + (row + 1) +
                                                        "," + col + "." + (row + 1) + "," + (col - 1);
                            dotright.index = dotCounter++;
                            allDots.Add(dotright);
                        }
                    }
                }
            }
        }
    }
Esempio n. 30
0
        // TODO change return type to void?
        public string LoadLevel(XDocument xDoc, ref Vector2 startingCenterScreenPos)
        {
            isLevelLoaded = false;
            try
            {
                //XDocument xDoc = XDocument.Load(fileName);
                XElement curElement, childElement;
                curElement = xDoc.Root.Element("BasicInfo");
                levelName = curElement.Element("Name").Value;
                pxWidth = uint.Parse(curElement.Element("Width").Value);
                pxHeight = uint.Parse(curElement.Element("Height").Value);
                childElement = curElement.Element("StartingScreenPos");
                startingCenterScreenPos.X = uint.Parse(childElement.Element("X").Value);
                startingCenterScreenPos.Y = uint.Parse(childElement.Element("Y").Value);

                curElement = xDoc.Root.Element("Backgrounds");
                numBackgroundLayers = (uint)curElement.Attribute("NumLayers");
                backgroundRowTiles = new uint[numBackgroundLayers];
                backgroundRowColumns = new uint[numBackgroundLayers];
                backgrounds = new BackgroundTile[numBackgroundLayers][][];
                if (numBackgroundLayers > 0)
                {
                    IEnumerable<XElement> bgList = curElement.Elements("Background");
                    foreach (XElement bgElem in bgList)
                    {
                        uint layerNum, numRows, numColumns;
                        string texturePath;
                        layerNum = uint.Parse(bgElem.Element("Layer").Value);
                        texturePath = bgElem.Element("TexturePath").Value;
                        numColumns = uint.Parse(bgElem.Element("NumColumns").Value);
                        numRows = uint.Parse(bgElem.Element("NumRows").Value);
                        Texture2D tempTexture = contentManager.Load<Texture2D>(texturePath);
                        backgroundRowTiles[layerNum] = numColumns;
                        backgroundRowColumns[layerNum] = numRows;
                        //Initialize the tiles for this layer
                        backgrounds[layerNum] = new BackgroundTile[numColumns][];
                        for (uint x = 0; x < numColumns; ++x)
                        {
                            backgrounds[layerNum][x] = new BackgroundTile[numRows];
                            for (uint y = 0; y < numRows; ++y)
                            {
                                backgrounds[layerNum][x][y] = new BackgroundTile(tempTexture, x, y);
                            }
                        }
                    }
                } // if (numBackgroundLayers > 0)
                // TODO verify starting position is in level
                // TODO verify total level width and height are greater than our max resolution

                Vector2[] offsets = new Vector2[4];
                offsets[0] = new Vector2(0, 0);
                offsets[1] = new Vector2(0, pxHeight);
                offsets[2] = new Vector2(pxWidth, pxHeight);
                offsets[3] = new Vector2(pxWidth, 0);
                Physics.Polygon tempPoly = new Physics.Polygon(Vector2.Zero, offsets, Vector2.Zero, 4, true);
                collisionPolygons.Add(tempPoly);

                foreach (Physics.Polygon poly in collisionPolygons)
                    poly.SetPosition(Vector2.Zero, Vector2.Zero, 0);
            }
            catch (Exception ex)
            {
                //TODO log
                //Error loading the level
                //TODO show messagebox
                Environment.Exit(0);
            }
            isLevelLoaded = true;
            return null;
        }
Esempio n. 31
0
        public static Bitmap FindResource(BackgroundTile.BackgroundType animation)
        {
            switch (animation)
            {
                case BackgroundTile.BackgroundType.Plain:
                    return Properties.Resources.TilePlain;
                case BackgroundTile.BackgroundType.BlueHouse:
                    return Properties.Resources.BlueHouseTop;
                case BackgroundTile.BackgroundType.RedHouse:
                    return Properties.Resources.RedHouseTop;
                case BackgroundTile.BackgroundType.BrownHouse:
                    return Properties.Resources.BrownHouse;

                case BackgroundTile.BackgroundType.ForestTopLeft:
                    return Properties.Resources.ForestTopLeft;
                case BackgroundTile.BackgroundType.ForestTopMiddle:
                    return Properties.Resources.ForestTopMiddle;
                case BackgroundTile.BackgroundType.ForestTopRight:
                    return Properties.Resources.ForestTopRight;

                case BackgroundTile.BackgroundType.ForestMiddleLeft:
                    return Properties.Resources.ForestMiddleLeft;
                case BackgroundTile.BackgroundType.ForestMiddle:
                    return Properties.Resources.ForestMiddle;
                case BackgroundTile.BackgroundType.ForestMiddleRight:
                    return Properties.Resources.ForestMiddleRight;

                case BackgroundTile.BackgroundType.ForestBottomLeft:
                    return Properties.Resources.ForestBottomLeft;
                case BackgroundTile.BackgroundType.ForestBottomMiddle:
                    return Properties.Resources.ForestBottomMiddle;
                case BackgroundTile.BackgroundType.ForestBottomRight:
                    return Properties.Resources.ForestBottomRight;

                case BackgroundTile.BackgroundType.ForestSolo:
                    return Properties.Resources.ForestSolo;
                case BackgroundTile.BackgroundType.DechetterieTopLeft:
                    return Properties.Resources.DechetterieTopLeft;
                case BackgroundTile.BackgroundType.DechetterieTopRight:
                    return Properties.Resources.DechetterieTopRight;

                case BackgroundTile.BackgroundType.MairieTopLeft:
                    return Properties.Resources.mairie_top_left;
                case BackgroundTile.BackgroundType.MairieTopMid:
                    return Properties.Resources.mairie_top_mid;
                case BackgroundTile.BackgroundType.MairieTopRight:
                    return Properties.Resources.mairie_top_right;
                case BackgroundTile.BackgroundType.MairieMidLeft:
                    return Properties.Resources.mairie_mid_left;
                case BackgroundTile.BackgroundType.MairieMid:
                    return Properties.Resources.mairie_mid;
                case BackgroundTile.BackgroundType.MairieMidRight:
                    return Properties.Resources.mairie_mid_right;

                case BackgroundTile.BackgroundType.HouseFlowerTop:
                    return Properties.Resources.House4_top;

                case BackgroundTile.BackgroundType.Heolienne:
                    return Properties.Resources.Heolienne;

                case BackgroundTile.BackgroundType.HousePink:
                    return Properties.Resources.House5_top;
                case BackgroundTile.BackgroundType.HouseGreen:
                    return Properties.Resources.House6_top;
                case BackgroundTile.BackgroundType.HouseWater:
                    return Properties.Resources.House7_top;

                case BackgroundTile.BackgroundType.LabTopLeft:
                    return Properties.Resources.House8_topleft;
                case BackgroundTile.BackgroundType.LabTopRight:
                    return Properties.Resources.House8_topright;

                case BackgroundTile.BackgroundType.ChurchTopLeft:
                    return Properties.Resources.Church_topleft;
                case BackgroundTile.BackgroundType.ChurchTopRight:
                    return Properties.Resources.Church_topright;
                case BackgroundTile.BackgroundType.ChurchMidLeft:
                    return Properties.Resources.Church_midleft;
                case BackgroundTile.BackgroundType.ChurchMidRight:
                    return Properties.Resources.Church_midright;

                case BackgroundTile.BackgroundType.HouseYellowTopLeft:
                    return Properties.Resources.House9_topleft;
                case BackgroundTile.BackgroundType.HouseYellowTopRight:
                    return Properties.Resources.House9_topright;

                default:
                    Console.Error.WriteLine("Unhandled animation: " + animation);
                    return Properties.Resources.Missing; //FIXME Not the good one !!!
            }
        }
Esempio n. 32
0
 public void AddNeighbor(string label, BackgroundTile tile)
 {
     neighbors.Add(label, tile);
 }
Esempio n. 33
0
 public ActiveTile(BackgroundTile Parent, int x, int y)
 {
     X      = x;
     Y      = y;
     parent = Parent;
 }
Esempio n. 34
0
 public static void AddObject(BackgroundTile t)
 {
     tilesToAdd.Add(t);
 }