from microbit import * import music # 2.04.2021 # -- COMMUNICATION - cannot be changed pit= bytearray(1) pit[0] = 1 spd = 8 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") # -- COMMUNICATION --- end def trazi(): global pit try: pit = i2c.read(0x11,1) except OSError: print("er: seek") # -- def rest(): global pit ispis("RST") while True: trazi() if pit[0] == 5: break sleep(20) # -- def begin(): ispis("CLS") ispis("START;2;1;2") ispis("G A M E;3;3") sleep(1000) ispis("CLS") # -- 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 zvuk(): global pit if pit[0] == 2: # POINT music.pitch(1500, 50) ispis("LED;G;30") if pit[0] == 3: # LIFE music.pitch(800, 100) ispis("LED;R;30") if pit[0] == 4: # FALL for freq in range(900, 1200, 30): music.pitch(freq, 8) # -- rest() begin() ispis("BIT;1;255;153;189;231;231;189;153;255") ispis("BIT;2;102;255;255;255;255;126;60;24") ispis("BIT;3;60;60;219;255;255;219;60;60") ispis("BIT;8;60;66;165;153;66;255;231;0") # player anima ispis("BIT;9;0;0;60;66;165;153;66;255") # player ispis("OBJ;1;1;0;4;10") ispis("OBJ;1;2;4;3;1") ispis("OBJ;1;3;6;3;1") ispis("OBJ;2;1;0;2;5") ispis("OBJ;2;1;6;3;4") ispis("OBJ;2;2;6;2;1") ispis("OBJ;2;3;3;1;1") ispis("FX;1") ispis("POZ;4;0") ispis("ANI;3") ispis("KOL;1") ispis("GRV;1") ispis("ASD;1") ispis("SPD;50;1") ispis("PAD;1") ispis("BOD;0") ispis("LIV;5") spd = 4 while True: if button_a.is_pressed(): ispis("JMP;15;-;2") if button_b.is_pressed(): ispis("JMP;15;+;2") sleep(100) trazi() if pit[0] != 9: zvuk() else: sleep(300) end()