Inheritance: Sprite
示例#1
0
        private void LoadTiles()
        {
            // Allocate the Tile grid.
            tiles = new Tile[map.rows[0].columns.Length, map.rows.Length];
            int x    = 0;
            int y    = 0;
            int newX = 0;

            foreach (Row r in map.rows)
            {
                for (int ix = 0; ix <= r.columns.Length - 1; ix++)
                {
                    Enumeration.TileType nextTileType = Enumeration.TileType.space;
                    if (ix + 1 < r.columns.Length)
                    {
                        nextTileType = r.columns[ix + 1].tileType;
                    }

                    tiles[x, y] = LoadTile(r.columns[ix].tileType, r.columns[ix].state, r.columns[ix].switchButton, r.columns[ix].item, nextTileType, r.columns[ix].timeOpen);
                    //tiles[x, y].tileAnimation.fra = maze.player.sprite.frameRate_background;


                    Rectangle rect = new Rectangle(x * Convert.ToInt32(Math.Truncate(Tile.Size.X)), y * Convert.ToInt32(Math.Truncate(Tile.Size.Y)) - BOTTOM_BORDER, Convert.ToInt32(tiles[x, y].Texture.Width), Convert.ToInt32(tiles[x, y].Texture.Height));
                    Vector2   v    = new Vector2(rect.X, rect.Y);

                    tiles[x, y].Position   = new Position(v, v);
                    tiles[x, y].Position.X = v.X;
                    tiles[x, y].Position.Y = v.Y;



                    //x+1 for avoid base zero x array, WALL POSITION 0-29
                    tiles[x, y].panelInfo = newX + roomIndex;

                    switch (r.columns[ix].spriteType)
                    {
                    case Enumeration.SpriteType.kid:
                        int xPlayer = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                        int yPlayer = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                        maze.player = new Player(this, new Vector2(xPlayer, yPlayer), new Point(x, y), maze.graphicsDevice, r.columns[ix].spriteEffect);
                        break;

                    case Enumeration.SpriteType.guard:
                        int xGuard = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                        //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                        int   yGuard = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                        Guard g      = new Guard(this, new Vector2(xGuard, yGuard), maze.graphicsDevice, r.columns[ix].spriteEffect);
                        maze.sprites.Add(g);
                        break;

                    case Enumeration.SpriteType.skeleton:
                        int xSkel = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                        //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                        int      ySkel = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                        Skeleton h     = new Skeleton(this, new Vector2(xSkel, ySkel), maze.graphicsDevice, r.columns[ix].spriteEffect);
                        maze.sprites.Add(h);
                        break;


                    case Enumeration.SpriteType.serpent:
                        int xSerp = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                        //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                        int     ySerp = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                        Serpent s     = new Serpent(this, new Vector2(xSerp, ySerp), maze.graphicsDevice, r.columns[ix].spriteEffect);
                        maze.sprites.Add(s);
                        break;

                    default:


                        break;
                    }


                    x    += 1;
                    newX += 1;
                }
                x  = 0;
                y += 1;
            }
        }
示例#2
0
        private void LoadTiles()
        {
            // Allocate the Tile grid.
            tiles = new Tile[map.rows[0].columns.Length, map.rows.Length];
            int x = 0;
            int y = 0;
            int newX = 0;

            foreach (Row r in map.rows)
            {
                for (int ix = 0; ix <= r.columns.Length - 1; ix++)
                {
                    Enumeration.TileType nextTileType = Enumeration.TileType.space;
                    if (ix + 1 < r.columns.Length)
                    {
                        nextTileType = r.columns[ix + 1].tileType;
                    }

                    tiles[x, y] = LoadTile(r.columns[ix].tileType, r.columns[ix].state, r.columns[ix].switchButton, r.columns[ix].item, nextTileType, r.columns[ix].timeOpen);
                    //tiles[x, y].tileAnimation.fra = maze.player.sprite.frameRate_background;
                    Rectangle rect = new Rectangle(x * Convert.ToInt32(Math.Truncate(Tile.Size.X)), y * Convert.ToInt32(Math.Truncate(Tile.Size.Y)) - BOTTOM_BORDER, Convert.ToInt32(tiles[x, y].Texture.Width), Convert.ToInt32(tiles[x, y].Texture.Height));
                    Vector2 v = new Vector2(rect.X, rect.Y);

                    tiles[x, y].Position = new Position(v, v);
                    tiles[x, y].Position.X = v.X;
                    tiles[x, y].Position.Y = v.Y;

                    //x+1 for avoid base zero x array, WALL POSITION 0-29
                    tiles[x, y].panelInfo = newX + roomIndex;

                    switch (r.columns[ix].spriteType)
                    {
                        case Enumeration.SpriteType.kid:
                            int xPlayer = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                            int yPlayer = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                            maze.player = new Player(this, new Vector2(xPlayer, yPlayer), new Point(x, y), maze.graphicsDevice, r.columns[ix].spriteEffect);
                            break;

                        case Enumeration.SpriteType.guard:
                            int xGuard = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                            //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                            int yGuard = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                            Guard g = new Guard(this, new Vector2(xGuard, yGuard), maze.graphicsDevice, r.columns[ix].spriteEffect);
                            maze.sprites.Add(g);
                            break;

                        case Enumeration.SpriteType.skeleton:
                            int xSkel = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                            //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                            int ySkel = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                            Skeleton h = new Skeleton(this, new Vector2(xSkel, ySkel), maze.graphicsDevice, r.columns[ix].spriteEffect);
                            maze.sprites.Add(h);
                            break;

                        case Enumeration.SpriteType.serpent:
                            int xSerp = (x - 1) * Tile.WIDTH + Player.SPRITE_SIZE_X;
                            //int yGuard = (y + 1) * (Tile.HEIGHT - Sprite.PLAYER_STAND_FLOOR_PEN - RoomNew.BOTTOM_BORDER + RoomNew.TOP_BORDER);
                            int ySerp = ((y + 1) * (Tile.HEIGHT)) - Sprite.SPRITE_SIZE_Y + RoomNew.TOP_BORDER;
                            Serpent s = new Serpent(this, new Vector2(xSerp, ySerp), maze.graphicsDevice, r.columns[ix].spriteEffect);
                            maze.sprites.Add(s);
                            break;

                        default:

                            break;
                    }

                    x += 1;
                    newX += 1;
                }
                x = 0;
                y += 1;
            }
        }