from microbit import * import music # 30.03.2021 - PLAYER MOVEMENT TEST micro:bit AD-BW - DOR # IN STATIONARY GAME POINTS AND LOST LIVES ARE DOUBLED # THIS FINCTIONS ARE FOR SCROLL GAMES MADE pit= bytearray(1) pit[0] = 1 # -- COMMUNICATION - cannot be changed spd = 8 # comm speed min. 8 = start speed / lower spped when you have more data to transfer def ispis(tekst): dd = len(tekst) if dd < 31: salji(tekst) else: salji(tekst[0:30] + "+") salji(tekst[30:dd]) def salji(tekst): global spd duz = len(tekst) buf = bytearray(duz) for n in range(0, duz): bb = ord(tekst[n : n + 1]) buf[n] = bb try: i2c.write(0x11, buf) sleep(duz * spd) except OSError: print("er: send") #----- def trazi(): global pit try: pit = i2c.read(0x11,1) except OSError: print("er: seek") def begin(): ispis("CLS") ispis("START;2;1;2") ispis("G A M E;3;3") sleep(1000) def end(): global pit sleep(100) trazi() ispis("CLS") ispis("E N D;2;1;2") ispis("G A M E;3;3") ispis("Score:"+str(pit[0])+";3;4") while True: sleep(5000) def rest(): global pit ispis("RST") while True: trazi() if pit[0] == 5: break sleep(20) def zvuk(): global pit if pit[0] == 2: music.pitch(1500, 50) ispis("LED;G;10") if pit[0] == 3: music.pitch(800, 100) ispis("LED;R;10") if pit[0] == 4: for freq in range(900, 1200, 30): music.pitch(freq, 8) def getx(): global x global y ispis("GET;X") trazi() x = pit[0] def gety(): global x global y ispis("GET;Y") trazi() y = pit[0] def disxy(): ispis(" ;0;41;G") ispis("x="+str(x)+"-y="+str(y)+";0;41;G") def dodaj(): # added drowings on screen ispis("LIN;0;40;83;40;B") ispis("LIN;0;42;83;42;B") def ek1(): # setup first screen (ekran) ispis("DEL") # delite past objects ispis("CLS") ispis("OBJ;1;2;6;1;1;0") # plus ispis("OBJ;1;3;5;2;1;0") # minus live ispis("OBJ;1;2;0;3;1;0") # plus ispis("OBJ;1;2;4;4;1;0") # plus ispis("OBJ;1;4;9;4;1;0") # exit X ispis("FX;1") # setup forst screen (ekran) dodaj() ispis("POZ;2;2") ispis("BUT;1") # player set on screen def ek2(): # setup second screen (ekran) ispis("DEL") # delite past objects ispis("CLS") ispis("OBJ;1;2;3;1;1;0") # plus ispis("OBJ;1;3;5;2;1;0") # minus live ispis("OBJ;1;2;8;2;1;0") # plus ispis("OBJ;1;2;2;4;1;0") # plus ispis("OBJ;1;4;0;4;1;0") # exit X ispis("FX;1") # setup forst screen (ekran) dodaj() ispis("POZ;2;2") ispis("BUT;1") # player set on screen rest() # reset at start ispis("BIT;1;0;0;0;0;0;0;0;195") ispis("BIT;9;60;126;219;219;255;219;102;255") # player ispis("BIT;2;8;28;54;99;54;28;8;0") # PLUS points ispis("BIT;3;195;219;60;126;126;60;219;195") # minus lives ispis("BIT;4;136;68;34;17;17;34;68;136") # door (DOR) >> begin() ek1() ispis("KOL;1") ispis("BOD;0") # set points 0 ispis("LIV;6") # set lives ispis("DOR") x = 16 y = 16 ek = 2 #spd = 8 # comm speed min. 8 = start speed 8 = working speed while True: ispis("DIS") trazi() #so = pit[0] if pit[0] < 9: p1 = pin1.read_analog() # touch sensor p2 = pin2.read_analog() # touch sensor if button_b.is_pressed(): ispis("BUT;+;X;2") #getx() if button_a.is_pressed(): ispis("BUT;-;X;2") #getx() if p2 > 240 or p2 < 230: ispis("BUT;-;Y;2") #gety() if p1 > 240 or p1 < 230: ispis("BUT;+;Y;2") #gety() zvuk() else: sleep(200) end() if pit[0] == 8: x = 16 y = 16 if ek == 2: ek2() # setup second screen (ekran) ek = 1 else: ek1() # setup first screen (ekran) ek = 2