Changeset 8432
- Timestamp:
- 2017-05-20 14:43:40 (5 years ago)
- Location:
- 2016/23/JaakkoS/JS_Pong/JSPhaser
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/23/JaakkoS/JS_Pong/JSPhaser/pong.js
r8423 r8432 6 6 var scaled = false; 7 7 var pUPicture; 8 var AIOn = true; 8 9 var tekstinTyyli = {font: "bold 32px Arial", fill: "#fff", boundsAlingH : "center", boundsAlingV:"middle"} 9 10 … … 12 13 13 14 function preload() { 15 game.load.spritesheet('painikkeet', 'kuvat/kuvakkeet.png', 50, 50); 16 } 17 18 function load() { 14 19 15 20 } … … 44 49 addPickUp(pUPicture); 45 50 46 51 game.add.button(leveys/2, korkeus + 60, 'painikkeet', changePlayerStatus, this, 2, 1, 0); 47 52 48 53 } … … 53 58 game.physics.arcade.overlap(pU, ball); 54 59 55 checkMovement(stick1, wButton, sButton); 60 if(!AIOn){ 61 checkMovement(stick1, wButton, sButton);} 62 else{ 63 prosessAI(stick1, ball, nopeus); 64 } 65 56 66 checkMovement(stick2, cursors.up, cursors.down); 57 67 … … 65 75 game.paused = true; 66 76 } 77 } 78 function changePlayerStatus(){ 79 AIOn = !AIOn; 67 80 } 68 81 … … 148 161 } 149 162 150 163 function changeVelocity(pickUp, ball){ 151 164 152 165 } 153 166 167 function prosessAI(stick, target, speed){ 168 169 var direction = 0.0; 170 171 direction = (target.y - stick.y) / (korkeus * 0.06); 172 suunta = Math.min(direction, 1.0); 173 suunta = Math.max(direction, -1.0); 174 175 stick.body.velocity.y = direction * speed; 176 177 } 178 179 180
Note: See TracChangeset
for help on using the changeset viewer.