예제 #1
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            // 画像からブロックを切り取る
            const int srcLen  = 60;
            var       srcRect = new Rectangle[Block.COLOR_NUM];

            for (int i = 0; i < Block.COLOR_NUM; ++i)
            {
                srcRect[i] = new Rectangle(i * srcLen, 0, srcLen, srcLen);
            }

            // ゲーム画面にブロックを表示するための領域を確保
            var       screenHeight = CurScreen.Height;
            var       screenWidth  = CurScreen.Width;
            var       destRect     = new Rectangle[screenHeight, screenWidth];
            const int dstLen       = 20;

            for (int y = 0; y < screenHeight; ++y)
            {
                for (int x = 0; x < screenWidth; ++x)
                {
                    destRect[y, x] = new Rectangle(x * dstLen, y * dstLen, dstLen, dstLen);
                }
            }

            // ゲーム画面に描画
            for (int y = 0; y < screenHeight; ++y)
            {
                for (int x = 0; x < screenWidth; ++x)
                {
                    var nc = Block.ColorToInt(CurScreen.Field[y, x]);
                    e.Graphics.DrawImage(BlockImage, destRect[y, x], srcRect[nc], GraphicsUnit.Pixel);
                }
            }
        }