{"id":13314,"student_id":10,"content":"var redjoin = true;\nvar bluejoin = true;\nvar greenjoin = true;\nvar goldjoin = true;\n\nforever(function(){\n if (status == 0) {\n print(redjoin ? 'on' : 'off', 30, 30, 'red', 30);\n print(bluejoin ? 'on' : 'off', 500, 30, 'blue', 30);\n print(greenjoin ? 'on' : 'off', 30, 370, 'green', 30);\n print(goldjoin ? 'on' : 'off', 500, 370, 'gold', 30);\n\n print('按鍵 a/q', 30, 60, 'red', 20);\n print('按鍵 o/l', 500, 60, 'blue', 20);\n print('按鍵 x/z', 30, 400, 'green', 20);\n print('按鍵 right/left', 500, 400, 'gold', 20);\n\n print('Start', 260, 220, 'black', 45);\n }\n});\n\nwhen('mouseup', function () {\n var x = cursor.x - 320;\n var y = cursor.y - 240;\n if ((x*x + y*y) \u003c 5000) return startGame();\n if (cursor.x \u003c 320 \u0026\u0026 cursor.y \u003c 240) redjoin = !redjoin;\n if (cursor.x \u003e 320 \u0026\u0026 cursor.y \u003c 240) bluejoin = !bluejoin;\n if (cursor.x \u003e 320 \u0026\u0026 cursor.y \u003e 240) goldjoin = !goldjoin;\n if (cursor.x \u003c 320 \u0026\u0026 cursor.y \u003e 240) greenjoin = !greenjoin;\n});\n\nvar players = [];\nvar walls = [];\nvar clock = 0;\nvar startTime;\nvar status = 0;\n\nfunction startGame () {\n status = 1;\n if (redjoin) {\n var red = createPlayer('red.png');\n red.x = 20;\n red.y = 20;\n red.direction = 135;\n when('holding', 'a', function () { \n red.direction += 3;\n });\n when('holding', 'q', function () {\n red.direction -= 3;\n });\n }\n\n if (bluejoin) {\n var blue = createPlayer('blue.png');\n blue.x = 640 - 20;\n blue.y = 30;\n blue.direction = 225;\n when('holding', 'o', function () { \n blue.direction += 3;\n });\n when('holding', 'l', function () {\n blue.direction -= 3;\n });\n }\n\n if (greenjoin) {\n var green = createPlayer('green.png');\n green.x = 30;\n green.y = 480 - 20;\n green.direction = 45;\n when('holding', 'x', function () { \n green.direction += 3;\n });\n when('holding', 'z', function () {\n green.direction -= 3;\n });\n }\n\n if (goldjoin) {\n var gold = createPlayer('gold.png');\n gold.x = 640 - 20;\n gold.y = 480 - 20;\n gold.direction = 315;\n when('holding', 'right', function () { \n gold.direction += 3;\n });\n when('holding', 'left', function () {\n gold.direction -= 3;\n });\n }\n\n startTime = Date.now();\n\n}\n\nforever(function(){\n\n clock++;\n\n for (var i=0; i\u003cplayers.length; i++) {\n\n if (players[i]._deleted) continue;\n\n var p = players[i];\n\n p.stepForward(1.3);\n\n if (p.x \u003c 0) p.x += 640;\n if (p.y \u003c 0) p.y += 480;\n if (p.x \u003e 640) p.x -= 640;\n if (p.y \u003e 480) p.y -= 480;\n \n if (clock%120 \u003c 80 \u0026\u0026 clock%2 == 0) {\n var body = createSprite(p.costumes[0]);\n body.moveTo(p);\n body.name = p.name;\n walls.unshift(body);\n body.opacity = 1;\n \n }\n if (clock%120 \u003e 80 \u0026\u0026 clock%10 == 0) {\n var round = Math.floor(clock/120);\n var body = createSprite(p.costumes[0]);\n zz++\n body.id = round*4 + i;\n body.moveTo(p);\n body.name = p.name;\n walls.unshift(body);\n body.opacity = 0;\n }\n\n for (var c=0; c\u003cwalls.length; c++) {\n var index = walls.indexOf(walls[c]);\n if (index \u003c 10*players.length \u0026\u0026 walls[c].name == p.name) continue;\n \n if (p.touched(walls[c])) {\n if (walls[c].opacity == 0) {\n if (p.name != walls[c].name \u0026\u0026 p.crossId.indexOf(walls[c].id) == -1) {\n p.crossId.push(walls[c].id);\n }\n } else {\n p.killBy = walls[c].name;\n p.time = Date.now() - startTime;\n p.destroy();\n }\n }\n }\n }\n});\n\nfunction createPlayer (img) {\n var player = createSprite(img);\n player.crossId = [];\n player.points = 0;\n player.name = img.slice(0, -4);\n players.push(player);\n return player;\n}\n\nforever(function(){\n if (players.length == 0) return;\n for (var i=0; i\u003cplayers.length; i++) {\n if (players[i]._deleted == false) return;\n }\n\n stop();\n\n for (var i=0; i\u003cplayers.length; i++) {\n var p = players[i];\n p.points = Math.floor(p.time/10) + p.crossId.length*200;\n }\n\n players.sort(function (a, b) { return b.points - a.points; });\n\n var result = '';\n for (var i=0; i\u003cplayers.length; i++) {\n var p = players[i];\n result += '#' + (i + 1) + ' ' + p.name + \"玩家 得分:\" + p.points + \"\\n存活時間(s):\" + p.time/1000 + \"\\n穿越個數:\" + p.crossId.length + \"\\n被 \" + p.killBy + \"擊殺\\n\\n\";\n }\n alert(result);\n \n});\n","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2019-11-01T12:48:34.999+08:00","name":"蛇蛇大戰 (2~4人)","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/13314/c9b66f9f859573831b64a764e49cc0b1.jpg"},"parent_id":2,"plugin":"","description":"存活時間越久、穿越個數越多分數越高","note":null,"status":"public","like_student_ids":[1936,7],"is_featured":true,"views":1259,"hashid":"kdms63yz","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":275067,"file_name":"gold.png","project_id":13314,"asset_id":33430,"created_at":"2017-10-18T00:24:16.494+08:00","updated_at":"2017-10-18T00:24:16.494+08:00"},{"id":275068,"file_name":"blue.png","project_id":13314,"asset_id":33431,"created_at":"2017-10-18T00:24:16.496+08:00","updated_at":"2017-10-18T00:24:16.496+08:00"},{"id":275069,"file_name":"red.png","project_id":13314,"asset_id":33432,"created_at":"2017-10-18T00:24:16.716+08:00","updated_at":"2017-10-18T00:24:16.716+08:00"},{"id":275070,"file_name":"green.png","project_id":13314,"asset_id":33433,"created_at":"2017-10-18T00:24:16.718+08:00","updated_at":"2017-10-18T00:24:16.718+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦