from microbit import * import music # PLATFORM game 29.08.2020 - TEST GAME FOR micro:bit AD-BW # PLATFORM GAME - OS GAME v07 pit = bytearray(1) pit[0] = 1 sleep(2000) # -- COMMUNICATION - cannot be changed 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 rest(): global pit ispis("RST") while True: trazi() if pit[0] == 5: break sleep(20) # START SCREEN - user can change def begin(): ispis("CLS") ispis("START;2;1;2") ispis("G A M E;3;3") sleep(1000) # END SCREEN - user can change 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) # SOUND EFFECTS - user can change def zvuk(): global pit if pit[0] == 2: # POINT music.pitch(1500, 50) if pit[0] == 3: # LIFE music.pitch(800, 100) if pit[0] == 4: # FALL for freq in range(900, 1200, 30): music.pitch(freq, 8) rest() # reset at start # BITMAPS - - user can change ispis("BIT;9;60;126;219;219;255;219;102;255") # map 9 - player bitmap ispis("BIT;2;8;28;54;99;54;28;8;0") # map 2 + point bitmap ispis("BIT;3;195;219;60;126;126;60;219;195") # map 3 - minus live bitmap ispis("BIT;4;255;129;255;129;255;129;255;0") # map 4 - wall # screen definitions - objects setup # screen 1 ispis("OBJ;1;3;9;1;1") # MAP 3,x,length,y ispis("OBJ;1;2;7;1;3") # MAP 2 ispis("OBJ;1;4;1;5;3") # MAP 4 ispis("OBJ;1;4;7;3;4") ispis("OBJ;1;4;3;4;5") # screen 2 ispis("OBJ;2;2;1;1;1") ispis("OBJ;2;3;9;1;2") ispis("OBJ;2;4;1;4;4") ispis("OBJ;2;4;6;3;3") ispis("OBJ;2;4;6;4;5") ispis("OBJ;2;4;1;3;0") ispis("OBJ;3;4;5;5;0") ispis("OBJ;3;3;6;1;1") # screen 3 ispis("OBJ;3;2;6;1;2") ispis("OBJ;3;4;0;3;3") ispis("OBJ;3;4;8;3;4") ispis("OBJ;3;4;3;6;5") ispis("GRV;1") # gravity 0 = no, 1 = yes ispis("PAD;1") # fall 0 = rotate, 1 = dead begin() # start screen ispis("CLS") # clear screen ispis("BOD;0") # start points ispis("LIV;5") # start lives ispis("POZ;4;0") # player start postition x,y ispis("SPD;30;1") # scroll speed ( max 20 ), number of pixel scroll movement # ispis("RND;1") # random redosljed ekrana 0 / 1 - ne radi jos sleep(100) # ispis("LVL;20;40;10;5") # auto levels - max speed, poc start speed, change -, points for level change ispis("FX;1") # set screen 1 ispis("ASD;1") # auto scroll 1 = on, 0 = off sleep(100) x = 25 y = 0 while True: if pit[0] != 9: trazi() if button_b.is_pressed(): ispis("JMP;4") if button_a.is_pressed(): ispis("JMP;12") zvuk() sleep(100) # mora biti else: sleep(200) end()