14
2024
11

python编程学习-bloxorz

学习python编程,在新东方少儿编程官网的自由创作平台做的一些作品。

可以在线运行,效果如下(在新页面中打开链接):

代码如下(用到平台自定义的xdf库):

assets = {
    "bitmap1000.png": "20240118/1705548024551_046780.png",
    "bitmap1002.png": "20240118/1705548024603_798710.png",
    "bitmap1004.png": "20240118/1705548024616_385345.png",
    "bitmap1006.png": "20240118/1705548024581_177917.png",
    "bitmap1008.png": "20240118/1705548024543_787011.png",
    "bitmap101.png": "20240118/1705548024547_104964.png",
    "bitmap1010.png": "20240118/1705548024582_748005.png",
    "bitmap1012.png": "20240118/1705548024520_173663.png",
    "bitmap1014.png": "20240118/1705548024690_611319.png",
    "bitmap1016.png": "20240118/1705548024590_222471.png",
    "bitmap103.png": "20240118/1705548024544_130247.png",
    "bitmap105.png": "20240118/1705548024540_420189.png",
    "bitmap107.png": "20240118/1705548024602_383214.png",
    "bitmap109.png": "20240118/1705548024573_178420.png",
    "bitmap111.png": "20240118/1705548024549_650350.png",
    "bitmap266.png": "20240118/1705548024603_143559.png",
    "bitmap270.png": "20240118/1705548024542_155573.png",
    "bitmap272.png": "20240118/1705548024717_203151.png",
    "bitmap274.png": "20240118/1705548024550_978919.png",
    "bitmap276.png": "20240118/1705548024656_275751.png",
    "bitmap278.png": "20240118/1705548024583_638035.png",
    "bitmap280.png": "20240118/1705548024660_202719.png",
    "bitmap282.png": "20240118/1705548024544_336964.png",
    "bitmap285.png": "20240118/1705548024588_847221.png",
    "bitmap287.png": "20240118/1705548024671_633939.png",
    "bitmap289.png": "20240118/1705548024655_260561.png",
    "bitmap292.png": "20240118/1705548024688_054441.png",
    "bitmap294.png": "20240118/1705548024658_986699.png",
    "bitmap297.png": "20240118/1705548024653_592182.png",
    "bitmap299.png": "20240118/1705548024699_489534.png",
    "bitmap301.png": "20240118/1705548024717_028014.png",
    "bitmap303.png": "20240118/1705548024537_100422.png",
    "bitmap305.png": "20240118/1705548024680_443555.png",
    "bitmap307.png": "20240118/1705548024663_449255.png",
    "bitmap309.png": "20240118/1705548024707_471976.png",
    "bitmap311.png": "20240118/1705548024647_137567.png",
    "bitmap313.png": "20240118/1705548024673_921804.png",
    "bitmap315.png": "20240118/1705548024658_497176.png",
    "bitmap317.png": "20240118/1705548024602_005710.png",
    "bitmap59.png": "20240118/1705548024586_768527.png",
    "bitmap61.png": "20240118/1705548024657_447434.png",
    "bitmap63.png": "20240118/1705548024678_646847.png",
    "bitmap65.png": "20240118/1705548024616_328594.png",
    "bitmap67.png": "20240118/1705548024699_679360.png",
    "bitmap69.png": "20240118/1705548024585_054506.png",
    "bitmap71.png": "20240118/1705548024683_837600.png",
    "bitmap73.png": "20240118/1705548024703_697897.png",
    "bitmap75.png": "20240118/1705548024615_697507.png",
    "bitmap77.png": "20240118/1705548024692_427541.png",
    "bitmap79.png": "20240118/1705548024654_078470.png",
    "bitmap81.png": "20240118/1705548024713_454436.png",
    "bitmap83.png": "20240118/1705548024630_345711.png",
    "bitmap830.png": "20240118/1705548024615_176500.png",
    "bitmap832.png": "20240118/1705548024633_732782.png",
    "bitmap834.png": "20240118/1705548024710_133956.png",
    "bitmap836.png": "20240118/1705548024702_843913.png",
    "bitmap838.png": "20240118/1705548024671_295787.png",
    "bitmap840.png": "20240118/1705548024709_549125.png",
    "bitmap842.png": "20240118/1705548024606_854707.png",
    "bitmap844.png": "20240118/1705548024661_709621.png",
    "bitmap846.png": "20240118/1705548024715_846112.png",
    "bitmap848.png": "20240118/1705548024705_342680.png",
    "bitmap85.png": "20240118/1705548024680_281755.png",
    "bitmap850.png": "20240118/1705548024672_125466.png",
    "bitmap852.png": "20240118/1705548024698_899888.png",
    "bitmap854.png": "20240118/1705548024692_545270.png",
    "bitmap856.png": "20240118/1705548024700_192518.png",
    "bitmap858.png": "20240118/1705548024701_264224.png",
    "bitmap860.png": "20240118/1705548024678_826529.png",
    "bitmap862.png": "20240118/1705548024695_896558.png",
    "bitmap864.png": "20240118/1705548024689_729665.png",
    "bitmap866.png": "20240118/1705548024613_166304.png",
    "bitmap868.png": "20240118/1705548024706_785625.png",
    "bitmap87.png": "20240118/1705548024675_109253.png",
    "bitmap870.png": "20240118/1705548024663_729376.png",
    "bitmap872.png": "20240118/1705548024664_549352.png",
    "bitmap874.png": "20240118/1705548024684_946284.png",
    "bitmap876.png": "20240118/1705548024672_832619.png",
    "bitmap878.png": "20240118/1705548024699_313286.png",
    "bitmap880.png": "20240118/1705548024661_700508.png",
    "bitmap882.png": "20240118/1705548024706_238478.png",
    "bitmap884.png": "20240118/1705548024696_158299.png",
    "bitmap886.png": "20240118/1705548024708_653798.png",
    "bitmap888.png": "20240118/1705548024702_428842.png",
    "bitmap89.png": "20240118/1705548024706_844530.png",
    "bitmap890.png": "20240118/1705548024694_880494.png",
    "bitmap892.png": "20240118/1705548024696_814249.png",
    "bitmap894.png": "20240118/1705548024698_861418.png",
    "bitmap896.png": "20240118/1705548024680_420455.png",
    "bitmap898.png": "20240118/1705548024700_120750.png",
    "bitmap900.png": "20240118/1705548024705_284710.png",
    "bitmap902.png": "20240118/1705548024711_626578.png",
    "bitmap904.png": "20240118/1705548024700_452434.png",
    "bitmap906.png": "20240118/1705548024697_597171.png",
    "bitmap908.png": "20240118/1705548024713_608258.png",
    "bitmap91.png": "20240118/1705548024701_045882.png",
    "bitmap910.png": "20240118/1705548024716_226154.png",
    "bitmap912.png": "20240118/1705548024712_463565.png",
    "bitmap914.png": "20240118/1705548024696_032463.png",
    "bitmap916.png": "20240118/1705548024697_161114.png",
    "bitmap918.png": "20240118/1705548024662_754431.png",
    "bitmap920.png": "20240118/1705548024706_481774.png",
    "bitmap922.png": "20240118/1705548024663_910014.png",
    "bitmap924.png": "20240118/1705548024708_315974.png",
    "bitmap926.png": "20240118/1705548024705_796534.png",
    "bitmap928.png": "20240118/1705548024713_043760.png",
    "bitmap93.png": "20240118/1705548024711_251399.png",
    "bitmap930.png": "20240118/1705548024693_603806.png",
    "bitmap932.png": "20240118/1705548024693_407651.png",
    "bitmap934.png": "20240118/1705548024697_965108.png",
    "bitmap936.png": "20240118/1705548024710_377395.png",
    "bitmap938.png": "20240118/1705548024713_563634.png",
    "bitmap940.png": "20240118/1705548024691_142758.png",
    "bitmap942.png": "20240118/1705548024694_985709.png",
    "bitmap944.png": "20240118/1705548024708_465387.png",
    "bitmap946.png": "20240118/1705548024714_267290.png",
    "bitmap948.png": "20240118/1705548024716_788279.png",
    "bitmap95.png": "20240118/1705548024706_109658.png",
    "bitmap950.png": "20240118/1705548024716_406653.png",
    "bitmap952.png": "20240118/1705548024703_369717.png",
    "bitmap954.png": "20240118/1705548024680_519458.png",
    "bitmap956.png": "20240118/1705548024683_309363.png",
    "bitmap958.png": "20240118/1705548024714_043463.png",
    "bitmap960.png": "20240118/1705548024709_476872.png",
    "bitmap962.png": "20240118/1705548024708_671903.png",
    "bitmap964.png": "20240118/1705548024677_086832.png",
    "bitmap966.png": "20240118/1705548024683_283880.png",
    "bitmap968.png": "20240118/1705548024679_793296.png",
    "bitmap97.png": "20240118/1705548024678_688161.png",
    "bitmap970.png": "20240118/1705548024694_809585.png",
    "bitmap972.png": "20240118/1705548024709_447826.png",
    "bitmap974.png": "20240118/1705548024704_557483.png",
    "bitmap976.png": "20240118/1705548024711_884799.png",
    "bitmap978.png": "20240118/1705548024711_914677.png",
    "bitmap980.png": "20240118/1705548024713_565587.png",
    "bitmap982.png": "20240118/1705548024663_879930.png",
    "bitmap984.png": "20240118/1705548024700_456740.png",
    "bitmap986.png": "20240118/1705548024708_306359.png",
    "bitmap988.png": "20240118/1705548024627_801112.png",
    "bitmap99.png": "20240118/1705548024703_499620.png",
    "bitmap990.png": "20240118/1705548024696_887183.png",
    "bitmap992.png": "20240118/1705548024693_362502.png",
    "bitmap994.png": "20240118/1705548024714_551058.png",
    "bitmap996.png": "20240118/1705548024701_416342.png",
    "bitmap998.png": "20240118/1705548024714_491721.png",
    "bitmap1133.png": "20240119/1705631797979_346026.png",
    "bitmap1136.png": "20240119/1705631797988_776617.png",
    "bitmap1138.png": "20240119/1705631797989_904591.png",
    "bitmap1140.png": "20240119/1705631797981_311571.png",
    "bitmap1142.png": "20240119/1705631797988_342546.png",
    "bitmap1144.png": "20240119/1705631797990_637533.png",
    "bitmap1146.png": "20240119/1705631797987_093592.png",
    "bitmap1148.png": "20240119/1705631797981_689536.png"
}

frames1 = [
    "bitmap99.png",
    "bitmap101.png",
    "bitmap103.png",
    "bitmap105.png",
    "bitmap107.png",
    "bitmap109.png",
    "bitmap111.png",
    "bitmap59.png",
    "bitmap61.png",
    "bitmap830.png",
    "bitmap832.png",
    "bitmap834.png",
    "bitmap836.png",
    "bitmap838.png",
    "bitmap840.png",
    "bitmap842.png",
    "bitmap844.png",
    "bitmap846.png",
    "bitmap848.png",
    "bitmap850.png",
    "bitmap852.png",
    "bitmap854.png",
    "bitmap856.png",
    "bitmap858.png",
    "bitmap860.png",
    "bitmap862.png",
    "bitmap864.png",
    "bitmap866.png",
    "bitmap868.png",
    "bitmap870.png",
    "bitmap872.png",
    "bitmap874.png",
    "bitmap876.png",
    "bitmap878.png",
    "bitmap880.png",
    "bitmap882.png",
    "bitmap884.png",
    "bitmap886.png",
    "bitmap888.png",
    "bitmap890.png",
    "bitmap892.png",
    "bitmap894.png",
    "bitmap896.png",
    "bitmap898.png",
    "bitmap900.png",
    "bitmap902.png",
    "bitmap904.png",
    "bitmap906.png",
    "bitmap908.png",
    "bitmap910.png",
    "bitmap912.png",
    "bitmap914.png",
    "bitmap916.png",
    "bitmap918.png",
    "bitmap920.png",
    "bitmap922.png",
    "bitmap924.png",
    "bitmap926.png",
    "bitmap928.png",
    "bitmap930.png",
    "bitmap932.png",
    "bitmap934.png",
    "bitmap936.png",
    "bitmap938.png",
    "bitmap940.png",
    "bitmap942.png",
    "bitmap944.png",
    "bitmap946.png",
    "bitmap948.png",
    "bitmap950.png",
    "bitmap952.png",
    "bitmap954.png",
    "bitmap956.png",
    "bitmap958.png",
    "bitmap960.png",
    "bitmap962.png",
    "bitmap964.png",
    "bitmap966.png",
    "bitmap968.png",
    "bitmap970.png",
    "bitmap81.png",
    "bitmap83.png",
    "bitmap85.png",
    "bitmap87.png",
    "bitmap89.png",
    "bitmap91.png",
    "bitmap93.png",
    "bitmap95.png",
    "bitmap97.png",
    "bitmap972.png",
    "bitmap63.png",
    "bitmap65.png",
    "bitmap67.png",
    "bitmap69.png",
    "bitmap71.png",
    "bitmap73.png",
    "bitmap75.png",
    "bitmap77.png",
    "bitmap79.png",
    "bitmap974.png",
    "bitmap976.png",
    "bitmap978.png",
    "bitmap980.png",
    "bitmap982.png",
    "bitmap984.png",
    "bitmap986.png",
    "bitmap988.png",
    "bitmap990.png",
    "bitmap992.png",
    "bitmap994.png",
    "bitmap996.png",
    "bitmap998.png",
    "bitmap1000.png",
    "bitmap1002.png",
    "bitmap1004.png",
    "bitmap1006.png",
    "bitmap1008.png",
    "bitmap1010.png",
    "bitmap1012.png",
    "bitmap1014.png",
    "bitmap1016.png",
    "bitmap1133.png",
    "bitmap1136.png",
    "bitmap1138.png",
    "bitmap1140.png",
    "bitmap1142.png",
    "bitmap1144.png",
    "bitmap1146.png",
    "bitmap1148.png"
]

frames2 = [
    "bitmap266.png",
    "bitmap270.png",
    "bitmap272.png",
    "bitmap292.png",
    "bitmap294.png",
    "bitmap297.png",
    "bitmap315.png",
    "bitmap317.png",
    "bitmap274.png",
    "bitmap276.png",
    "bitmap278.png",
    "bitmap280.png",
    "bitmap282.png",
    "bitmap285.png",
    "bitmap287.png",
    "bitmap289.png",
    "bitmap299.png",
    "bitmap301.png",
    "bitmap303.png",
    "bitmap305.png",
    "bitmap307.png",
    "bitmap309.png",
    "bitmap311.png",
    "bitmap313.png"
]

levels = [
    [
        "               ",
        "               ",
        "  bbb          ",
        "  bbbbbb       ",
        "  bbbbbbbbb    ",
        "   bbbbbbbbb   ",
        "       bbebb   ",
        "        bbb    ",
        "               ",
        "               ",
        [3, 3]
    ],
    [
        "               ",
        "      bbbb  bbb",
        "bbbb  bbhb  beb",
        "bbsb  bbbb  bbb",
        "bbbb  bbbb  bbb",
        "bbbblrbbbblrbbb",
        "bbbb  bbbb     ",
        "               ",
        "               ",
        "               ",
        [1, 5],
        {
            "swatch23": [
                [4, 5, "onoff"],
                [5, 5,"onoff"]
            ],
            "swatch82": [
                [10, 5, "onoff"],
                [11, 5, "onoff"]
            ]
        }
    ],
    [
        "               ",
        "               ",
        "      bbbbbbb  ",
        "bbbb  bbb  bb  ",
        "bbbbbbbbb  bbbb",
        "bbbb       bbeb",
        "bbbb        bbb",
        "               ",
        "               ",
        "               ",
        [1, 5],
        {}
    ],
    [
        "               ",
        "   fffffff     ",
        "   fffffff     ",
        "bbbb     bbb   ",
        "bbb       bb   ",
        "bbb       bb   ",
        "bbb  bbbbfffff ",
        "bbb  bbbbfffff ",
        "     beb  ffbf ",
        "     bbb  ffff ",
        [1, 6],
        {}
    ],
    [
        "           bbbb",
        " bbbbkqbsbbbbbb",
        " bbbb       bbb",
        " bbsb          ",
        " bbbb          ",
        "   bbbsbkqbbb  ",
        "          bbbbs",
        "bbb       bbbbb",
        "bebbbkqbbbbbb  ",
        "bbbb           ",
        [13, 1],
        {
            "swatch81": [
                [6, 1, "onoff"],
                [5, 1, "onoff"]
            ],
            "swatch65": [
                [5, 8, "off"],
                [6, 8, "off"]
            ],
            "swatch33": [
                [5, 8, "on"],
                [6, 8, "on"]
            ],
            "swatch146": [
                [5, 8, "onoff"],
                [6, 8, "onoff"]
            ]
        }
    ],
    [
        "     bbbbbb    ",
        "     b  bbb    ",
        "     b  bbbbb  ",
        "bbbbbb     bbbb",
        "    bbb    bbeb",
        "    bbb     bbb",
        "      b  bb    ",
        "      bbbbb    ",
        "      bbbbb    ",
        "       bbb     ",
        [0, 3],
        {}
    ],
    [
        "               ",
        "        bbbb   ",
        "        bbbb   ",
        "bbb     b  bbbb",
        "bbbbbbbbb   beb",
        "bbb    bbh  bbb",
        "bbb    bbb  bbb",
        " bbl   b       ",
        "  bbbbbb       ",
        "               ",
        [1, 4],
        {
            "swatch95": [
                [3, 7, "onoff"]
            ]
        }
    ],
    [
        "         bbb   ",
        "         bbb   ",
        "         bbb   ",
        "bbbbbb   bbbbbb",
        "bbbbvb   bbbbeb",
        "bbbbbb   bbbbbb",
        "         bbb   ",
        "         bbb   ",
        "         bbb   ",
        "               ",
        [1, 4],
        {},
        {
            "swatch44": [10, 1, 10, 7]
        }
    ],
    [
        "               ",
        "               ",
        "               ",
        "bbbb   b   bbbb",
        "bbbb   b   bbvb",
        "bbbbbbbbbbbbbbb",
        "      beb      ",
        "      bbb      ",
        "               ",
        "               ",
        [1, 4],
        {},
        {
            "swatch134": [12, 4, 2, 4]
        }
    ],
    [
        " bbb     bbbbbb",
        " beblrblrbbbbvb",
        " bbb     bbbbl ",
        "          bbbl ",
        "            bb ",
        "             b ",
        "             b ",
        "            bb ",
        "     bbbbb  bb ",
        "     bs  bbbhb ",
        [10, 1],
        {
            "swatch129": [
                [7, 1, "onoff"],
                [8, 1, "onoff"],
                [13, 2, "onoff"],
                [13, 3, "onoff"]
            ],
            "swatch69": [
                [4, 1, "onoff"],
                [5, 1, "onoff"]
            ]
        },
        {
            "swatch131": [13,1,10,1]
        }
    ],
    [
        "   bbbk        ",
        "   bebk        ",
        "   bbb         ",
        "   b   bbbbbb  ",
        "   b   bb  bb  ",
        "  bbbbbbb  bbb ",
        "       bs    b ",
        "       bbbb  b ",
        "       bbbbbbb ",
        "          bbb  ",
        [2, 5],
        {
            "swatch86": [
                [6, 0, "off"],
                [6, 1, "off"]
            ]
        }
    ],
    [
        "             h ",
        "      bbb  bbb ",
        "      bhbbbbbl ",
        "    bbbbb  bb  ",
        "    bebl   bb  ",
        "  bbbbb   bbbb ",
        " bbbb     bbbb ",
        " bbbb  bbbbb   ",
        "      bbb      ",
        "      bbb      ",
        [3, 6],
        {
            "swatch72": [
                [13, 2, "onoff"]
            ],
            "swatch130": [
                [7, 4, "onoff"]
            ]
        }
    ],
    [
        " bbbfbbbbfbbbb ",
        " bb        bbb ",
        " bb         bbb",
        " bbb   bbb  bbb",
        " bbbfffbeb  bbb",
        " bbb  fbbb  b  ",
        "   b  fffffbb  ",
        "   bbbffbfff   ",
        "    bbffffff   ",
        "    bbb  bb    ",
        [13, 3],
        {}
    ],
    [
        "        bbb    ",
        "   bbb  bbb    ",
        "blrbbbbbbbbbbb ",
        "blrbbb      hb ",
        "b           bb ",
        "b           bb ",
        "b       bbbbbb ",
        "bbbbb   bbb    ",
        " bbeb   bbb    ",
        "  bbb   bbbbbh ",
        [4, 2],
        {
            "swatch123": [
                [1, 2, "onoff"],
                [2, 2, "onoff"]
            ],
            "swatch139": [
                [1, 3, "onoff"],
                [2, 3, "onoff"]
            ]
        }
    ],
    [
        "       bbb  bbb",
        "    bkqbbblrhbb",
        "bblrb  bbb  bbb",
        "bbbbb   s      ",
        "bb             ",
        " b     v       ",
        " b     b       ",
        "bbb   bbb  sbb ",
        "bbbbbbbbbkqbeb ",
        "bbb   bbb  sbb ",
        [1, 8],
        {
            "swatch121": [
                [2, 2, "onoff"],
                [3, 2, "onoff"],
                [5, 1, "onoff"],
                [6, 1, "onoff"]
            ],
            "swatch83": [
                [5, 1, "onoff"],
                [6, 1, "onoff"],
                [10, 1, "onoff"],
                [11, 1, "onoff"]
            ],
            "swatch117": [
                [9, 8, "off"],
                [10, 8, "off"]
            ],
            "swatch119": [
                [9, 8, "off"],
                [10, 8, "off"]
            ]
        },
        {
            "swatch75": [13, 1, 1, 8
            ]
        }
    ],
    [
        "               ",
        "               ",
        " v        bbb  ",
        "vbvlrhhblrbeb  ",
        " v        bbb  ",
        "               ",
        "               ",
        "  bbb   bbb    ",
        "  bbbbbbbvb    ",
        "  bbb   bbb    ",
        [3, 8],
        {
            "swatch53": [
                [3, 3, "on"],
                [4, 3, "on"],
            ],
            "swatch63": [
                [8, 3, "on"],
                [9, 3, "on"],
            ]
        },
        {
            "swatch98": [1, 2, 0, 3],
            "swatch12": [7, 3, 5, 3],
            "swatch03": [2, 3, 1, 2],
            "swatch23": [0, 3, 2, 3],
            "swatch14": [1, 4, 0, 3
            ]
        }
    ],
    [
        "bbb            ",
        "bbbbbbbbbl  bbb",
        "bbb    rbbbbbeb",
        "bbb         hhb",
        "bbb            ",
        "bbb            ",
        "bbb   rbbbbbh  ",
        "bbbbbbbbl  bb  ",
        "bsb        bb  ",
        "bbb        bh  ",
        [1, 1],
        {
            "swatch18": [
                [8, 7, "onoff"]
            ],
            "swatch126": [
                [7, 2, "on"],
            ],
            "swatch129": [
                [9, 1, "on"],
                [8, 7, "off"]
            ],
            "swatch123": [
                [6, 6, "off"]
            ],
            "swatch133": [
                [6, 6, "on"],
            ]
        }
    ],
    [
        "               ",
        "       s       ",
        "bbsb   b       ",
        "bbbbb  b       ",
        "bsbbbbbblrbblrb",
        "bbbbbl  b   b  ",
        "bbsb    b   b  ",
        "b       s  bbb ",
        "b         bbeb ",
        "blrh      bbbb ",
        [2, 4],
        {
            "swatch14": [
                [8, 4, "off"],
                [9, 4, "off"]
            ],
            "swatch71": [
                [8, 4, "on"],
                [9, 4, "on"],
            ],
            "swatch22": [
                [12, 4, "off"],
                [13, 4, "off"],
                [1, 9, "off"],
                [2, 9, "off"]
            ],
            "swatch26": [
                [12, 4, "off"],
                [13, 4, "off"],
                [1, 9, "off"],
                [2, 9, "off"]
            ],
            "swatch39": [
                [5, 5, "onoff"]
            ],
            "swatch87": [
                [12, 4, "on"],
                [13, 4, "on"],
                [1, 9, "on"],
                [2, 9, "on"],
            ]
        }
    ],
    [
        " bbbbbbbbbsbbbb",
        "     bb      bb",
        "     bb      bb",
        "             bb",
        "             bb",
        "bbb  bblrbsbbbb",
        "beb  bb        ",
        "bbb  bb        ",
        " bb  bb        ",
        " bkqbbbbbbsbbb ",
        [1, 0],
        {
            "swatch100": [
                [7, 5, "onoff"],
                [8, 5, "onoff"]
            ],
            "swatch105": [
                [2, 9, "off"],
                [3, 9, "off"]
            ],
            "swatch109": [
                [2, 9, "on"],
                [3, 9, "on"],
            ]
        }
    ],
    [
        "            bbb",
        "  bbbkqbbblrbbb",
        "  bbb  sbb  bbb",
        "  bbb  bbb     ",
        "  bsb  vbs     ",
        "  bbb  bbb     ",
        "bbbb   bbblrsbb",
        "bs          bbb",
        "            beb",
        "            bbb",
        [8, 2],
        {
            "swatch72": [
                [5, 1, "off"],
                [6, 1, "off"]
            ],
            "swatch94": [
                [5, 1, "off"],
                [6, 1, "off"]
            ],
            "swatch34": [
                [5, 1, "off"],
                [6, 1, "off"]
            ],
            "swatch126": [
                [10, 6, "onoff"],
                [11, 6, "onoff"]
            ],
            "swatch17": [
                [10, 1, "onoff"],
                [11, 1, "onoff"]
            ]
        },
        {
            "swatch74": [13, 1, 13, 7
            ]
        }
    ],
    [
        "        bb     ",
        "       bbb     ",
        "bb  bbbbbb     ",
        "bbbbbb  b      ",
        "bbbb    b   bbb",
        " bb     hbbbbeb",
        "  b     hb  bbb",
        "  bbbl  bb     ",
        "   bbb  bb     ",
        "   rbbbbbb     ",
        [1, 3],
        {
            "swatch85": [
                [3, 9, "onoff"]
            ],
            "swatch86": [
                [5, 7, "onoff"]
            ]
        }
    ],
    [
        "      bb    bbb",
        "    bbbbbb  beb",
        " bbbbbbsbbbbbbb",
        " bbbbs  bbbbbl ",
        " bbb      bbb  ",
        "  b        b   ",
        "  b        b   ",
        "  bl      qb   ",
        "  bb      bb   ",
        "   h      h    ",
        [2, 3],
        {
            "swatch109": [
                [3, 7, "onoff"]
            ],
            "swatch39": [
                [13, 3, "onoff"]
            ],
            "swatch53": [
                [3, 7, "off"],
                [13, 3, "off"]
            ],
            "swatch72": [
                [3, 7, "off"],
                [13, 3, "off"]
            ]
        }
    ],
    [
        " bbb        bbb",
        " bhb        bsb",
        " bbb   bbbkqbbb",
        "rbbbl  beb  bbs",
        "b   b  bbb    b",
        "s   b  fff    b",
        "blrbbbfffffbbbk",
        "   bbbfffffbvb ",
        "   bbbfffffbbb ",
        "   bbbbbl      ",
        [4, 7],
        {
            "swatch143": [
                [14, 6, "off"],
                [10, 2, "off"],
                [11, 2, "off"]
            ],
            "swatch131": [
                [8, 9, "onoff"],
                [1, 6, "on"],
                [2, 6, "on"],
            ],
            "swatch05": [
                [0, 3, "on"],
                [1, 6, "off"],
                [2, 6, "off"]
            ],
            "swatch21": [
                [4, 3, "on"],
            ]
        },
        {
            "swatch127": [12, 7, 2, 2
            ]
        }
    ],
    [
        "               ",
        "           bbbb",
        "    rbbbbbbbhbv",
        "  blrbhb   bbbb",
        " hb  bb      b ",
        " bb  b       b ",
        " bbbbb     bbb ",
        " bbb  bbblrbeb ",
        "      hbl  bbb ",
        "               ",
        [2, 3],
        {
            "swatch14": [
                [4, 2, "on"],
            ],
            "swatch122": [
                [4, 3, "on"],
                [3, 3, "on"],
            ],
            "swatch63": [
                [8, 8, "on"],
            ],
            "swatch68": [
                [9, 7, "on"],
                [10, 7, "on"],
            ]
        },
        {
            "swatch142": [6, 7, 8, 7
            ]
        }
    ],
    [
        "  bb           ",
        "  bbb          ",
        "  bbs     bbbl ",
        "   bbbbl  bebl ",
        "      bblrbbb  ",
        " bb   bb       ",
        "bbhbkqbb       ",
        "bbk   bb   bbb ",
        "bbk   bbsbbbbb ",
        "           bbb ",
        [1, 7],
        {
            "swatch42": [
                [13, 2, "onoff"],
                [13, 3, "onoff"],
                [8, 4, "onoff"],
                [9, 4, "onoff"]
            ],
            "swatch88": [
                [7, 3, "on"],
                [4, 6, "off"],
                [5, 6, "off"]
            ],
            "swatch26": [
                [8, 4, "on"],
                [9, 4, "on"],
            ]
        }
    ],
    [
        "     bbbb    v ",
        "     bbsbbb  b ",
        "    bbbbbbb  b ",
        "bbkqbbbb  bbbb ",
        "bbbl  b   bb   ",
        "bbb   b   b    ",
        " b    bbb      ",
        " h    bebl     ",
        "      bbb      ",
        "               ",
        [10, 5],
        {
            "swatch71": [
                [2, 3, "off"],
                [3, 3, "off"]
            ],
            "swatch17": [
                [9, 7, "on"],
                [3, 4, "on"],
            ]
        },
        {
            "swatch130": [12, 3, 10, 5
            ]
        }
    ],
    [
        "bbb    bbbbbbbb",
        "bbbbbbbbbbb  bb",
        "bbb    bb    bb",
        "            bhb",
        "            bb ",
        "bbb  ffffb  ss ",
        "bebfffffff  bbb",
        "bbbfffffffffbbb",
        "     fffffffbbb",
        "      qbbk     ",
        [1, 1],
        {
            "swatch125": [
                [6, 9, "off"]
            ],
            "swatch135": [
                [9, 9, "off"]
            ],
            "swatch133": [
                [6, 9, "off"],
                [9, 9, "off"]
            ]
        }
    ],
    [
        " bbkqbb        ",
        " bb  bbb       ",
        "ffb  bbbb      ",
        "ff     bbb     ",
        "ff      bbb    ",
        "fbbb     bbv   ",
        " beb      bbbbb",
        " bbbbbb   bsbbb",
        "  b  bb   bbb  ",
        "  b  bbbkqbbb  ",
        [2, 2],
        {
            "swatch117": [
                [4, 0, "off"],
                [3, 0, "off"],
                [8, 9, "off"],
                [9, 9, "off"]
            ]
        },
        {
            "swatch115": [14, 6, 12, 9
            ]
        }
    ],
    [
        "  skqb   blrh  ",
        "     b   b     ",
        "     bbbbb     ",
        "hlrbbbbbbbbblrh",
        "     bbbbb     ",
        "     rb  b     ",
        "     rb  bkqs  ",
        "bbb  bb  b     ",
        "beblrb   b     ",
        "bbbl     bkqs  ",
        [7, 3],
        {
            "swatch20": [
                [10, 0, "on"],
                [11, 0, "on"],
                [10, 6, "off"],
                [11, 6, "off"]
            ],
            "swatch120": [
                [5, 5, "on"],
                [5, 6, "on"],
            ],
            "swatch03": [
                [3, 8, "on"],
                [4, 8, "on"],
                [10, 9, "off"],
                [11, 9, "off"]
            ],
            "swatch143": [
                [3, 9, "on"],
            ],
            "swatch126": [
                [1, 3, "on"],
                [2, 3, "on"],
            ],
            "swatch129": [
                [12, 3, "on"],
                [13, 3, "on"],
                [10, 6, "off"],
                [11, 6, "off"],
                [3, 0, "off"],
                [4, 0, "off"],
                [10, 0, "off"],
                [11, 0, "off"]
            ]
        }
    ],
    [
        "   bbbbbffbbbb ",
        "   bebb     fb ",
        "   bbb      fbh",
        "       fbbkqbbb",
        "  b    ff     b",
        " hbf   ff     b",
        "ffff   bbl  rbb",
        "fffbfbffbf  hbl",
        "bfffffffffffb  ",
        " fbfff  ffffb  ",
        [2, 4],
        {
            "swatch15": [
                [10, 3, "on"],
                [11, 3, "on"],
            ],
            "swatch142": [
                [10, 3, "off"],
                [11, 3, "off"],
                [9, 6, "on"],
                [12, 6, "on"],
            ],
            "swatch127": [
                [14, 7, "onoff"]
            ]
        }
    ],
    [
        "           bbbl",
        " bbb    h  bebl",
        " bbbkqbbblrbbbl",
        " bbb  bbb   b  ",
        " fff  sbb   f  ",
        "  f   bbb  fff ",
        "  b   bbb  bbb ",
        "qbbblrbsbkqbbb ",
        "qbhb  h    bbb ",
        "qbbb           ",
        [12, 7],
        {
            "swatch81": [
                [9, 2, "onoff"],
                [10, 2, "onoff"]
            ],
            "swatch68": [
                [4, 7, "onoff"],
                [5, 7, "onoff"]
            ],
            "swatch28": [
                [14, 2, "on"],
                [14, 1, "on"],
                [14, 0, "on"],
                [4, 2, "off"],
                [5, 2, "off"]
            ],
            "swatch77": [
                [4, 2, "off"],
                [5, 2, "off"],
                [9, 2, "off"],
                [10, 2, "off"],
                [4, 7, "off"],
                [5, 7, "off"],
                [9, 7, "off"],
                [10, 7, "off"]
            ],
            "swatch64": [
                [4, 2, "off"],
                [5, 2, "off"],
                [9, 2, "off"],
                [10, 2, "off"],
                [4, 7, "off"],
                [5, 7, "off"],
                [9, 7, "off"],
                [10, 7, "off"]
            ]
        }
    ],
    [
        "             bh",
        "   bbkqbb   bbb",
        "  bbblrbb  bhbb",
        "  beb   bbbbb  ",
        "  bbb    bbb   ",
        "          bb   ",
        "     bbb  bb   ",
        " bblrbhb  bb   ",
        " bblrbbbbbbb   ",
        "               ",
        [11, 6],
        {
            "swatch140": [
                [3, 7, "onoff"],
                [4, 7, "onoff"],
                [5, 1, "onoff"],
                [6, 1, "onoff"]
            ],
            "swatch122": [
                [3, 8, "onoff"],
                [4, 8, "onoff"]
            ],
            "swatch67": [
                [5, 2, "onoff"],
                [6, 2, "onoff"]
            ]
        }
    ],
    [
        "     bbsbbb    ",
        "     bbbbbbl   ",
        "bbb  sbbsbbbbb ",
        "bbbkqbbbbssbbs ",
        "     bbsbbsbbb ",
        "     bbbbbbsbb ",
        "bbb  bbbbbbsbbb",
        "bebkqbsb  bbbsh",
        "bbb  bbb   bbbb",
        "bbb         bbb",
        [1, 3],
        {
            "swatch147": [
                [11, 1, "on"],
            ],
            "swatch70": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch52": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch82": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch93": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch103": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch104": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch115": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch133": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch116": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch137": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch74": [
                [3, 7, "off"],
                [4, 7, "off"]
            ],
            "swatch67": [
                [3, 7, "off"],
                [4, 7, "off"]
            ]
        }
    ]
]

from xdf import *
import math

class Sprite:
    def __init__(self, dis):
        self.id = 0
        self.x = 0
        self.y = 0
        self.w = 1
        self.h = 1
        self.visible = True
        self.dis = dis
    
    def front(self):
        self.dis.front()
        
    def move(self, x, y):
        self.x = x
        self.y = y
    
    def change(self, value):
        self.dis.change(value)
    
    def update(self):
        self.dis.move(self.x, self.y)
        if self.visible:
            self.dis.show()
        else:
            self.dis.hide()


class SpriteSheet(Sprite):
    def __init__(self, arr, config):
        self.isPlaying = True
        self.isFlag = False
        self.currentFrame = 0
        self.totalFrames = len(arr)
        self.stamps = []
        self.config = config
        self.flipped = False
        self.flipArr = []
        self.reverse = False
        self.loop = True
        self.lastFrame = self.currentFrame
        for i in range(len(arr)):
            sp = stamp(arr[i])
            self.stamps.append(sp)
            sp.hide()
            self.flipArr.append(False)
        Sprite.__init__(self, self.stamps[0])
    
    def play(self):
        self.isPlaying = True
    
    def stop(self):
        self.isPlaying = False
    
    def gotoAndStop(self, n):
        self.currentFrame = n;
        self.stop()
    
    def gotoAndPlay(self, n):
        self.currentFrame = n;
        self.play()
        
    def prevFrame(self):
        self.currentFrame = self.currentFrame - 1
        if self.currentFrame < self.startFrame:
            if self.loop:
                self.currentFrame = self.endFrame
            else:
                self.currentFrame = self.startFrame
                self.stop()

    def nextFrame(self):
        self.currentFrame = self.currentFrame + 1
        if self.currentFrame > self.endFrame:
            if self.loop:
                self.currentFrame = self.startFrame
            else:
                self.currentFrame = self.endFrame
                self.stop()
    @property
    def startFrame(self):
        if self.isFlag:
            return self.flagStart
        return 0
    @property
    def endFrame(self):
        if self.isFlag:
            return self.flagEnd
        return self.totalFrames - 1
    
    def playFlag(self, flag, reverse = False):
        if flag in self.config:
            a = self.config[flag]
            self.flagStart = a[0]
            self.flagEnd = a[1]
            self.isFlag = True
            self.reverse = reverse
            if reverse:
                self.gotoAndPlay(self.flagEnd)
            else:
                self.gotoAndPlay(self.flagStart);
    
    def clearPlayFlag(self):
        self.isFlag = False
    
    def update(self):
        if self.isPlaying:
            if self.reverse:
                self.prevFrame()
            else:
                self.nextFrame()
        for stm in self.stamps:
            stm.hide()
        self.dis = self.stamps[self.currentFrame]
        if self.flipped != self.flipArr[self.currentFrame]:
            self.flipArr[self.currentFrame] = self.flipped
            self.dis.flip()
        super().update()
        if self.lastFrame != self.currentFrame:
            if self.currentFrame == (self.startFrame if self.reverse else self.endFrame):
                self.onPlayEnd()
        self.lastFrame = self.currentFrame
    
    def onPlayEnd(self):
        pass
blockConfig = {
    "0": [0, 9],
    "1": [10, 19],
    "2": [20, 29],
    "3": [30, 39],
    "4": [40, 49],
    "5": [50, 59],
    "6": [60, 69],
    "7": [70, 79],
    "8": [80, 89],
    "9": [90, 99],
    "10": [100, 109],
    "11": [110, 120],
    "12": [121, 128]
}
class Block(SpriteSheet):
    def __init__(self):
        SpriteSheet.__init__(self, list(map(mapAssetUrl, frames1)), blockConfig)
        self.curState = 7
        self.tarState = 0
        self.isAnim = False
        self.loop = False
        self.reset()
        self.I = 0
        self.J = 0
        self.drop = False
        self.v = 0
        self.states = [
            # x y, w, h, tx, ty, tw, th, left, up, right, down
            [0, -1, 1, 1, -2, -1, 2, 1, 8, 9, 10, 11],
            [0, -1, 1, 1, 0, -3, 1, 2, 4, 5, 6, 7],
            [0, -1, 1, 1, 1, -1, 2, 1, 8, 9, 10, 11],
            [0, -1, 1, 1, 0, 0, 1, 2, 4, 5, 6, 7],
            
            [0, -2, 1, 2, -1, -2, 1, 2, 4, 5, 6, 7],
            [0, -2, 1, 2, 0, -3, 1, 1, 0, 1, 2, 3],
            [0, -2, 1, 2, 1, -2, 1, 2, 4, 5, 6, 7],
            [0, -2, 1, 2, 0, 0, 1, 1, 0, 1, 2, 3],
            
            [0, -1, 2, 1, -1, -1, 1, 1, 0, 1, 2, 3],
            [0, -1, 2, 1, 0, -2, 2, 1, 8, 9, 10, 11],
            [0, -1, 2, 1, 2, -1, 1, 1, 0, 1, 2, 3],
            [0, -1, 2, 1, 0, 0, 2, 1, 8, 9, 10, 11],
            
            [0, -1, 1, 1, 0, -1, 1, 1, 4, 5, 6, 7]
        ]
        
    def playDir(self, dr):
        if self.isAnim or dr < 0 or dr > 3:
            return
        self.playState(self.states[self.curState][dr + 8])
        
    def playState(self, state):
        # print("play state:", state)
        self.isAnim = True
        self.tarState = state
        self.playFlag(str(self.tarState))
        a1 = self.states[self.curState]
        a2 = self.states[self.tarState]
        i = self.I + a1[4] - a2[0]
        j = self.J + a1[5] - a2[1]
        self.setPos(i, j)
        
    def update(self):
        super().update()
        if self.drop:
            self.v += 10
            self.y += self.v
            self.dis.back()
        else:
            self.dis.front()
        
    def onPlayEnd(self):
        #print("play end")
        self.isAnim = False
        self.curState = self.tarState
        if self.curState == 12:
            pos = [self.I, self.J]
            self.reset()
            self.setPos(pos[0], pos[1])
            self.drop = True
        else:
            checkGame()
        
    def getRect(self):
        a = self.states[self.curState][4:8]
        a[0] += self.I
        a[1] += self.J
        return a
    
    def setPos(self, i, j):
        self.I = i
        self.J = j
        xy = ij2xy(i, j)
        self.x = xy[0] + 9
        self.y = xy[1] - 40
        #print(i, j, xy, self.curState)
        
    def playSuccess(self):
        self.playState(12)
    
    def reset(self):
        self.v = 0
        self.drop = False
        self.curState = 7
        self.gotoAndStop(self.config['7'][1])
        
    def playLose(self, pos):
        if pos != None:
            self.reset()
            self.setPos(pos[0], pos[1])
        self.drop = True

tileConfig = {
    "b": [0, 0],
    "e": [5, 5],
    "s": [3, 3],
    "h": [4, 4],
    "f": [7, 7],
    "l": [8,15],
    "r": [16, 23],
    "k": [8, 15],
    "q": [16, 23]
}
class Tile(SpriteSheet):
    def __init__(self, i, j):
        SpriteSheet.__init__(self, list(map(mapAssetUrl, frames2)), tileConfig)
        self.stop()
        self.I = i
        self.J = j
        self.state = ''
        self.isOpen = False
        self.loop = False
        
    def updatePos(self):
        xy = ij2xy(self.I, self.J + 1)
        if self.state in 'lrkq':
            self.x = xy[0] - 91 + 100
            self.y = xy[1] - 115 + 75
        else:
            self.x = xy[0] - 15 + 24.5
            self.y = xy[1] - 25 + 16.5
        
    def setState(self, c):
        self.isOpen = False
        self.state = c
        if c == ' ':
            self.visible = False
        else:
            self.visible = True
            self.playFlag(c)
            self.stop()
        if self.state in "kq":
            self.setOpen(True)
        self.updatePos()
    
    def exeCommand(self, command):
        if command == "onoff":
            self.toggleOpen()
        elif command == "on":
            self.setOpen(True)
        elif command == "off":
            self.setOpen(False)
            
    def toggleOpen(self):
        self.setOpen(not self.isOpen)
            
    def setOpen(self, boo):
        if self.state in 'lrkq' and self.isOpen != boo:
            self.isOpen = boo
            self.playFlag(self.state,  not self.isOpen)
    
    def update(self):
        super().update()
    
    def isF(self):
        return self.state == 'f'
    
    def isSwitch(self):
        return self.state in "sh" 
    
    def isSwitch1(self):
        return self.state == "h"
    
    def isSwitch2(self):
        return self.state == "s"
    
    def isHole(self):
        return self.state == 'e'
    
    def isSpace(self):
        return self.state == ' ' or (self.state in 'lrkq' and not self.isOpen)
    
class TileMap:
    def __init__(self):
        self.level = 0
        self.data = levels[0]
        self.tiles = []
        for i in range(m):
            self.tiles.append([])
            for j in range(n):
                self.tiles[i].append(Tile(m - 1 - i, j))
    
    def nextLevel(self):
        setLevel(self.level + 1)
        
    def setLevel(self, level):
        self.level = min(level, len(levels) - 1)
        self.data = levels[self.level]
        for j in range(n):
            s = self.data[j]
            for i in range(m):
                self.getTile(i, j).setState(s[i])
        
    def update(self):
        for i in range(m):
            for j in range(n):
                self.tiles[i][j].update()
    
    def getTile(self, i, j):
        if i < 0 or i >= m or j < 0 or j >= n:
            return self.tiles[0][0]
        return self.tiles[m - 1 - i][j]
            
def mapAssetUrl(name):
    return "https://code-file.xdf.cn/files/dingdangweb/" + assets[name]

m = 15
n = 10
CW = [31, 10]
CH = [-5, 16]
OX = (768 - m * CW[0] - n * CW[1]) // 2
OY = (1024 - m * CH[0] - n * CH[1]) // 2
def ij2xy(i, j):
    return [OX + i * CW[0] + j * CW[1], OY + i * CH[0] + j * CH[1]]

def xy2ij(x, y):
    a = CW[0]
    b = CW[1]
    c = CH[0]
    d = CH[1]
    dx = x - OX
    dy = y - OY
    i = (c * dx - a * dy) / (b * c - a * d)
    j = (d * dx - b * dy) / (a * d - b * c)
    return [i, j]

#fill("bg37")
tileMap = TileMap()
block = Block()
block.stop()
levelText = text("第1关", 10, 100, 80, "red")
maxLevel = 6
    
def checkGame():
    rect = block.getRect()
    [x,y,w,h] = rect
    tiles = []
    for i in range(w):
        for j in range(h):
            tiles.append(tileMap.getTile(x + i, y + j))
    # check success
    if len(tiles) == 1 and tiles[0].isHole():
        block.playSuccess()
        delay(nextLevel, 3000)
        # print("success")
        return
    # check over
    over = False
    if len(tiles) == 1:
        if tiles[0].isSpace():
            block.playLose(None)
            over = True
        elif tiles[0].isF():
            block.playLose(None)
            tiles[0].visible = False
            over = True
    else:
        if tiles[0].isSpace() and tiles[1].isSpace():
            block.playLose(None)
            over = True
        elif tiles[0].isSpace():
            block.playLose([tiles[0].I, tiles[0].J])
            over = True
        elif tiles[1].isSpace():
            block.playLose([tiles[1].I, tiles[1].J])
            over = True
    if over:
        delay(resetLevel, 3000)
        # print("lose")
        return
    # check switch
    for tl in tiles:
        if tl.isSwitch2() or (tl.isSwitch1() and len(tiles) == 1):
            data = levels[tileMap.level]
            if len(data) > n + 1:
                swConf = data[n + 1]
                name = "swatch" + str(tl.I) + str(tl.J)
                a2 = swConf[name]
                for a in a2:
                    tl = tileMap.getTile(a[0], a[1])
                    tl.exeCommand(a[2])
            pass
    #pass

def nextLevel():
    if tileMap.level == len(levels) - 1:
        setLevel(0)
    else:
        setLevel(tileMap.level + 1)

def resetLevel():
    setLevel(tileMap.level)
    
def setLevel(level):
    level = min(maxLevel, level)
    tileMap.setLevel(level)
    data = levels[level]
    bp = data[n]
    block.reset()
    block.setPos(bp[0], bp[1])
    levelText.change("第"+ str(level+1)+"关")

def keydown(code, key):
    block.playDir(code - 37)

def loop():
    block.update()
    tileMap.update()

setLevel(0)



class MyKeyBoard:
    def __init__(self, x, y, w):
        hw = w / 2
        hhw = w * 0.75
        self.arr = [
            box(x, y - w, w, w, "white", "red"),
            text("↑", x + hw, y - w + hhw, w, "center", "red"),
            box(x, y, w, w, "white", "red"),
            text("↓", x + hw, y + hhw, w, "center", "red"),
            box(x - w, y, w, w, "white", "red"),
            text("←", x - hw, y + hhw, w, "center", "red"),
            box(x + w, y, w, w, "white", "red"),
            text("→", x + w + hw, y + hhw, w, "center", "red"),
        ]
        self.arr[0].tap=self.clickUp
        self.arr[2].tap=self.clickDown
        self.arr[4].tap=self.clickLeft
        self.arr[6].tap=self.clickRight
        delay(self.loop, 100)
        
    def loop(self):
        for i in range(len(self.arr)):
            self.arr[i].front()
        delay(self.loop, 100)
    
    def onKeydown(self, keyCode, key):
        try:
            keydown(keyCode, key)
        except e:
            pass
    def clickUp(self):
        self.onKeydown(38, "ArrowLeft")
    def clickDown(self):
        self.onKeydown(40, "ArrowDown")
    def clickLeft(self):
        self.onKeydown(37, "ArrowLeft")
    def clickRight(self):
        self.onKeydown(39, "ArrowRight")
MyKeyBoard(768-200, 1024-100, 100)







也可以下载代码,本地python环境运行(用pygame封装了xdf库)。



« 上一篇下一篇 »

相关文章:

python编程学习-华容道  (2024-11-14 16:43:25)

python编程学习-动画  (2024-11-14 16:39:37)

python编程学习-别踩白块  (2024-11-14 16:38:59)

python编程学习-俄罗斯方块  (2024-11-14 16:38:19)

python编程学习-井字棋  (2024-11-14 16:34:9)

python编程学习-五子棋  (2024-11-14 16:33:23)

python编程学习-乒乓  (2024-11-14 16:32:46)

python编程学习-一笔画关卡生成  (2024-11-14 16:32:6)

python编程学习-一笔画  (2024-11-14 16:31:27)

python编程学习-woblox  (2024-11-14 16:30:47)

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。