{"id":179565,"student_id":10,"content":"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_0.png', 'ball_1.png') #球\nbar = create_sprite('bar_0.png', 'bar_1.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 ball.costume_id = 1\n gameover_text.hidden = False\n\nforever(loop) #重複不斷執行遊戲迴圈\n","created_at":"2020-08-10T16:41:45.201+08:00","updated_at":"2024-01-16T13:24:28.742+08:00","name":"打磚塊(完整版)","language":"python","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/179565/a4771b0e4ccdf8e4c189026d4893253a.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":614,"hashid":"gk4szwnv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3067388,"file_name":"bg.jpg","project_id":179565,"asset_id":215182,"created_at":"2020-08-10T16:44:06.803+08:00","updated_at":"2020-08-10T16:44:06.803+08:00"},{"id":3067400,"file_name":"1.mp3","project_id":179565,"asset_id":209236,"created_at":"2020-08-10T17:13:31.441+08:00","updated_at":"2020-08-10T17:13:31.441+08:00"},{"id":3067401,"file_name":"2.mp3","project_id":179565,"asset_id":209237,"created_at":"2020-08-10T17:13:31.444+08:00","updated_at":"2020-08-10T17:13:31.444+08:00"},{"id":3067406,"file_name":"7.mp3","project_id":179565,"asset_id":209242,"created_at":"2020-08-10T17:13:39.186+08:00","updated_at":"2020-08-10T17:13:39.186+08:00"},{"id":3067407,"file_name":"bgm.mp3","project_id":179565,"asset_id":172287,"created_at":"2020-08-10T17:13:39.188+08:00","updated_at":"2020-08-10T17:13:39.188+08:00"},{"id":3067408,"file_name":"hit.wav","project_id":179565,"asset_id":172284,"created_at":"2020-08-10T17:13:39.842+08:00","updated_at":"2020-08-10T17:13:39.842+08:00"},{"id":3067404,"file_name":"5.mp3","project_id":179565,"asset_id":209240,"created_at":"2020-08-10T17:13:34.637+08:00","updated_at":"2020-08-10T17:13:34.637+08:00"},{"id":3067405,"file_name":"6.mp3","project_id":179565,"asset_id":209241,"created_at":"2020-08-10T17:13:34.639+08:00","updated_at":"2020-08-10T17:13:34.639+08:00"},{"id":3067402,"file_name":"3.mp3","project_id":179565,"asset_id":209238,"created_at":"2020-08-10T17:13:33.087+08:00","updated_at":"2020-08-10T17:13:33.087+08:00"},{"id":3067403,"file_name":"4.mp3","project_id":179565,"asset_id":209239,"created_at":"2020-08-10T17:13:33.089+08:00","updated_at":"2020-08-10T17:13:33.089+08:00"},{"id":3067386,"file_name":"ball_0.png","project_id":179565,"asset_id":215181,"created_at":"2020-08-10T16:44:06.023+08:00","updated_at":"2020-08-14T17:12:51.138+08:00"},{"id":3067387,"file_name":"bar_1.png","project_id":179565,"asset_id":237133,"created_at":"2020-08-10T16:44:06.025+08:00","updated_at":"2020-08-14T17:13:06.243+08:00"},{"id":3067382,"file_name":"b4.png","project_id":179565,"asset_id":215177,"created_at":"2020-08-10T16:44:04.911+08:00","updated_at":"2020-08-10T16:44:04.911+08:00"},{"id":3067383,"file_name":"b5.png","project_id":179565,"asset_id":215178,"created_at":"2020-08-10T16:44:04.913+08:00","updated_at":"2020-08-10T16:44:04.913+08:00"},{"id":3067392,"file_name":"p0.png","project_id":179565,"asset_id":215185,"created_at":"2020-08-10T16:44:07.977+08:00","updated_at":"2020-08-10T16:44:07.977+08:00"},{"id":3067393,"file_name":"p1.png","project_id":179565,"asset_id":237132,"created_at":"2020-08-10T16:44:07.979+08:00","updated_at":"2020-08-10T16:44:07.979+08:00"},{"id":3067384,"file_name":"b6.png","project_id":179565,"asset_id":215179,"created_at":"2020-08-10T16:44:05.543+08:00","updated_at":"2020-08-10T16:44:05.543+08:00"},{"id":3067385,"file_name":"b7.png","project_id":179565,"asset_id":215180,"created_at":"2020-08-10T16:44:05.545+08:00","updated_at":"2020-08-10T16:44:05.545+08:00"},{"id":3067380,"file_name":"b2.png","project_id":179565,"asset_id":215175,"created_at":"2020-08-10T16:44:04.274+08:00","updated_at":"2020-08-10T16:44:04.274+08:00"},{"id":3067381,"file_name":"b3.png","project_id":179565,"asset_id":215176,"created_at":"2020-08-10T16:44:04.276+08:00","updated_at":"2020-08-10T16:44:04.276+08:00"},{"id":3067390,"file_name":"gameover.png","project_id":179565,"asset_id":215183,"created_at":"2020-08-10T16:44:07.284+08:00","updated_at":"2020-08-10T16:44:07.284+08:00"},{"id":3067391,"file_name":"hint.png","project_id":179565,"asset_id":237134,"created_at":"2020-08-10T16:44:07.285+08:00","updated_at":"2020-08-10T16:44:07.285+08:00"},{"id":3067378,"file_name":"b0.png","project_id":179565,"asset_id":215173,"created_at":"2020-08-10T16:44:03.623+08:00","updated_at":"2020-08-10T16:44:03.623+08:00"},{"id":3067379,"file_name":"b1.png","project_id":179565,"asset_id":215174,"created_at":"2020-08-10T16:44:03.625+08:00","updated_at":"2020-08-10T16:44:03.625+08:00"},{"id":3077751,"file_name":"ball_1.png","project_id":179565,"asset_id":249473,"created_at":"2020-08-14T17:12:12.458+08:00","updated_at":"2020-08-14T17:12:53.659+08:00"},{"id":3067389,"file_name":"bar_0.png","project_id":179565,"asset_id":215195,"created_at":"2020-08-10T16:44:06.805+08:00","updated_at":"2020-08-14T17:13:02.402+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦