{"id":226584,"student_id":10,"content":"setBackdrop(\"black\");\n\nvar btn_1 = createSprite('tower_1.png');\nvar btn_2 = createSprite('tower_2.png');\nvar btn_3 = createSprite('tower_3.png');\nvar btn_start = createSprite('tower_1.png');\nvar btn_levelup = createSprite('tower_1.png');\n\n\nbtn_1.moveTo(30, 870);\nbtn_2.moveTo(90, 870);\nbtn_3.moveTo(150, 870);\nbtn_start.moveTo(1170, 870);\nbtn_levelup.moveTo(1170, 30);\nbtn_1.on('click', buildTowerA);\nbtn_2.on('click', buildTowerB);\nbtn_3.on('click', buildTowerC);\nbtn_start.on('click', nextLevel);\nbtn_levelup.on('click', levelup);\n\n\nfor (var x = 0; x \u003c 20; x++) {\n for (var y = 0; y \u003c 14; y++) {\n if (x % 5 != 4 \u0026\u0026 y % 5 != 4) {\n var t = createSprite('base.png', 'tower_1.png', 'tower_2.png', 'tower_3.png');\n t.x = x * 60 + 30;\n t.y = y * 60 + 30;\n towers.push(t); \n }\n }\n}\n\nfunction updateEnemies () {\n for (var i=0; i\u003cenemies.length; i++) {\n var e = enemies[i];\n \n if (e.life \u003c 2400 \u0026\u0026 e.opacity \u003e 0) {\n e.stepForward(e.speed);\n e.life += e.speed;\n } else {\n enemies.splice(i, 1);\n i -= 1;\n e.destroy();\n }\n if (e.life \u003c 900) e.direction = 90;\n else if (e.life \u003c 1200) e.direction = 180;\n else if (e.life \u003c 1800) e.direction = 270;\n else e.direction = 0;\n }\n}\n\nfunction attact () {\n for (var i=0; i\u003ctowers.length; i++) {\n \n var t = towers[i];\n \n if (t.costumeId == 1) {\n for (var j=0; j\u003cenemies.length; j++) {\n e = enemies[j];\n \n if (e.distanceTo(t) \u003c t.range) {\n e.opacity -= 0.01;\n pen.color = 'red';\n pen.size = 2;\n pen.drawLine(t.x, t.y, e.x, e.y);\n t.toward(e);\n break;\n }\n }\n }\n \n if (t.costumeId == 2) {\n for (var j=0; j\u003cenemies.length; j++) {\n e = enemies[j];\n \n if (e.distanceTo(t) \u003c t.range) {\n e.opacity -= 0.0001;\n pen.color = 'blue';\n pen.size = 1;\n pen.drawLine(t.x, t.y, e.x, e.y);\n t.toward(e);\n }\n }\n }\n }\n}\n\nfunction gameloop() {\n for (var i=0; i \u003c towers.length; i++) {\n t = towers[i];\n if (cursor.isDown \u0026\u0026 t.touched(cursor)) {\n select = t;\n }\n \n if (select) {\n t.opacity = 0.5;\n } else {\n t.opacity = 1;\n }\n }\n if (select) {\n select.opacity = 1;\n pen.color = 'white';\n pen.size = 2;\n pen.drawCircle(select.x, select.y, select.range || 0);\n }\n}\n\nfunction levelup () {\n if (select) {\n if (select.costumeId == 0) {\n select.scale *= 1.1;\n select.range += 100;\n }\n if (select.costumeId == 1) {\n select.scale *= 1.1;\n select.range += 100;\n }\n if (select.costumeId == 2) {\n select.scale *= 1.1;\n select.range += 100;\n }\n }\n}\n\nfunction nextLevel () {\n if (level == 0) {\n for (var i=0; i\u003c30; i++) {\n setTimeout(createA, i * 500);\n } \n }\n if (level == 1) {\n for (var i=0; i\u003c30; i++) {\n setTimeout(createB, i * 500);\n } \n }\n \n}\n\nfunction createA () {\n var a = createSprite('ant.png');\n a.x = -30;\n a.y = 270;\n a.speed = 2;\n a.life = 0;\n enemies.push(a);\n}\n\nfunction createB () {\n var a = createSprite('ant.png');\n a.x = -30;\n a.y = 270;\n a.speed = 2;\n a.life = 0;\n enemies.push(a);\n}\n\nfunction buildTowerA () {\n if (select) {\n select.costumeId = 1;\n select.range = 300;\n select.attact\n }\n select = undefined;\n}\n\nfunction buildTowerB () {\n if (select) {\n select.costumeId = 2;\n select.range = 150;\n }\n select = undefined;\n}\n\nfunction buildTowerC () {\n if (select) {\n select.costumeId = 3;\n select.range = 300;\n }\n select = undefined;\n}\n\nforever(gameloop);\nforever(attact);\nforever(updateEnemies);\n\n","created_at":"2021-02-03T15:59:47.193+08:00","updated_at":"2021-02-04T11:05:01.473+08:00","name":"塔防","language":"javascript","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/226584/0e6b6342c4103b57588a23dd8353bbef.jpg"},"parent_id":2,"plugin":"Game.set({width: 1200, height: 900});","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":188,"hashid":"kdms6832n","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4036885,"file_name":"tower_3.png","project_id":226584,"asset_id":314534,"created_at":"2021-02-03T16:01:22.545+08:00","updated_at":"2021-02-03T16:01:22.545+08:00"},{"id":4036886,"file_name":"tower_2.png","project_id":226584,"asset_id":314535,"created_at":"2021-02-03T16:01:22.546+08:00","updated_at":"2021-02-03T16:01:22.546+08:00"},{"id":4036887,"file_name":"tower_1.png","project_id":226584,"asset_id":314536,"created_at":"2021-02-03T16:01:23.376+08:00","updated_at":"2021-02-03T16:01:23.376+08:00"},{"id":4036888,"file_name":"base.png","project_id":226584,"asset_id":314537,"created_at":"2021-02-03T16:01:23.377+08:00","updated_at":"2021-02-03T16:01:23.377+08:00"},{"id":4036889,"file_name":"ant.png","project_id":226584,"asset_id":314538,"created_at":"2021-02-03T16:01:23.998+08:00","updated_at":"2021-02-03T16:01:23.998+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦