{"id":169690,"student_id":2589,"content":"sound.play(\"bgm.mp3\")\n// 設定背景與桌子:\nsetBackdrop(\"bar.png\");\nvar table_1 = createSprite(\"table_1.png\");\nvar table_2 = createSprite(\"table_2.png\");\nvar table_3 = createSprite(\"table_3.png\");\nvar table_4 = createSprite(\"table_4.png\");\n//第一排客人要在table_1後面,第二排客人要在table_2後面......\n//因此需要編排圖層,4張桌子跟4排客人加起來有8層\n//圖層編號是1, 3, 5, 7\ntable_1.layer = 2;\ntable_2.layer = 4;\ntable_3.layer = 6;\ntable_4.layer = 8;\n\n// 播放音檔:\n//sound.play(\"Gymnopedie_No_1.mp3\");\nvar clock = 0;\nvar customers = [];\nvar beerMugs = [];\nvar backCustomers = [];\nvar score = 0;\nvar level = 1;\nvar speed = 0.5;\nvar interval = 200;\n\n//beertender\nvar koding = createSprite([\"koding.png\", \"kodingWithBeer.png\", \"kodingUpset.png\"]);\nkoding.costumeId = 0;\nkoding.x = 950;\nkoding.y = 220;\nkoding.direction = 100;\n\nfunction kodingGoDown(){\n if (koding.y \u003c 850) {\n koding.y += 180;\n }\n}\n\nfunction kodingGoUp(){\n if (koding.y \u003e 250) {\n koding.y -= 180;\n }\n}\non(\"keydown\", \"down\", kodingGoDown);\non(\"keydown\", \"up\", kodingGoUp);\n\nfunction kodingGetBeer(){\n koding.costumeId = 1;\n}\n\nfunction kodingSendBeer(){\n koding.costumeId = 0;\n createBeer(koding.y);\n}\n\non(\"keydown\", \"space\", kodingGetBeer);\non(\"keyup\", \"space\", kodingSendBeer);\n\nfunction createBeer(yloc) {\n var beer = createSprite([\"beer.png\",\"broken.png\"]);\n beer.x = 800;\n beer.y = yloc+20\n beer.layer = 10\n beerMugs.push(beer);\n\n beer.on(\"touch\", customers, function(target) {\n target.costumeId = 1;\n backCustomers.push(target);\n score += 1;\n beer.hidden = true;\n beer.destroy();\n });\n\n}\n\nfunction moveBeerMugs() {\n for (var i = 0; i \u003c beerMugs.length; i++) {\n if (beerMugs[i].hidden == false){\n beerMugs[i].x -= 2*speed;\n }\n }\n}\n\nfunction createCustomer() {\n if (clock%interval == 0) {\n var customer = createSprite([\"customer.png\", \"customerWithBeer.png\", \"customerAngry.png\"]);\n customer.costumeId = 0;\n //table=0~3\n table = Math.ceil(Math.random()*4);\n //客人要在桌子後面,所以桌子的圖層編號是1, 3, 5, 7\n customer.layer = 2*table-1;\n \n //視覺效果上,每一層入口有些傾斜,所以初始x值會不同\n //但是這樣程式碼會很醜,要判斷消失位置也很困難,故作罷\n /*\n //table_1:350-55, table_2:350-55-55, ...\n customer.x = 350-55*table;\n */\n customer.x = 100;\n //客人的位置比酒保偏上20,所以從220變成200\n //table_1:200, table_2:200+180, table_3: 200+180+180...\n customer.y = 20+180*table;\n customers.push(customer);\n //x跟y的關係:x=350-55*(y-20)/180 = \n }\n}\n\nfunction moveCustomers() {\n for (var i = 0; i \u003c customers.length; i++) {\n customers[i].x += speed;\n }\n for (var i = 0; i \u003c backCustomers.length; i++) {\n backCustomers[i].x -= 3*speed;\n if (backCustomers[i].x \u003c 100) {\n backCustomers[i].destroy();\n }\n }\n}\n\nfunction checkGameOver() {\n for (var i = 0; i \u003c beerMugs.length; i++) {\n //理論上每個桌子撞到牆面的水平位置不一樣\n //但是要一一偵測牆面在哪太麻煩,先作罷\n if(beerMugs[i].x\u003c100){\n /*\n //用下面的方式雖然程式碼簡潔,\n //但是會有bug,而且碰撞偵測超慢,只好作罷\n //可惜沒有顏色碰撞偵測......\n if (!(beerMugs[i].touched(table_1) ||\n beerMugs[i].touched(table_2) ||\n beerMugs[i].touched(table_3) ||\n beerMugs[i].touched(table_4))){\n */\n beerMugs[i].costumeId = 1;\n sound.play(\"beerHit.mp3\");\n gameOver();\n }\n }\n \n for(var i = 0; i \u003c customers.length; i++){\n if(customers[i].x \u003e 850){\n customers[i].costumeId = 2;\n gameOver();\n }\n }\n}\n\nfunction gameOver() {\n koding.costumeId = 2;\n drawText(\"GAME OVER\", 300, 350, 'white', 100);\n stop();\n}\n\n// 不停地執行...\nforever(function() {\n drawText(\"Score:\", 900, 50, 'white', 50);\n drawText(score, 1080, 50, 'white', 50);\n drawText(\"Level:\", 50, 50, 'white', 50);\n drawText(level, 200, 50, 'white', 50);\n drawText(\"Interval:\", 400, 50, 'white', 50);\n drawText(interval, 600, 50, 'white', 50);\n createCustomer();\n moveCustomers();\n moveBeerMugs();\n checkGameOver();\n\n clock += 1;\n if(clock%500 == 0){\n speed += 0.2;\n level += 1;\n if(interval\u003e20){\n interval -= 30;\n }\n }\n});","created_at":"2020-07-23T10:51:01.015+08:00","updated_at":"2020-07-23T10:55:18.487+08:00","name":"beertender_teacher","language":"javascript","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/169690/bf2c99186c8dcc3164c183ec3bf8349e.jpg"},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900})","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":80,"hashid":"9ygskdy3","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2931160,"file_name":"bgm.mp3","project_id":169690,"asset_id":241347,"created_at":"2020-07-23T10:51:23.501+08:00","updated_at":"2020-07-23T10:51:23.501+08:00"},{"id":2931161,"file_name":"beerHit.mp3","project_id":169690,"asset_id":241348,"created_at":"2020-07-23T10:51:23.506+08:00","updated_at":"2020-07-23T10:51:23.506+08:00"},{"id":2931162,"file_name":"kodingUpset.png","project_id":169690,"asset_id":241349,"created_at":"2020-07-23T10:51:23.517+08:00","updated_at":"2020-07-23T10:51:23.517+08:00"},{"id":2931163,"file_name":"customerAngry.png","project_id":169690,"asset_id":241350,"created_at":"2020-07-23T10:51:23.520+08:00","updated_at":"2020-07-23T10:51:23.520+08:00"},{"id":2931164,"file_name":"broken.png","project_id":169690,"asset_id":241351,"created_at":"2020-07-23T10:51:23.524+08:00","updated_at":"2020-07-23T10:51:23.524+08:00"},{"id":2931165,"file_name":"table_1.png","project_id":169690,"asset_id":241352,"created_at":"2020-07-23T10:51:23.528+08:00","updated_at":"2020-07-23T10:51:23.528+08:00"},{"id":2931166,"file_name":"table_4.png","project_id":169690,"asset_id":241353,"created_at":"2020-07-23T10:51:23.532+08:00","updated_at":"2020-07-23T10:51:23.532+08:00"},{"id":2931167,"file_name":"table_red.png","project_id":169690,"asset_id":241354,"created_at":"2020-07-23T10:51:23.536+08:00","updated_at":"2020-07-23T10:51:23.536+08:00"},{"id":2931168,"file_name":"table_2.png","project_id":169690,"asset_id":241355,"created_at":"2020-07-23T10:51:23.540+08:00","updated_at":"2020-07-23T10:51:23.540+08:00"},{"id":2931169,"file_name":"table_3.png","project_id":169690,"asset_id":241356,"created_at":"2020-07-23T10:51:23.544+08:00","updated_at":"2020-07-23T10:51:23.544+08:00"},{"id":2931170,"file_name":"kodingWithBeer.png","project_id":169690,"asset_id":241357,"created_at":"2020-07-23T10:51:23.548+08:00","updated_at":"2020-07-23T10:51:23.548+08:00"},{"id":2931171,"file_name":"koding.png","project_id":169690,"asset_id":241358,"created_at":"2020-07-23T10:51:23.552+08:00","updated_at":"2020-07-23T10:51:23.552+08:00"},{"id":2931172,"file_name":"customerWithBeer.png","project_id":169690,"asset_id":241359,"created_at":"2020-07-23T10:51:23.556+08:00","updated_at":"2020-07-23T10:51:23.556+08:00"},{"id":2931173,"file_name":"customer.png","project_id":169690,"asset_id":241360,"created_at":"2020-07-23T10:51:23.560+08:00","updated_at":"2020-07-23T10:51:23.560+08:00"},{"id":2931174,"file_name":"beer.png","project_id":169690,"asset_id":241361,"created_at":"2020-07-23T10:51:23.564+08:00","updated_at":"2020-07-23T10:51:23.564+08:00"},{"id":2931175,"file_name":"bar.png","project_id":169690,"asset_id":241362,"created_at":"2020-07-23T10:51:23.568+08:00","updated_at":"2020-07-23T10:51:23.568+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦