{"id":9024,"student_id":70,"content":"var enemies = {};\nvar me = createSprite([\"tank.png\",\"boom.png\"]);\nvar bullets = [];\nforever(function(){\n\tme.toward(cursor);\n DB.broadcast({type:\"tank\", x:me.x, y:me.y, direction:me.direction});\n if(me.touched(bullets)){\n me.currentCostumeId=1;\n setTimeout(function(){\n stop();\n },1000);\n }\n for(var i in enemies){\n if(enemies[i].touched(bullets)){\n enemies[i].currentCostumeId=1;\n }\n }\n});\nDB.onMessage(\"message\",function(data){\n if(data.content.type==\"tank\"){\n if(!enemies[data.userId]){\n enemies[data.userId] = createSprite([\"tank.png\",\"boom.png\"]);\n enemies[data.userId].userId=data.userId;\n enemies[data.userId].forever(function(){\n print(this.userId,this.x-8,this.y-28);\n });\n }\n enemies[data.userId].x = data.content.x;\n enemies[data.userId].y = data.content.y;\n enemies[data.userId].direction = data.content.direction;\n } else if(data.content.type==\"bullet\"){\n createBullet(data.content.x,data.content.y,data.content.direction);\n }\n});\nwhen(\"holding\",\"w\",function(){ me.y-=3; });\nwhen(\"holding\",\"s\",function(){ me.y+=3; });\nwhen(\"holding\",\"d\",function(){ me.x+=3; });\nwhen(\"holding\",\"a\",function(){ me.x-=3; });\nwhen(\"click\",function(){\n\tvar bullet = createBullet(me.x,me.y,me.direction);\n bullet.stepForward(20);\n DB.broadcast({type:\"bullet\", x:bullet.x, y:bullet.y, direction:bullet.direction});\n});\nforever(function(){\n\tfor(var i=0;i\u003cbullets.length;i++){\n \tbullets[i].stepForward(8); \n if(bullets[i].energy--\u003c=0){\n \tbullets[i].destroy();\n }\n }\n});\nfunction createBullet(x,y,direction){\n\tvar bullet = createSprite(\"bullet.png\");\n bullet.x = x;\n bullet.y = y;\n bullet.direction = direction;\n bullet.energy = 100;\n bullets.push(bullet);\n return bullet;\n}","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2019-11-09T18:02:44.639+08:00","name":"MMO Tank","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/9024/8ef758322427ecdb7e601b8f87870fe5.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":360,"hashid":"5j3sg6m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":198153,"file_name":"bullet.png","project_id":9024,"asset_id":23638,"created_at":"2017-08-09T15:04:17.746+08:00","updated_at":"2017-08-09T15:04:17.746+08:00"},{"id":198154,"file_name":"boom.png","project_id":9024,"asset_id":23639,"created_at":"2017-08-09T15:04:17.748+08:00","updated_at":"2017-08-09T15:04:17.748+08:00"},{"id":198155,"file_name":"tank.png","project_id":9024,"asset_id":23640,"created_at":"2017-08-09T15:05:49.150+08:00","updated_at":"2017-08-09T15:05:49.150+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦