{"id":179569,"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') #設定背景圖\nball = create_sprite('ball.png') #球\nplayer = create_sprite('p0.png', 'p1.png') #玩家擋板\nbar = create_sprite('bar0.png', 'bar1.png') #下方橘色長條\nhint = create_sprite('hint.png') #遊戲說明\ngameover_text = create_sprite('gameover.png') #遊戲結束文字\n\nblocks = [] #存放磚塊\nactive = False #是否發球\nspeed = 10 #球速\nscore = 0 #得分\nlife = 3 #生命\ncombo = 0 #連擊數\n\nball.y = 700\nplayer.y = 800\nball.layer = 1\nhint.layer = 1\ngameover_text.layer = 1\ngameover_text.hidden = True\n\nball.direction = 0\n\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(7)\n blocks.append(b)\n\ncreate_sound('bgm.mp3', True)\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.y = 700\n ball.x = cursor.x\n \n #點擊畫面發球\n if cursor.is_down:\n active = True\n hint.hidden = True\n \n #球撞到擋板反彈\n if ball.touched(player):\n ball.direction = (ball.x - player.x) * 45 / 100\n combo = 0\n create_sound('hit.wav')\n \n #球掉出場景下方\n if ball.y \u003e 850:\n active = False\n ball.direction = 0\n life -= 1\n \n if life \u003c= 0: gameover()\n \n for b in blocks:\n if active: b.y += speed / 100 #磚塊向下移動\n \n if b.y \u003e 800 and b.hidden == False: gameover()\n \n if ball.touched(b):\n b.hidden = True\n ball.direction = -ball.direction + 180\n if speed \u003c 20: speed += 0.2\n combo += 1\n score += combo\n create_sound(str(combo % 7 + 1) + '.mp3')\n\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.x = x * 120 + 60\n b.y = -30\n b.costume_id = random.randrange(7)\n blocks = [b] + blocks\n \n draw_text('life:' + str(life), 100, 860, 'white', 40)\n draw_text('score:' + str(score), 500, 860, 'white', 40)\n draw_text('combo:' + str(combo), 900, 860, 'white', 40)\n \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\n\nforever(loop) #重複不斷執行遊戲迴圈\n\n\n","created_at":"2020-08-10T17:54:03.849+08:00","updated_at":"2020-08-17T12:49:50.840+08:00","name":"打磚塊(錄影版)","language":"python","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/179569/80e46dcec474c1f7b65d970d3d56aedd.jpg"},"parent_id":179565,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":258,"hashid":"yeys82g8","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3067414,"file_name":"hit.wav","project_id":179569,"asset_id":172284,"created_at":"2020-08-10T17:54:03.858+08:00","updated_at":"2020-08-10T17:54:03.858+08:00"},{"id":3067415,"file_name":"bgm.mp3","project_id":179569,"asset_id":172287,"created_at":"2020-08-10T17:54:03.861+08:00","updated_at":"2020-08-10T17:54:03.861+08:00"},{"id":3067416,"file_name":"7.mp3","project_id":179569,"asset_id":209242,"created_at":"2020-08-10T17:54:03.865+08:00","updated_at":"2020-08-10T17:54:03.865+08:00"},{"id":3067417,"file_name":"6.mp3","project_id":179569,"asset_id":209241,"created_at":"2020-08-10T17:54:03.866+08:00","updated_at":"2020-08-10T17:54:03.866+08:00"},{"id":3067418,"file_name":"5.mp3","project_id":179569,"asset_id":209240,"created_at":"2020-08-10T17:54:03.867+08:00","updated_at":"2020-08-10T17:54:03.867+08:00"},{"id":3067419,"file_name":"4.mp3","project_id":179569,"asset_id":209239,"created_at":"2020-08-10T17:54:03.868+08:00","updated_at":"2020-08-10T17:54:03.868+08:00"},{"id":3067420,"file_name":"3.mp3","project_id":179569,"asset_id":209238,"created_at":"2020-08-10T17:54:03.869+08:00","updated_at":"2020-08-10T17:54:03.869+08:00"},{"id":3067421,"file_name":"2.mp3","project_id":179569,"asset_id":209237,"created_at":"2020-08-10T17:54:03.870+08:00","updated_at":"2020-08-10T17:54:03.870+08:00"},{"id":3067422,"file_name":"1.mp3","project_id":179569,"asset_id":209236,"created_at":"2020-08-10T17:54:03.871+08:00","updated_at":"2020-08-10T17:54:03.871+08:00"},{"id":3067423,"file_name":"p1.png","project_id":179569,"asset_id":237132,"created_at":"2020-08-10T17:54:03.872+08:00","updated_at":"2020-08-10T17:54:03.872+08:00"},{"id":3067424,"file_name":"p0.png","project_id":179569,"asset_id":215185,"created_at":"2020-08-10T17:54:03.873+08:00","updated_at":"2020-08-10T17:54:03.873+08:00"},{"id":3067425,"file_name":"hint.png","project_id":179569,"asset_id":237134,"created_at":"2020-08-10T17:54:03.873+08:00","updated_at":"2020-08-10T17:54:03.873+08:00"},{"id":3067426,"file_name":"gameover.png","project_id":179569,"asset_id":215183,"created_at":"2020-08-10T17:54:03.874+08:00","updated_at":"2020-08-10T17:54:03.874+08:00"},{"id":3067427,"file_name":"bar0.png","project_id":179569,"asset_id":215195,"created_at":"2020-08-10T17:54:03.875+08:00","updated_at":"2020-08-10T17:54:03.875+08:00"},{"id":3067428,"file_name":"bg.jpg","project_id":179569,"asset_id":215182,"created_at":"2020-08-10T17:54:03.876+08:00","updated_at":"2020-08-10T17:54:03.876+08:00"},{"id":3067429,"file_name":"bar1.png","project_id":179569,"asset_id":237133,"created_at":"2020-08-10T17:54:03.877+08:00","updated_at":"2020-08-10T17:54:03.877+08:00"},{"id":3067430,"file_name":"ball.png","project_id":179569,"asset_id":215181,"created_at":"2020-08-10T17:54:03.878+08:00","updated_at":"2020-08-10T17:54:03.878+08:00"},{"id":3067431,"file_name":"b7.png","project_id":179569,"asset_id":215180,"created_at":"2020-08-10T17:54:03.879+08:00","updated_at":"2020-08-10T17:54:03.879+08:00"},{"id":3067432,"file_name":"b6.png","project_id":179569,"asset_id":215179,"created_at":"2020-08-10T17:54:03.880+08:00","updated_at":"2020-08-10T17:54:03.880+08:00"},{"id":3067433,"file_name":"b5.png","project_id":179569,"asset_id":215178,"created_at":"2020-08-10T17:54:03.881+08:00","updated_at":"2020-08-10T17:54:03.881+08:00"},{"id":3067434,"file_name":"b4.png","project_id":179569,"asset_id":215177,"created_at":"2020-08-10T17:54:03.881+08:00","updated_at":"2020-08-10T17:54:03.881+08:00"},{"id":3067435,"file_name":"b3.png","project_id":179569,"asset_id":215176,"created_at":"2020-08-10T17:54:03.882+08:00","updated_at":"2020-08-10T17:54:03.882+08:00"},{"id":3067436,"file_name":"b2.png","project_id":179569,"asset_id":215175,"created_at":"2020-08-10T17:54:03.883+08:00","updated_at":"2020-08-10T17:54:03.883+08:00"},{"id":3067437,"file_name":"b1.png","project_id":179569,"asset_id":215174,"created_at":"2020-08-10T17:54:03.884+08:00","updated_at":"2020-08-10T17:54:03.884+08:00"},{"id":3067438,"file_name":"b0.png","project_id":179569,"asset_id":215173,"created_at":"2020-08-10T17:54:03.885+08:00","updated_at":"2020-08-10T17:54:03.885+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦