SHOW:
|
|
- or go back to the newest paste.
| 1 | //Variable initialization so i don't have to do it later | |
| 2 | let plyrRot = 0 | |
| 3 | let localPlayerX = 2 | |
| 4 | let localPlayerY = 2 | |
| 5 | let globalPlayerX = 2 | |
| 6 | let globalPlayerY = 2 | |
| 7 | let plyr2X = 0 | |
| 8 | let plyr2Y = 0 | |
| 9 | let csrvrste = 0 | |
| 10 | let tmp = 0 | |
| 11 | let tmp1 = 0 | |
| 12 | let mapSize = 7 | |
| 13 | let frametime = 200 /*frametime defines how long | |
| 14 | until the clear function will allow the next frame | |
| 15 | to be processed and drawn. */ | |
| 16 | ||
| 17 | /*Alright so the map is going to be 25x25 when finished | |
| 18 | Map edges will be defined by walls*/ | |
| 19 | ||
| 20 | //Function Library :p | |
| 21 | ||
| 22 | //Most functions are commented out currently until the finished | |
| 23 | //product is created. Most functions require having a physical | |
| 24 | //micro:bit for testing both client and server scripts. | |
| 25 | ||
| 26 | //Player Rotation control | |
| 27 | function playerRotation() {
| |
| 28 | if (input.compassHeading() > 0 && input.compassHeading() < 90) { plyrRot = 0 }
| |
| 29 | if (input.compassHeading() > 90 && input.compassHeading() < 180) { plyrRot = 1 }
| |
| 30 | if (input.compassHeading() > 180 && input.compassHeading() < 270) { plyrRot = 2 }
| |
| 31 | if (input.compassHeading() > 270 && input.compassHeading() < 361) { plyrRot = 3 }
| |
| 32 | } | |
| 33 | //Player Positioning based on input from the playerRotation function | |
| 34 | function playerPositioning() {
| |
| 35 | if (input.buttonIsPressed(Button.A)) {
| |
| 36 | switch (plyrRot) {
| |
| 37 | case 0: | |
| 38 | globalPlayerX && localPlayerX++ | |
| 39 | break; | |
| 40 | case 1: | |
| 41 | globalPlayerY && localPlayerY++ | |
| 42 | break | |
| 43 | case 2: | |
| 44 | globalPlayerX && localPlayerX-- | |
| 45 | break | |
| 46 | case 3: | |
| 47 | globalPlayerY && localPlayerY-- | |
| 48 | break | |
| 49 | } | |
| 50 | } | |
| 51 | if (globalPlayerX = 1) { localPlayerX = globalPlayerX }
| |
| 52 | if (globalPlayerX > 1) { localPlayerX = 2 }
| |
| 53 | if (globalPlayerY = 1) { localPlayerY = globalPlayerY }
| |
| 54 | if (globalPlayerY > 1) { localPlayerY = 2 }
| |
| 55 | } | |
| 56 | /*Waiting for connection request from client | |
| 57 | function clientSync() {
| |
| 58 | radio.onReceivedNumber(function (receivedNumber: 69) {
| |
| 59 | csrvrste = 1 | |
| 60 | radio.sendNumber(420) | |
| 61 | }) | |
| 62 | } */ | |
| 63 | //Wall Function | |
| 64 | function mapEdge() {
| |
| 65 | if (globalPlayerX < 3) {
| |
| 66 | basic.plotLeds(` | |
| 67 | # # # # # | |
| 68 | . . . . . | |
| 69 | . . . . . | |
| 70 | . . . . . | |
| 71 | . . . . . | |
| 72 | `) | |
| 73 | } | |
| 74 | if (globalPlayerY < 3) {
| |
| 75 | basic.plotLeds(` | |
| 76 | # . . . . | |
| 77 | # . . . . | |
| 78 | # . . . . | |
| 79 | # . . . . | |
| 80 | # . . . . | |
| 81 | `) | |
| 82 | } | |
| 83 | } | |
| 84 | /*Update Player 2 Positioning | |
| 85 | function plyr2UpdPos() {
| |
| 86 | radio.onReceivedNumber(function (receivedNumber: 0) {
| |
| 87 | plyr2X ++ | |
| 88 | }) | |
| 89 | radio.onReceivedNumber(function (receivedNumber: 1) {
| |
| 90 | plyr2Y ++ | |
| 91 | }) | |
| 92 | radio.onReceivedNumber(function (receivedNumber: 2) {
| |
| 93 | plyr2X -- | |
| 94 | }) | |
| 95 | radio.onReceivedNumber(function (receivedNumber: 3) {
| |
| 96 | plyr2Y -- | |
| 97 | }) | |
| 98 | }*/ | |
| 99 | /*Update plyr2X & Y based on Rotation | |
| 100 | function posUpdByRot() {
| |
| 101 | switch (plyrRot){
| |
| 102 | case 0: | |
| 103 | break | |
| 104 | case 1://Facing Right, plyr2 needs to be on left | |
| 105 | tmp = plyr2X | |
| 106 | tmp1 = plyr2Y | |
| 107 | tmp * -1 | |
| 108 | tmp1 * -1 | |
| 109 | plyr2X = tmp | |
| 110 | plyr2Y = tmp1 | |
| 111 | } | |
| 112 | }*/ | |
| 113 | //Draw Player | |
| 114 | function plyrDraw() {
| |
| 115 | led.plot(localPlayerX, localPlayerY) | |
| 116 | } | |
| 117 | ||
| 118 | //Game itself | |
| 119 | basic.forever(function () {
| |
| 120 | // while (csrvrste = 0) { clientSync }
| |
| 121 | while (csrvrste = 0) {
| |
| 122 | playerRotation() | |
| 123 | playerPositioning() | |
| 124 | plyrDraw() | |
| 125 | basic.pause(frametime) | |
| 126 | basic.clearScreen() | |
| 127 | } | |
| 128 | }) |