{"id":1023887,"student_id":2589,"content":"import random\nfrom game import (\n set_backdrop,\n create_sprite,\n create_sound,\n draw_text,\n key,\n forever,\n stop\n)\n\nset_backdrop('bg_grid.jpg')\nfood = create_sprite('apple.png', 'orange.png')\nhead = create_sprite('head.png')\nhint = create_sprite('hint.png')\ngame_over = create_sprite('gameover.png')\ntail = create_sprite('body.png', 'body_left.png', 'body_right.png', 'tail.png')\n\ntail.costume_id = 3\n\nfood.layer = 1\nhead.layer = 2\ngame_over.layer = 3\n\ngame_over.hidden = True\n\nclock = 0\nnext_direction = 90\nbodies = [tail]\nis_start = False\nlevel = 0\n\nfood.move_to(930, 450)\nhead.move_to(270, 450)\ntail.move_to(210, 450)\nhint.move_to(270, 450)\n\n\n\ndef loop():\n global clock, next_direction, is_start, level, bodies\n\n if key.up == True and head.direction != 180:\n next_direction = 0\n is_start = True\n \n if key.right == True and head.direction != 270:\n next_direction = 90\n is_start = True\n \n if key.down == True and head.direction != 0:\n next_direction = 180\n is_start = True\n \n if key.left == True and head.direction != 90:\n next_direction = 270\n is_start = True\n \n hint.hidden = is_start\n \n level = (len(bodies) - 1) // 5\n if level \u003e 10:\n level = 10\n \n clock = clock + 1\n\n if clock % (15 - level) == 0 and is_start == True:\n if head.touched(food) == True:\n food.x = random.randrange(20) * 60 + 30\n food.y = random.randrange(15) * 60 + 30\n \n b = create_sprite('body.png', 'body_left.png', 'body_right.png', 'tail.png')\n b.move_to(head)\n bodies.append(b)\n \n if len(bodies) \u003e 0:\n b = bodies.pop()\n b.move_to(head)\n bodies = [b] + bodies\n update_bodies_costume()\n \n head.direction = next_direction\n head.step_forward(60)\n \n if head.touched(bodies) == True:\n stop()\n game_over.hidden = False\n draw_text(len(bodies) - 1, 550, 430, 'white', 80)\n \n if head.x \u003e 1200:\n head.x = head.x - 1200\n \n if head.x \u003c 0:\n head.x = head.x + 1200\n \n if head.y \u003e 900:\n head.y = head.y - 900\n \n if head.y \u003c 0:\n head.y = head.y + 900\n \n if clock % 20 == 0:\n if food.scale == 1:\n food.scale = 0.8\n hint.scale = 0.8\n else:\n food.scale = 1\n hint.scale = 1\n \n draw_text(len(bodies) - 1, 10, 10, 'white', 40)\n\n\nforever(loop)\n\n\n\ndef update_bodies_costume():\n diff = next_direction - head.direction\n\n if diff == 0:\n bodies[0].costume_id = 0\n \n if diff == -90 or diff == 270:\n bodies[0].costume_id = 1\n \n if diff == 90 or diff == -270:\n bodies[0].costume_id = 2\n \n bodies[0].direction = next_direction\n\n bodies[-1].costume_id = 3\n","created_at":"2025-05-29T12:24:20.891+08:00","updated_at":"2025-05-29T12:25:13.602+08:00","name":"11_B_D_貪吃蛇_綜合練習_【講解】縮放動畫特效 副本","language":"python","screenshot":{"url":null},"parent_id":1012130,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":76,"hashid":"yeys553j3","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":38687025,"file_name":"bg_grid.jpg","project_id":1023887,"asset_id":251902,"created_at":"2025-05-29T12:24:20.896+08:00","updated_at":"2025-05-29T12:24:20.896+08:00"},{"id":38687026,"file_name":"bg.jpg","project_id":1023887,"asset_id":251903,"created_at":"2025-05-29T12:24:20.898+08:00","updated_at":"2025-05-29T12:24:20.898+08:00"},{"id":38687027,"file_name":"body_left.png","project_id":1023887,"asset_id":251904,"created_at":"2025-05-29T12:24:20.899+08:00","updated_at":"2025-05-29T12:24:20.899+08:00"},{"id":38687028,"file_name":"body.png","project_id":1023887,"asset_id":251905,"created_at":"2025-05-29T12:24:20.900+08:00","updated_at":"2025-05-29T12:24:20.900+08:00"},{"id":38687029,"file_name":"apple.png","project_id":1023887,"asset_id":251906,"created_at":"2025-05-29T12:24:20.901+08:00","updated_at":"2025-05-29T12:24:20.901+08:00"},{"id":38687030,"file_name":"gameover.png","project_id":1023887,"asset_id":251907,"created_at":"2025-05-29T12:24:20.902+08:00","updated_at":"2025-05-29T12:24:20.902+08:00"},{"id":38687031,"file_name":"head.png","project_id":1023887,"asset_id":251908,"created_at":"2025-05-29T12:24:20.902+08:00","updated_at":"2025-05-29T12:24:20.902+08:00"},{"id":38687032,"file_name":"hint.png","project_id":1023887,"asset_id":251909,"created_at":"2025-05-29T12:24:20.903+08:00","updated_at":"2025-05-29T12:24:20.903+08:00"},{"id":38687033,"file_name":"tail.png","project_id":1023887,"asset_id":251910,"created_at":"2025-05-29T12:24:20.904+08:00","updated_at":"2025-05-29T12:24:20.904+08:00"},{"id":38687034,"file_name":"orange.png","project_id":1023887,"asset_id":251911,"created_at":"2025-05-29T12:24:20.905+08:00","updated_at":"2025-05-29T12:24:20.905+08:00"},{"id":38687035,"file_name":"bling.ogg","project_id":1023887,"asset_id":251912,"created_at":"2025-05-29T12:24:20.906+08:00","updated_at":"2025-05-29T12:24:20.906+08:00"},{"id":38687036,"file_name":"bgm.mp3","project_id":1023887,"asset_id":251913,"created_at":"2025-05-29T12:24:20.907+08:00","updated_at":"2025-05-29T12:24:20.907+08:00"},{"id":38687037,"file_name":"body_right.png","project_id":1023887,"asset_id":251914,"created_at":"2025-05-29T12:24:20.908+08:00","updated_at":"2025-05-29T12:24:20.908+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
繁中
简中
English
日本語
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦