Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Variable initialization so i don't have to do it later
- let plyrRot = 0
- let localPlayerX = 2
- let localPlayerY = 2
- let globalPlayerX = 2
- let globalPlayerY = 2
- let plyr2X = 0
- let plyr2Y = 0
- let csrvrste = 0
- let tmp = 0
- let tmp1 = 0
- let mapSize = 7
- let frametime = 200 /*frametime defines how long
- until the clear function will allow the next frame
- to be processed and drawn. */
- /*Alright so the map is going to be 25x25 when finished
- Map edges will be defined by walls*/
- //Function Library :p
- //Most functions are commented out currently until the finished
- //product is created. Most functions require having a physical
- //micro:bit for testing both client and server scripts.
- //Player Rotation control
- function playerRotation() {
- if (input.compassHeading() > 0 && input.compassHeading() < 90) { plyrRot = 0 }
- if (input.compassHeading() > 90 && input.compassHeading() < 180) { plyrRot = 1 }
- if (input.compassHeading() > 180 && input.compassHeading() < 270) { plyrRot = 2 }
- if (input.compassHeading() > 270 && input.compassHeading() < 361) { plyrRot = 3 }
- }
- //Player Positioning based on input from the playerRotation function
- function playerPositioning() {
- if (input.buttonIsPressed(Button.A)) {
- switch (plyrRot) {
- case 0:
- globalPlayerX && localPlayerX++
- break;
- case 1:
- globalPlayerY && localPlayerY++
- break
- case 2:
- globalPlayerX && localPlayerX--
- break
- case 3:
- globalPlayerY && localPlayerY--
- break
- }
- }
- if (globalPlayerX = 1) { localPlayerX = globalPlayerX }
- if (globalPlayerX > 1) { localPlayerX = 2 }
- if (globalPlayerY = 1) { localPlayerY = globalPlayerY }
- if (globalPlayerY > 1) { localPlayerY = 2 }
- }
- /*Waiting for connection request from client
- function clientSync() {
- radio.onReceivedNumber(function (receivedNumber: 69) {
- csrvrste = 1
- radio.sendNumber(420)
- })
- } */
- //Wall Function
- function mapEdge() {
- if (globalPlayerX < 3) {
- basic.plotLeds(`
- # # # # #
- . . . . .
- . . . . .
- . . . . .
- . . . . .
- `)
- }
- if (globalPlayerY < 3) {
- basic.plotLeds(`
- # . . . .
- # . . . .
- # . . . .
- # . . . .
- # . . . .
- `)
- }
- }
- /*Update Player 2 Positioning
- function plyr2UpdPos() {
- radio.onReceivedNumber(function (receivedNumber: 0) {
- plyr2X ++
- })
- radio.onReceivedNumber(function (receivedNumber: 1) {
- plyr2Y ++
- })
- radio.onReceivedNumber(function (receivedNumber: 2) {
- plyr2X --
- })
- radio.onReceivedNumber(function (receivedNumber: 3) {
- plyr2Y --
- })
- }*/
- /*Update plyr2X & Y based on Rotation
- function posUpdByRot() {
- switch (plyrRot){
- case 0:
- break
- case 1://Facing Right, plyr2 needs to be on left
- tmp = plyr2X
- tmp1 = plyr2Y
- tmp * -1
- tmp1 * -1
- plyr2X = tmp
- plyr2Y = tmp1
- }
- }*/
- //Draw Player
- function plyrDraw() {
- led.plot(localPlayerX, localPlayerY)
- }
- //Game itself
- basic.forever(function () {
- // while (csrvrste = 0) { clientSync }
- while (csrvrste = 0) {
- playerRotation()
- playerPositioning()
- plyrDraw()
- basic.pause(frametime)
- basic.clearScreen()
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment