Esempio n. 1
0
        private void reset()
        {
            activePiece = new Piece();
            isactive = false;

            for (int i = 0; i < gridsize.Y; i++)
            {
                for (int j = 0; j < gridsize.X; j++)
                {
                    blocks[i][j] = Piece.block.NONE;
                }
            }

            score = 0;
            level = 1;
            lines = 0;
            stepTime = 1000.0f;
        }
Esempio n. 2
0
        public world(int x, int y, int unit, Vector2 gamesize)
        {
            gridsize = new Vector2(x, y);
            this.gamesize = gamesize;
            gridunit = unit;
            score = 0;
            level = 1;
            lines = 0;
            stepTime = 1000.0f;

            paused = false;

            rand = new Random();

            blocks = new Piece.block[y][];

            startpos = new Vector2( ((int)this.gamesize.X / 2) - 2*unit,2*unit );
            shelfpos = new Vector2(0, 0);
            isactive = false;

            int piece = rand.Next(7);
            int r, g, b;
            r = rand.Next(85, 255);
            g = rand.Next(85, 255);
            b = rand.Next(85, 255);
            nextPiece = new Piece((Piece.block)piece, new Color(r, g, b), shelfpos);

            // test to populate the playable area
            for (int i = 0; i < y; i++)
            {
                blocks[i] = new Piece.block[x];
                for (int j = 0; j < x; j++)
                {
                   blocks[i][j] = Piece.block.NONE;
                }
            }
        }
Esempio n. 3
0
        // Updates the game by:
        //     moving the activePiece down
        //     TODO: checking for collision
        //     TODO: adding piece to backround if colided
        //     removing completed rows
        //     TODO: moving the rows down after some have been removed
        //     increasing  score
        public void Update(GameTime gameTime)
        {
            if (paused) return;

            if (game_lost())
            {
                reset();
            }

            if ((warninglevel = warn_player()) != 0)
            {

                float sinval = (float)( (warninglevel/3.0) *Math.Sin(gameTime.TotalGameTime.Milliseconds * 2*Math.PI / 1000 ));
                warnalpha = (int) (255*(( sinval / 2) + 1));

            }

            if (isactive == false)
            {
                int piece = rand.Next(7);
                int r, g, b;
                r = rand.Next(85,255);
                g = rand.Next(85,255);
                b = rand.Next(85, 255);
                nextPiece.pos = startpos;
                activePiece = nextPiece;
                nextPiece = new Piece((Piece.block)piece, new Color(r, g, b), shelfpos);

                Vector2 start_offset = new Vector2(0, activePiece.bounding_box.Y + activePiece.bounding_box.Height);
                activePiece.move(-start_offset*gridunit);
                isactive = true;

            }
            moveDown(gameTime);

            // NOTE: could possibly change to integers?
            int addedscore = 0;
            // more rows at a time give you a higher multiplier
            int multiplier = 1;

            // Checks for completed rows
            int clearedLines = 0;
            for (int i = 0; i < (int)gridsize.Y; i++)
            {

                if (row_full(i))
                {
                    clearedLines++;
                    addedscore += ( 100  + 100*level) * multiplier;
                    multiplier += 2;
                    for (int j = 0; j < (int)gridsize.X; j++)
                    {
                       blocks[i][j] = Piece.block.NONE ;
                    }
                    for (int j = i; j > 0; j-- )
                        swap_rows(j, j - 1);

                }
            }
            lines += clearedLines;
            score += (ulong)addedscore;

            check_level();
        }