from microbit import * import music # 29.08.2020 - PLAYER MOVEMENT TEST micro:bit AD-BW pit= bytearray(1) pit[0] = 1 def ispis(tekst): dd = len(tekst) if dd < 31: salji(tekst) else: salji(tekst[0:30]+"+") salji(tekst[30:dd]) def salji(tekst): 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*4) except OSError: print("er: salji") def trazi(): global pit try: pit = i2c.read(0x11,1) except OSError: print("er: trazi") 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) if pit[0] == 3: music.pitch(800, 100) if pit[0] == 4: for freq in range(900, 1200, 30): music.pitch(freq, 8) def prikaz(): global pit if pit[0] == 8: # id_ok = 8 dodaj() def dodaj(): # added drowings on screen ispis("LIN;40;0;40;48;C") ispis("LIN;0;40;83;40;C") ispis("IDO;1") # id_ok to 1 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;255;255;129;255;255;129;255;255") # wall ispis("BIT;5;0;66;36;24;24;36;66;0") # door (DOR) ispis("OBJ;1;2;6;1;3") # plus ispis("OBJ;1;2;5;1;1") # plus ispis("OBJ;1;3;4;1;2") # minus live ispis("OBJ;1;5;7;1;2") # vrata desno lijevo 5 ispis("OBJ;1;2;3;1;4") # plus #ispis("GRV;1") # 0 off ispis("PAD;0") # 0 fall = rotation, 1 = dead ispis("POZ;2;2") begin() ispis("CLS") ispis("FX;1") # setup forst screen (ekran) ispis("DIS") ispis("BUT") ispis("BOD;0") # set points 0 ispis("LIV;2") # set lives ispis("DOR") # door setup (bitmap 5) pit[0] == 8 dodaj() x = 25 y = 0 while True: trazi() 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") if button_a.is_pressed(): ispis("BUT;-;X;2") if p2 > 240 or p2 < 230: ispis("BUT;-;Y;2") if p1 > 240 or p1 < 230: ispis("BUT;+;Y;2") ispis("BUT;1") ispis("BUT;0") zvuk() prikaz() else: sleep(200) end()