from microbit import * import music # PLATFORM game 30.03.2021 - TEST GAME FOR micro:bit AD-BW # METEORS - OS GAME v07 pit= bytearray(1) pit[0] = 1 sleep(3000) # -- COMMUNICATION - cannot be changed spd = 8 # comm speed min. 4 - max. speed 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: 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) 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) rest() # reset at start ispis("BIT;9;248;124;60;127;127;60;124;248") # player - plain ispis("BIT;2;8;28;54;99;54;28;8;0") # + point object ispis("BIT;1;60;126;255;255;255;255;126;60") # stone ispis("BIT;3;60;126;231;195;195;231;126;60") # meteor ( - live object ) # objects on displays ispis("OBJ;1;2;6;4;1;0") # ekran 1 / bitmap,x,length,y ispis("OBJ;1;3;7;3;1;0") ispis("OBJ;1;3;1;3;1;0") ispis("OBJ;1;2;5;1;1;0") ispis("OBJ;1;3;3;5;1;0") ispis("OBJ;1;1;3;4;2;0") ispis("OBJ;2;3;1;1;1;0") # ekran 2 ispis("OBJ;2;2;8;2;1;0") ispis("OBJ;2;3;4;0;1;0") ispis("OBJ;2;3;7;3;1;0") ispis("OBJ;2;2;6;5;1;0") ispis("OBJ;2;1;1;2;2;0") ispis("OBJ;3;2;5;5;1;0") # ekran 3 ispis("OBJ;3;3;6;2;1;0") ispis("OBJ;3;3;4;3;1;0") ispis("OBJ;3;2;6;4;1;0") ispis("OBJ;3;3;3;1;1;0") ispis("OBJ;3;1;7;5;2;0") ispis("GRV;0") # gravity 0 = no, 1 = yes ispis("PAD;0") # fall 0 = rotate, 1 = dead begin() # start screen ispis("CLS") ispis("BOD;0") # bod 0 ispis("LIV;5") # lives ispis("POZ;4;0") # player start postition ispis("SPD;30;1") # scroll speed ( max ) ( SPD or LVL ) #ispis("LVL;20;40;10;5") # auto levels - max speed, start speed, level speed change -, points needed for new level ispis("FX;1") # set ekran 1 ispis("KOL;1") # set colision on ispis("ASD;1") # auto scroll 1 = on, 0 = off #ispis("BUT;1") #first player pix move x = 25 y = 0 while True: if pit[0] != 9: trazi() if button_b.is_pressed(): ispis("BUT;+;Y;2"); if button_a.is_pressed(): ispis("BUT;-;Y;2"); zvuk() sleep(20) # must be 20 or > else: sleep(200) end()