Пример #1
0
        //Use the vectors to move the character on the x axis
        public void Move(Floor floor, Level[] map)
        {
            float     prevX    = X;
            Rectangle charRect = new Rectangle((int)X, (int)(Y + Height - 1), (int)Width, 1);

            if (X <= 0)
            {
                xVector += 20;
                Jump();
            }
            if (X < screenWidth - xVector)
            {
                if (!landInBramble)
                {
                    X       += (float)xVector;
                    distance = (float)xVector;
                }
            }
            if (colTest(charRect, map))
            {
                if (!stable && yVector >= 0)
                {
                    Y      = tileY - Height + 1;
                    stable = true;
                }
            }
            else if (colTest(charRect, floor))
            {
                if (!stable && yVector >= 0)
                {
                    Y      = floor.Y - Height + 1;
                    stable = true;
                }
            }
            else
            {
                stable = false;
            }
            if (!stable)
            {
                Y = Y + (float)yVector;
            }
            if (Jumped)
            {
                Y      = Y + (float)yVector;
                Jumped = false;
            }
            if (prevX < X)
            {
                score += 1 * (Level.curLevel + 1);
                foreach (Land l in floor.floor)
                {
                    l.X    = l.X - distance;
                    l.rect = new Rectangle((int)l.X, (int)l.Y, (int)l.Width, (int)l.Height);
                }
                foreach (Level l in map)
                {
                    foreach (Tile t in l.level)
                    {
                        t.X    = t.X - distance;
                        t.rect = new Rectangle((int)t.X, (int)t.Y, (int)t.Width, (int)t.Height);
                    }
                }
            }
            if (prevX <= X)
            {
                FacingLeft = false;
            }
            else if (prevX >= X)
            {
                FacingLeft = true;
            }
        }
Пример #2
0
        //Generate the level randomly based on several parameters
        public Level(GameContent gameContent, SpriteBatch spriteBatch, float screenWidth, float screenHeight, Floor floor, int levelNum)
        {
            levelCount      = levelNum;
            variation       = 100;                                        //How far up or down the tile with be
            platformNumber  = 20 * levelCount;                            // the number of platforms in the level
            specPlatformNum = 5 * levelCount;                             //the number of special platforms in the level
            level           = new Tile[platformNumber + specPlatformNum]; //create a tile array to hold all platforms needed for level
            Width           = 0;
            Height          = 0;
            Tile platform = new Tile(gameContent, spriteBatch, 0, 0);

            X          = floor.X + floor.Width;             // the base X coordinate used to determine first tile location
            Y          = screenHeight - (screenHeight / 4); //the base Y coordinate used to determine first tile location
            prevHeight = 0;
            visible    = true;

            //loop to create all the basic tiles in the game
            for (int i = 0; i < platformNumber; i++)
            {
                level[i] = new Tile(gameContent, spriteBatch, X + (100 * i + 1), Y);
                Width   += level[i].Width;
                int zerOne = randGen.Next(0, 2);
                prevHeight = Y;
                if (Y > 100 && Y <= (screenHeight - 200))
                {
                    if (zerOne == 1)
                    {
                        Y = (Y + variation);
                    }
                    else
                    {
                        Y = Y - variation;
                    }
                }
                else
                {
                    Y = screenHeight - 300;
                }
            }

            for (int i = platformNumber; i < platformNumber + specPlatformNum; i++)
            {
                int type          = randGen.Next(2, 4);
                int offsetShift   = randGen.Next(1, 4);
                int platformPlace = randGen.Next(0, platformNumber);
                int Y             = 0;
                int x             = 0;
                if (type == 2)
                {
                    //Spike platform creation
                    xOffset = 50;
                    yOffset = (int)level[platformPlace].Y;
                    X       = level[platformPlace].X - xOffset;
                    Y       = yOffset;
                }
                else
                {
                    //Icy Platform creation
                    xOffset = 0;
                    yOffset = -70 * offsetShift;
                    X       = level[platformPlace].X - xOffset;
                    if (level[platformPlace].Y < screenHeight / 2)
                    {
                        Y = (int)level[platformPlace].Y - yOffset;
                    }
                    else
                    {
                        Y = (int)level[platformPlace].Y + yOffset;
                    }
                }
                level[i] = new Tile(gameContent, spriteBatch, X, Y, type);
            }
            X = level[0].X;
        }