{"id":196939,"student_id":2589,"content":"","created_at":"2020-10-19T17:10:58.983+08:00","updated_at":"2023-03-14T14:43:16.274+08:00","name":"打磚塊 - 開始後用滑鼠點擊舞台以啟用按鍵,重整畫面即可重新遊戲。","language":"python","screenshot":{"url":null},"parent_id":4,"plugin":"import random #載入產生隨機數套件\nfrom game import (\n set_backdrop, #設定背景圖\n create_sprite, #創造角色\n create_sound, #創造音效\n draw_text, #繪製文字\n forever, #重複不斷執行\n stop, #遊戲暫停\n)\n\nset_backdrop('bg.jpg') #設定背景圖\nplayer = create_sprite('p0.png', 'p1.png') #玩家擋板\nball = create_sprite('ball.png') #球\nbar = create_sprite('bar0.png', 'bar1.png') #下方橘色長條\nhint = create_sprite('hint.png') #遊戲說明\ngameover_text = create_sprite('gameover.png') #遊戲結束文字\n\nblocks = [] #存放磚塊\nspeed = 10 #移動速度\nscore = 0 #遊戲分數\nlife = 3 #生命\nactive = False #是否卷動磚塊\ncombo = 0 #連擊個數\n\nplayer.y = 800\nball.y = 700\nball.layer = 1\nhint.layer = 1\ngameover_text.layer = 1\ngameover_text.hidden = True\n\nball.direction = 0\ncreate_sound('bgm.mp3')\n\n#初始化 10*5 磚塊\nfor y in range(5):\n for x in range(10):\n b = create_sprite('b0.png', 'b1.png', 'b2.png', 'b3.png', 'b4.png', 'b5.png', 'b6.png', 'b7.png')\n b.x = x*120 + 60\n b.y = y*60 + 30\n b.costume_id = random.randrange(6)\n blocks.append(b)\n\n#遊戲主迴圈\ndef loop ():\n global speed, score, life, active, combo, blocks\n\n player.x = cursor.x\n\n if active:\n ball.step_forward(speed)\n ball.bounce_edge()\n else :\n ball.x = player.x\n\n #玩家按下滑鼠開始發球\n if cursor.is_down:\n active = True\n hint.hidden = True\n \n #球掉出下方邊界時\n if ball.y \u003e= 850:\n ball.direction = 0\n active = False\n ball.y = 700\n ball.x = player.x\n life -= 1\n speed = 10\n \n if ball.touched(player):\n ball.direction = ((ball.x - player.x)/100)*45 #根據球與磚塊的水平位置決定反彈角度\n create_sound('hit.mp3')\n combo = 0\n \n for b in blocks:\n if ball.touched(b):\n b.hidden = True #用隱藏的方式消除磚塊\n ball.direction = -ball.direction + 180 #上下反彈\n \n if speed \u003c 20: speed += 0.2\n \n combo += 1\n score += combo\n create_sound(str(combo % 7 + 1) + '.mp3')\n \n if active:\n b.y += speed / 100 #磚塊下降的速度隨球速變快,而等比例提高\n \n if b.hidden == False and b.y \u003e 800:\n gameover()\n \n #如果到最上排磚塊完全進入遊戲場景內,就產生新的一排磚塊\n if blocks[0].y \u003e= 30:\n for x in range(10):\n b = create_sprite('b0.png', 'b1.png', 'b2.png', 'b3.png', 'b4.png', 'b5.png', 'b6.png', 'b7.png')\n b.costume_id = random.randrange(6)\n b.x = x*120 + 60\n b.y = -30\n blocks = [b] + blocks\n \n if life \u003c 0: gameover()\n\n draw_text('life: ' + str(life), 500, 860, 'white', 40)\n draw_text('score: ' + str(score), 900, 860, 'white', 40)\n draw_text('combo: ' + str(combo), 100, 860, 'white', 40)\n\n#遊戲結束\ndef gameover():\n stop()\n for b in blocks: b.costume_id = 7\n player.costume_id = 1\n bar.costume_id = 1\n gameover_text.hidden = False\n\nforever(loop) #重複不斷執行遊戲迴圈\n","description":null,"note":null,"status":"public","like_student_ids":[12187,12113,11876,11579,1998,12489,15249,12460,9253,9254,12971,12472,10292,8015,11629,12347,16672,8014,26954,11232,22072,40064,11645,13714,8354,17110,22505,19419,17411,28328,35825,30022,23460,33563,30556,24495,26482,26704,34617,27063,21012,26650,27966,22355,33684,38763,51569,41370,42163,43026,54059,11425,40578,23475,40231,37770,35917,42222,42279,41868,33044],"is_featured":false,"views":2242,"hashid":"p93skdeyk","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3378110,"file_name":"hit.wav","project_id":196939,"asset_id":270981,"created_at":"2020-10-19T17:11:13.473+08:00","updated_at":"2020-10-19T17:11:13.473+08:00"},{"id":3378111,"file_name":"bgm.mp3","project_id":196939,"asset_id":270982,"created_at":"2020-10-19T17:11:13.525+08:00","updated_at":"2020-10-19T17:11:13.525+08:00"},{"id":3378112,"file_name":"7.mp3","project_id":196939,"asset_id":270983,"created_at":"2020-10-19T17:11:13.536+08:00","updated_at":"2020-10-19T17:11:13.536+08:00"},{"id":3378113,"file_name":"6.mp3","project_id":196939,"asset_id":270984,"created_at":"2020-10-19T17:11:13.542+08:00","updated_at":"2020-10-19T17:11:13.542+08:00"},{"id":3378114,"file_name":"5.mp3","project_id":196939,"asset_id":270985,"created_at":"2020-10-19T17:11:13.547+08:00","updated_at":"2020-10-19T17:11:13.547+08:00"},{"id":3378115,"file_name":"4.mp3","project_id":196939,"asset_id":270986,"created_at":"2020-10-19T17:11:13.552+08:00","updated_at":"2020-10-19T17:11:13.552+08:00"},{"id":3378116,"file_name":"3.mp3","project_id":196939,"asset_id":270987,"created_at":"2020-10-19T17:11:13.557+08:00","updated_at":"2020-10-19T17:11:13.557+08:00"},{"id":3378117,"file_name":"2.mp3","project_id":196939,"asset_id":270988,"created_at":"2020-10-19T17:11:13.561+08:00","updated_at":"2020-10-19T17:11:13.561+08:00"},{"id":3378118,"file_name":"1.mp3","project_id":196939,"asset_id":270989,"created_at":"2020-10-19T17:11:13.567+08:00","updated_at":"2020-10-19T17:11:13.567+08:00"},{"id":3378119,"file_name":"p1.png","project_id":196939,"asset_id":270990,"created_at":"2020-10-19T17:11:13.571+08:00","updated_at":"2020-10-19T17:11:13.571+08:00"},{"id":3378120,"file_name":"p0.png","project_id":196939,"asset_id":270991,"created_at":"2020-10-19T17:11:13.575+08:00","updated_at":"2020-10-19T17:11:13.575+08:00"},{"id":3378121,"file_name":"hint.png","project_id":196939,"asset_id":270992,"created_at":"2020-10-19T17:11:13.580+08:00","updated_at":"2020-10-19T17:11:13.580+08:00"},{"id":3378122,"file_name":"gameover.png","project_id":196939,"asset_id":270993,"created_at":"2020-10-19T17:11:13.584+08:00","updated_at":"2020-10-19T17:11:13.584+08:00"},{"id":3378123,"file_name":"bar0.png","project_id":196939,"asset_id":270994,"created_at":"2020-10-19T17:11:13.588+08:00","updated_at":"2020-10-19T17:11:13.588+08:00"},{"id":3378124,"file_name":"bg.jpg","project_id":196939,"asset_id":270995,"created_at":"2020-10-19T17:11:13.592+08:00","updated_at":"2020-10-19T17:11:13.592+08:00"},{"id":3378125,"file_name":"bar1.png","project_id":196939,"asset_id":270996,"created_at":"2020-10-19T17:11:13.596+08:00","updated_at":"2020-10-19T17:11:13.596+08:00"},{"id":3378126,"file_name":"ball.png","project_id":196939,"asset_id":270997,"created_at":"2020-10-19T17:11:13.600+08:00","updated_at":"2020-10-19T17:11:13.600+08:00"},{"id":3378127,"file_name":"b7.png","project_id":196939,"asset_id":270998,"created_at":"2020-10-19T17:11:13.604+08:00","updated_at":"2020-10-19T17:11:13.604+08:00"},{"id":3378128,"file_name":"b6.png","project_id":196939,"asset_id":270999,"created_at":"2020-10-19T17:11:13.608+08:00","updated_at":"2020-10-19T17:11:13.608+08:00"},{"id":3378129,"file_name":"b5.png","project_id":196939,"asset_id":271000,"created_at":"2020-10-19T17:11:13.612+08:00","updated_at":"2020-10-19T17:11:13.612+08:00"},{"id":3378130,"file_name":"b4.png","project_id":196939,"asset_id":271001,"created_at":"2020-10-19T17:11:13.615+08:00","updated_at":"2020-10-19T17:11:13.615+08:00"},{"id":3378131,"file_name":"b3.png","project_id":196939,"asset_id":271002,"created_at":"2020-10-19T17:11:13.619+08:00","updated_at":"2020-10-19T17:11:13.619+08:00"},{"id":3378132,"file_name":"b2.png","project_id":196939,"asset_id":271003,"created_at":"2020-10-19T17:11:13.622+08:00","updated_at":"2020-10-19T17:11:13.622+08:00"},{"id":3378133,"file_name":"b1.png","project_id":196939,"asset_id":271004,"created_at":"2020-10-19T17:11:13.626+08:00","updated_at":"2020-10-19T17:11:13.626+08:00"},{"id":3378134,"file_name":"b0.png","project_id":196939,"asset_id":271005,"created_at":"2020-10-19T17:11:13.630+08:00","updated_at":"2020-10-19T17:11:13.630+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦