Example #1
0
        public Level(Texture2D _brick, Texture2D _badGuys, Texture2D _projectile, Texture2D _blank, GraphicsDevice graphicsDevice, SpriteBatch _spriteBatch)
        {
            spriteBatch = _spriteBatch;

            int brick2 = brickSize * brickSize;

            singleBrick = new Color[brick2];
            beginBrick = new Color[brick2];
            contBrick = new Color[brick2];
            endBrick = new Color[brick2];
            topDoor = new Color[brick2];
            botDoor = new Color[brick2];
            destructBrick = new Color[brick2];
            collectable = new Color[brick2];

            openDoor = new AnimatedSprite();

            projectile = _projectile;
            badGuys = _badGuys;
            brick = _brick;
            _brick.GetData<Color>(0, new Rectangle(0, 0, brickSize, brickSize), topDoor, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, brickSize, brickSize, brickSize), botDoor, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 2 * brickSize, brickSize, brickSize), singleBrick, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 3 * brickSize, brickSize, brickSize), beginBrick, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 4 * brickSize, brickSize, brickSize), contBrick, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 5 * brickSize, brickSize, brickSize), endBrick, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 6 * brickSize, brickSize, brickSize), destructBrick, 0, brick2);
            _brick.GetData<Color>(0, new Rectangle(0, 7 * brickSize, brickSize, brickSize), collectable, 0, brick2);

            currLvlText = new Texture2D(graphicsDevice, _blank.Width, _blank.Height);
            blankLevel = new Color[_blank.Height*_blank.Width];
            _blank.GetData<Color>(blankLevel);
            currLvlText.SetData<Color>(blankLevel);
        }
Example #2
0
 //------------------------------------------------------------------
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     spriteWalk = new AnimatedSprite();
     spriteWin = new AnimatedSprite();
 }
Example #3
0
        public Vector2 loadCurrentLevel(string FileName)
        {
            currLvlText.SetData<Color>(blankLevel);

            Vector2 PlayerVector = new Vector2();
            projectileArr = new Projectile[50];//arbitrary value
            isDoorOpen = false;
            levelFile = File.ReadAllLines(FileName);
            collisionCheck = new int[levelFile[0].Length,levelFile.Length];
            destroyTheseBricks = new bool[levelFile[0].Length, levelFile.Length];

            destructBrickArr = new AnimatedSprite[levelFile[0].Length, levelFile.Length];
            badShooters = new AnimatedSprite[levelFile[0].Length, levelFile.Length];

            int x, y, lineY, valueX, currProjectile;// 20 by 20
            x = 0;
            y = 0;
            lineY = 0;
            valueX = 0;
            currProjectile = 0;

            foreach (string line in levelFile)
            {
                foreach (char value in line)
                {
                    if (value == '-')
                    {
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), contBrick, 0, contBrick.Length);
                    }
                    if (value == '[')
                    {
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), beginBrick, 0, contBrick.Length);
                    }
                    if (value == ']')
                    {
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), endBrick, 0, contBrick.Length);
                    }
                    if (value == '_')
                    {
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), singleBrick, 0, contBrick.Length);
                    }
                    if (value == 'T')
                    {
                        doorX = x;
                        doorY = y;
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), topDoor, 0, contBrick.Length);
                    }
                    if (value == '|')
                    {
                        collisionCheck[valueX, lineY] = 1;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), botDoor, 0, contBrick.Length);
                        openDoor.LoadSprite(brick, x + (brickSize / 2), y, 0, 0, 6, brickSize, brickSize * 2, 10);
                    }
                    if (value == 'X')
                    {
                        collisionCheck[valueX, lineY] = 2;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), destructBrick, 0, contBrick.Length);
                        destructBrickArr[valueX, lineY] = new AnimatedSprite();
                        destructBrickArr[valueX, lineY].LoadSprite(brick, x + (brickSize / 2), y + (brickSize / 2), 0, 6 * brickSize, 3, brickSize, brickSize, 15);
                    }
                    if (value == '>')//shooter facing right
                    {
                        collisionCheck[valueX, lineY] = 4;
                        collisionCheck[valueX, lineY - 1] = 4;
                        badShooters[valueX, lineY] = new AnimatedSprite();
                        badShooters[valueX, lineY].LoadSprite(badGuys, x + brickSize/2, y, 0, 0, 7, 50, 100, 9, true);
                        projectileArr[currProjectile] = new Projectile(x, y, true, projectile);
                        currProjectile++;
                    }
                    if (value == '<')
                    {
                        collisionCheck[valueX, lineY] = 4;
                        collisionCheck[valueX, lineY - 1] = 4;
                        badShooters[valueX, lineY] = new AnimatedSprite();
                        badShooters[valueX, lineY].LoadSprite(badGuys, x + brickSize / 2, y, 0, 0, 7, 50, 100, 9, false);
                        projectileArr[currProjectile] = new Projectile(x, y, false, projectile);
                        currProjectile++;
                    }
                    if (value == 'C')
                    {
                        collisionCheck[valueX, lineY] = 3;
                        totalCollectables++;
                        currLvlText.SetData<Color>(0, new Rectangle(x, y, brickSize, brickSize), collectable, 0, contBrick.Length);
                    }
                    if (value == 'O')
                    {
                        PlayerVector.X = (float)x;
                        PlayerVector.Y = (float)y;
                    }

                    x += brickSize;
                    valueX++;
                }
                x = 0;
                y += brickSize;
                valueX = 0;
                lineY++;
            }
            return PlayerVector;
        }