{"id":162869,"student_id":2589,"content":"import game\nimport random\nimport time\nsound.setVolume(0.3)\nbg = game.create_sprite(\"bg1.png\", \"bg2.png\")\nup_block = game.create_sprite(\"up.png\")\ndown_block = game.create_sprite(\"down.png\")\nleft_block = game.create_sprite(\"left.png\")\nright_block = game.create_sprite(\"right.png\")\nstart_buttom = game.create_sprite(\"start.png\")\nblock = game.create_sprite(\"_up.png\", \"_down.png\", \"_left.png\", \"_right.png\")\nblock.hidden = True\n\nup_block.x = 490\nup_block.y = 800\ndown_block.x = 710\ndown_block.y = 800\nleft_block.x = 280\nleft_block.y = 800\nright_block.x = 920\nright_block.y = 800\n\nt_s = 0\nmax_combo = 0\ncounter = 0\nspeed = 0\nscore = 0\ncombo = 0\nstart = False\n\n# 計分及計算combo\ndef count_score(score, y, combo, max_combo):\n dis = y - 800\n combo += 1\n if dis \u003e= 0:\n score = score + (200-dis)*10 + (combo*10)\n else:\n score = score + (200+dis)*10 + (combo*10)\n if combo \u003e max_combo:\n max_combo = combo\n block.hidden = True\n return score, combo, max_combo\n\ndef loop():\n global counter, speed, score, combo, start, t_s, max_combo\n # 背景動畫\n if counter \u003e 15:\n bg.costume_id = 1\n counter += 1\n else:\n bg.costume_id = 0\n counter += 1\n if counter == 30:\n counter = 0\n \n # 遊戲開始\n if key.enter and start == False:\n game.create_sound(\"bgm.mp3\", True)\n start_buttom.hidden = True\n start = True\n \n t_s = time.time()\n \n # 方塊定位及出現\n if block.hidden == True and start == True:\n block.costume_id = random.randint(0, 3)\n block.y = -100\n if block.costume_id == 0:\n block.x = 490\n if block.costume_id == 1:\n block.x = 710\n if block.costume_id == 2:\n block.x = 280\n if block.costume_id == 3:\n block.x = 920\n block.hidden = False\n speed = random.randint(15, 25)\n \n # 方塊掉落 \n if block.hidden == False:\n block.y += speed\n if block.y \u003e 1000:\n block.hidden = True\n # combo歸0\n combo = 0\n \n # 按鍵按下\n if key.up and block.hidden == False and block.x == 490 and block.y \u003e= 600:\n score, combo, max_combo = count_score(score, block.y, combo, max_combo)\n block.hidden = True\n \n if key.down and block.hidden == False and block.x == 710 and block.y \u003e= 600:\n score, combo, max_combo = count_score(score, block.y, combo, max_combo)\n block.hidden = True\n \n if key.left and block.hidden == False and block.x == 280 and block.y \u003e= 600:\n score, combo, max_combo = count_score(score, block.y, combo, max_combo)\n block.hidden = True\n \n if key.right and block.hidden == False and block.x == 920 and block.y \u003e= 600:\n score, combo, max_combo = count_score(score, block.y, combo, max_combo)\n block.hidden = True\n \n # 遊戲顯示分數及combo\n if start == True and time.time()-t_s \u003c 36:\n game.draw_text(\"Score: \"+str(score), 400, 400, \"gray\", 50)\n if combo \u003e 5:\n game.draw_text(\"Combo: \"+str(combo), 400, 500, \"gray\", 50)\n # 遊戲結束及顯示max combo\n elif start == True and time.time()-t_s \u003e= 36:\n game.create_sound(\"bgm.mp3\", False)\n game.draw_text(\"Score: \"+str(score), 400, 400, \"gray\", 50)\n game.draw_text(\"Max Combo: \"+str(max_combo), 400, 500, \"gray\", 50)\n block.hidden = True\n game.stop()\n\ngame.forever(loop)","created_at":"2020-07-06T02:15:53.803+08:00","updated_at":"2020-07-12T18:00:43.150+08:00","name":"上下左右_T ","language":"python","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/162869/8b3891527497e8cf700aa57164b790a7.jpg"},"parent_id":160784,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":96,"hashid":"36ys82wn","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2832785,"file_name":"bgm.mp3","project_id":162869,"asset_id":235159,"created_at":"2020-07-06T02:15:53.809+08:00","updated_at":"2020-07-06T02:15:53.809+08:00"},{"id":2832786,"file_name":"start.png","project_id":162869,"asset_id":233822,"created_at":"2020-07-06T02:15:53.810+08:00","updated_at":"2020-07-06T02:15:53.810+08:00"},{"id":2832787,"file_name":"bg1.png","project_id":162869,"asset_id":233862,"created_at":"2020-07-06T02:15:53.811+08:00","updated_at":"2020-07-06T02:15:53.811+08:00"},{"id":2832788,"file_name":"bg2.png","project_id":162869,"asset_id":233861,"created_at":"2020-07-06T02:15:53.812+08:00","updated_at":"2020-07-06T02:15:53.812+08:00"},{"id":2832789,"file_name":"_up.png","project_id":162869,"asset_id":233854,"created_at":"2020-07-06T02:15:53.813+08:00","updated_at":"2020-07-06T02:15:53.813+08:00"},{"id":2832790,"file_name":"_right.png","project_id":162869,"asset_id":233852,"created_at":"2020-07-06T02:15:53.814+08:00","updated_at":"2020-07-06T02:15:53.814+08:00"},{"id":2832791,"file_name":"_left.png","project_id":162869,"asset_id":233851,"created_at":"2020-07-06T02:15:53.815+08:00","updated_at":"2020-07-06T02:15:53.815+08:00"},{"id":2832792,"file_name":"_down.png","project_id":162869,"asset_id":233850,"created_at":"2020-07-06T02:15:53.816+08:00","updated_at":"2020-07-06T02:15:53.816+08:00"},{"id":2832793,"file_name":"up.png","project_id":162869,"asset_id":233846,"created_at":"2020-07-06T02:15:53.817+08:00","updated_at":"2020-07-06T02:15:53.817+08:00"},{"id":2832794,"file_name":"right.png","project_id":162869,"asset_id":233844,"created_at":"2020-07-06T02:15:53.818+08:00","updated_at":"2020-07-06T02:15:53.818+08:00"},{"id":2832795,"file_name":"left.png","project_id":162869,"asset_id":233843,"created_at":"2020-07-06T02:15:53.819+08:00","updated_at":"2020-07-06T02:15:53.819+08:00"},{"id":2832796,"file_name":"down.png","project_id":162869,"asset_id":233842,"created_at":"2020-07-06T02:15:53.820+08:00","updated_at":"2020-07-06T02:15:53.820+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦