{"id":194890,"student_id":10,"content":"var X_LIMIT = 640; //右邊界\nvar Y_LIMIT = 480; // 下邊界\nvar A_FRAME_TIME = 1.0/60.0; // 一個 frame 經過時間\nvar GRAVITY = 600.0; // 重力參數\nvar MOVING_SPEED = 10; // 移動速度\nvar PIKACHU_JUMP_FORCE = -300;\n\nvar ball_vector = [0.0, 0.0]; // 球的速度向量\nvar left_pikachu_vector = [0.0, 0.0]; // 左邊皮卡丘速度向量\nvar left_pikachu_jumping = false; // 左邊皮卡丘是否跳躍\nvar right_pikachu_vector = [0.0, 0.0]; // 右邊皮卡丘速度向量\nvar right_pikachu_jumping = false; // 右邊皮卡丘是否跳躍\n\nvar point1 = 0;\nvar point2 = 0;\n\nvar background = Game.createSprite('bg.jpg');\nvar stick = Game.createSprite({\n x: 320,\n y: 440,\n scale: 1,\n costumes: [\"stick.jpg\"]\n});\n\nvar left_pikachu = Game.createSprite({\n x: 40,\n y: 417,\n scale: 2,\n costumes: [\"pikaAt1.png\"]\n});\n\nvar right_pikachu = Game.createSprite({\n x: 600,\n y: 417,\n scale: 2,\n costumes: [\"pikaToRight.png\"]\n});\n\nvar ball = Game.createSprite({\n x: 200,\n y: 100,\n scale: 1,\n costumes: [\"pikaBall.png\"]\n});\ninitBall();\n\nforever(()=\u003e {\n // 球的速度加上重力加速度\n ball_vector[1] += GRAVITY * A_FRAME_TIME;\n\n // 計算球的位置\n ball.x += ball_vector[0] * A_FRAME_TIME;\n ball.y += ball_vector[1] * A_FRAME_TIME;\n\n // 左皮卡丘跳躍\n if (left_pikachu_jumping) {\n // 左皮卡丘速度加上重力加速度\n left_pikachu_vector[1] += GRAVITY * A_FRAME_TIME;\n\n // 計算左皮卡丘位置\n left_pikachu.y += left_pikachu_vector[1] * A_FRAME_TIME * 2;\n\n // 若觸地則重設參數\n if (left_pikachu.y \u003e= 417) {\n left_pikachu.y = 417;\n left_pikachu_jumping = false;\n }\n }\n\n // 右皮卡丘跳躍\n if (right_pikachu_jumping) {\n // 右皮卡丘速度加上重力加速度\n right_pikachu_vector[1] += GRAVITY * A_FRAME_TIME;\n\n // 計算左皮卡丘位置\n right_pikachu.y += right_pikachu_vector[1] * A_FRAME_TIME * 2;\n\n // 若觸地則重設參數\n if (right_pikachu.y \u003e= 417) {\n right_pikachu.y = 417;\n right_pikachu_jumping = false;\n }\n }\n});\n\n// 球碰到邊界反彈\n// 0.8 為彈跳減速\nforever(()=\u003e {\n if (ball.x \u003c 0) {\n ball_vector[0] *= -0.8;\n ball.x = 0;\n }\n\n if (ball.x \u003e 640) {\n ball_vector[0] *= -0.8;\n ball.x = 640;\n }\n\n if (ball.y \u003c 0) {\n ball_vector[1] *= -0.8;\n ball.y = 0;\n }\n\n if (ball.y \u003e 440) {\n ball_vector[1] *= -0.8;\n ball.y = 440;\n if (ball.x \u003e 300) {\n point1 += 1;\n initBall('right');\n } else {\n point2 += 1;\n initBall('left');\n }\n if (point1 \u003e= 5 || point2 \u003e= 5) {\n point1 = point2 = 0;\n alert('遊戲結束');\n initBall();\n }\n }\n print(point2, 600, 10, 'red', 50);\n print(point1, 15, 10, 'red', 50);\n});\n\nfunction initBall(start) {\n if (start == 'left') ball.x = 150;\n else if (start == 'right') ball.x = 450;\n else ball.x = Math.random() \u003e 0.5 ? 150: 450;\n ball.y = 50;\n ball_vector = [0, 0];\n}\n\n\nforever(()=\u003e {\n // 球碰到皮卡丘行為\n if (left_pikachu.touched(ball)) {\n // 計算彈跳方向\n let x = ball.x - left_pikachu.x;\n let y = ball.y - left_pikachu.y;\n let ball_vector_length = Math.sqrt(ball_vector[0]**2 + ball_vector[1]**2);\n let diff_vector_length = Math.sqrt(x**2 + y**2);\n let ratio = ball_vector_length / diff_vector_length;\n\n // 1.2 為皮卡丘對球加速參數\n ball_vector[0] = x * ratio * 1.2;\n ball_vector[1] = y * ratio * 1.2;\n }\n\n if (right_pikachu.touched(ball)) {\n // 計算彈跳方向\n let x = ball.x - right_pikachu.x;\n let y = ball.y - right_pikachu.y;\n let ball_vector_length = Math.sqrt(ball_vector[0]**2 + ball_vector[1]**2);\n let diff_vector_length = Math.sqrt(x**2 + y**2);\n let ratio = ball_vector_length / diff_vector_length;\n\n // 1.2 為皮卡丘對球加速參數\n ball_vector[0] = x * ratio * 1.2;\n ball_vector[1] = y * ratio * 1.2;\n }\n\n})\n\n\n// // 球碰到柱子反彈\n// // @TODO: 有球卡住 bug\n// Game.on(\"touch\", [stick, ball], function(){\n// ball_vector[0] *= -0.8;\n// });\n\n// 右皮卡丘移動\nGame.on('holding', 'left', function() {\n if (right_pikachu.x \u003e 390) {\n right_pikachu.x -= MOVING_SPEED;\n }\n});\n\nGame.on('holding', 'right', function() {\n if (right_pikachu.x \u003c X_LIMIT) {\n right_pikachu.x += MOVING_SPEED;\n }\n});\n\nGame.on('holding', 'up', function() {\n if (!right_pikachu_jumping) {\n right_pikachu_vector[1] = PIKACHU_JUMP_FORCE;\n right_pikachu_jumping = true;\n }\n});\n/////////////\n\n// 左皮卡丘移動\nGame.on('holding', 'a', function() {\n if (left_pikachu.x \u003e -20) {\n left_pikachu.x -= MOVING_SPEED;\n }\n});\n\nGame.on('holding', 'd', function() {\n if (left_pikachu.x \u003c X_LIMIT / 2 - 65) {\n left_pikachu.x += MOVING_SPEED;\n }\n});\n\nGame.on('holding', 'w', function() {\n if (!left_pikachu_jumping) {\n left_pikachu_vector[1] = PIKACHU_JUMP_FORCE;\n left_pikachu_jumping = true;\n }\n});\n/////////////\n\n// setInterval(function(){\n// \tconsole.log('ww')\n// }, 10000)","created_at":"2020-10-14T15:37:10.955+08:00","updated_at":"2020-10-14T16:20:40.692+08:00","name":"皮卡丘打排球 副本","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/194890/578285924c26373430b2b8b48947fa09.jpg"},"parent_id":4718,"plugin":"","description":"風靡一時的皮卡丘打排球遊戲~雙人對戰版!\n\n左邊玩家控制:W, A, S, D\n右邊玩家控制:方向鍵","note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":286,"hashid":"meysw443k","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":3337134,"file_name":"bg.jpg","project_id":194890,"asset_id":15688,"created_at":"2020-10-14T15:37:10.962+08:00","updated_at":"2020-10-14T15:37:10.962+08:00"},{"id":3337135,"file_name":"stick.jpg","project_id":194890,"asset_id":15689,"created_at":"2020-10-14T15:37:10.963+08:00","updated_at":"2020-10-14T15:37:10.963+08:00"},{"id":3337136,"file_name":"pikaAt1.png","project_id":194890,"asset_id":15690,"created_at":"2020-10-14T15:37:10.965+08:00","updated_at":"2020-10-14T15:37:10.965+08:00"},{"id":3337137,"file_name":"pikaBall.png","project_id":194890,"asset_id":15691,"created_at":"2020-10-14T15:37:10.966+08:00","updated_at":"2020-10-14T15:37:10.966+08:00"},{"id":3337138,"file_name":"pikaToRight.png","project_id":194890,"asset_id":15692,"created_at":"2020-10-14T15:37:10.967+08:00","updated_at":"2020-10-14T15:37:10.967+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦