{"id":7216,"student_id":10,"content":"setBackdrop(\"bg.jpg\");\n\nvar platform = createSprite(\"platform.png\");\nplatform.moveTo(500, 200);\n\nvar life = 0;\nvar rockets = [];\n\nfor (var i=0; i\u003c20; i++) {\n var dna = randomDNA();\n var rocket = createSprite(\"rocket.png\");\n rocket.direction = 0;\n rocket.reset = function () {\n this.x = 50;\n this.y = 400;\n this.vx = 0;\n this.vy = 0;\n this.fuel = 300;\n this.active = true;\n }\n rocket.forever(function () {\n this.direction = this.vx*3;\n });\n rocket.on(\"touch\", platform, function(){\n if (this.y \u003e platform.y - this.height/2 || this.vx \u003e 0.2 || this.vx \u003c -0.2 || this.vy \u003e 0.2 || this.vy \u003c -0.2) {\n this.hidden = true;\n } else {\n this.active = false;\n }\n });\n rocket.reset();\n rocket.dna = dna\n rockets.push(rocket);\n}\n\nfunction randomDNA () {\n var dna = '';\n for (var i=0; i\u003c500; i++) {\n dna += Math.floor(Math.random()*4);\n }\n return dna;\n}\n\nfunction crossover (a, b) {\n var newDNA = '';\n for (var i=0; i\u003ca.length; i++) {\n newDNA += Math.random() \u003e 0.5 ? a[i] : b[i];\n }\n return mutation(newDNA);\n}\n\nfunction mutation (dna) {\n var newDNA = '';\n for (var i=0; i\u003cdna.length; i++) {\n newDNA += Math.random() \u003e 0.05 ? dna[i] : Math.floor(Math.random()*4);\n }\n return newDNA;\n}\n\nfunction nextGeneration () {\n rockets.sort(function (a, b) {\n return fitness(a) - fitness(b);\n });\n\n var pops = [];\n for (var i=0; i\u003c16; i++) {\n var rand1 = Math.floor(Math.sqrt(Math.random()*400));\n var rand2 = Math.floor(Math.sqrt(Math.random()*400));\n var newGen = crossover(rockets[rand1].dna, rockets[rand2].dna);\n pops.push(newGen);\n }\n pops.push(randomDNA());\n pops.push(rockets[19].dna);\n pops.push(rockets[18].dna);\n pops.push(rockets[17].dna);\n \n rockets.forEach(r =\u003e r.reset());\n\n for (var i=0; i\u003c20; i++) {\n rockets[i].dna = pops[i];\n }\n}\n\nfunction fitness (rocket) {\n var d = rocket.distanceTo(platform.x, platform.y - 50);\n if (rocket.hidden) d += 400;\n return -d;\n}\n\nforever(function(){\n\n if (life \u003e= 500) {\n nextGeneration();\n life = 0;\n } else {\n for (var i=0; i\u003crockets.length; i++) {\n rocket = rockets[i];\n rocket.vy += 0.05;\n var d = rocket.dna[life];\n if (rocket.fuel \u003e 0) {\n if (d == '0') rocket.vx += 0.1;\n if (d == '1') rocket.vx -= 0.1;\n if (d == '2') rocket.vy -= 0.3;\n rocket.fuel -= 1;\n }\n\n if (rocket.hidden != true \u0026\u0026 rocket.active)\n rocket.move(rocket.vx, rocket.vy);\n }\n }\n life++;\n});","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2019-11-08T02:54:00.062+08:00","name":"火箭降落","language":"javascript","screenshot":{"url":"/uploads/project/screenshot/7216/ed1bf956dab6995310ccf93f64934731.jpg"},"parent_id":2,"plugin":"\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":568,"hashid":"2pds85z","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":160038,"file_name":"bg.jpg","project_id":7216,"asset_id":19411,"created_at":"2017-06-24T09:11:20.270+08:00","updated_at":"2017-06-24T09:11:20.270+08:00"},{"id":160039,"file_name":"bomb.png","project_id":7216,"asset_id":19412,"created_at":"2017-06-24T09:11:20.271+08:00","updated_at":"2017-06-24T09:11:20.271+08:00"},{"id":160040,"file_name":"rocket.png","project_id":7216,"asset_id":19413,"created_at":"2017-06-24T09:11:20.273+08:00","updated_at":"2017-06-24T09:11:20.273+08:00"},{"id":160041,"file_name":"fire.png","project_id":7216,"asset_id":19414,"created_at":"2017-06-24T09:11:20.274+08:00","updated_at":"2017-06-24T09:11:20.274+08:00"},{"id":160042,"file_name":"platform.png","project_id":7216,"asset_id":19415,"created_at":"2017-06-24T09:11:20.275+08:00","updated_at":"2017-06-24T09:11:20.275+08:00"}]
Orange Apple Learning Platform
My Projects
View Project Page
Export
Remix
Import
Delete
Download Android APP (APK)
Screenshot
繁中
简中
English
日本語
1:1:1
1:1
Full Width
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer