frommathimport*fromkandinskyimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromionimport*fromionimportkeydownasKEYfromionimportKEY_LEFTasLEFTfromionimportKEY_RIGHTasRIGHTfromionimportKEY_UPasUPfromionimportKEY_DOWNasDOWNfromrandomimport*fromrandomimportrandintasRfromtimeimport*H=255SW=321SH=222bg=(0,0,0)F(0,0,SW,SH,bg)whilenotKEY(KEY_OK):STR("MAZE ESCAPE",100,10,(R(0,H),R(0,H),R(0,H)),bg)STR("KEYs [Arrow] = 8 Directions",6,70,"white",bg)STR("KEY [OK] = Slow Motion",6,100,"green",bg)STR("KEY [Backspace] = Pause/UnPause",6,130,"gray",bg)STR("( Press OK to Start )",40,200,(0,R(100,H),R(100,H)),bg)board="orange"F(0,0,SW,36,board)p_alive=Truemove=Truebg=(R(100,H),R(100,H),R(100,H))world=1score=0bonus_points=0plife=3px=4py=200pw=8ph=5ptravel=0#leave this
rect_x=300rect_y=0rect_size=0laser_w=10clock=0clock2=9#player
set_pixel(px,py,"blue")set_pixel(rect_x,rect_y,"black")p=(px,py,pw,ph,"blue")defrestart():globalpx,py,pw,ph,bg,plifeplife-=1F(px,py,pw,ph,bg)px=3py=200whilenotKEY(KEY_OK):STR("Press [ok]",100,15)STR("",100,15,"white","white")#generate new_world
defnew_world():globalclock,bg,world,bonus_points,scoreF(0,39,322,222,"black")whilebonus_points<=R(100,300):sleep(0.02)bonus_points+=1STR("World:"+str(world),100,80,"cyan","black")STR("Score: "+str(score),100,120,"white","black")STR("Bonus Points: "+str(bonus_points),70,200,"gray",(0,0,0))score+=1F(0,60,322,2,"cyan")F(0,170,322,2,"cyan")bonus_points=0bg=(R(100,H),R(100,H),R(100,H))F(0,38,322,200,bg)F(317,38,3,222,"blue")foriinrange(10):forjinrange(6):i=R(10,300)j=R(35,222)F(i,j,randint(3,8),randint(5,12),"black")clock+=1ifclock>=0andclock<=27:#horizontal rect
F(R(20,280),R(38,218),R(20,60),20,"black")#parallel rect
F(R(20,310),R(35,180),20,R(20,65),"black")F(0,0,322,2,"black")F(0,38,322,200,bg)F(317,38,3,222,(R(0,H),R(0,H),R(0,H)))foriinrange(10):forjinrange(6):i=R(10,300)j=R(35,222)F(i,j,randint(3,8),randint(5,12),"black")whilep_alive:F(317,38,3,222,(R(0,H),R(0,H),R(0,H)))pw=8ph=5set_pixel(px,py,"blue")STR("World:"+str(world),120,2,"black",board)STR("life "+"\u2248"+str(round(plife)),4,2,(0,0,100),board)STR("time:"+str(int(clock2)),240,2,"white",board)F(0,36,322,3,"black")F(0,219,322,3,"black")ifnotKEY(LEFT):clock2-=0.01clock+=1#laser amount depends on clock
ifclock>=0andclock<=22:#horizontal rect
F(R(20,280),R(38,218),R(20,60),5,"black")#parallel rect
F(R(20,310),R(35,180),8,R(20,65),"black")F(px,py,pw,ph,"blue")F(rect_x,rect_y,rect_size,rect_size,"black")ifKEY(LEFT)andmove:sleep(0.001)score+=R(0,1)px-=1F(px+pw+1,py,1,ph,bg)plife-=0.0001clock2=9ifpx>1:ptravel+=1ifpx<1:px=1ifKEY(KEY_RIGHT)andmove:sleep(0.001)score+=R(0,1)px+=1F(px-1,py,1,ph,bg)plife-=0.0001clock2=9ifpx+pw<321:ptravel+=1ifKEY(KEY_UP)andmove:sleep(0.001)score+=R(0,1)py-=1F(px,py+ph+1,pw,1,bg)plife-=0.0001clock2=9ifpy>37:ptravel+=1ifpy<38:py=38ifKEY(KEY_DOWN)andmove:sleep(0.001)score+=R(0,1)py+=1F(px,py-1,pw,1,bg)plife-=0.0001clock2=9ifpy+ph<222:ptravel+=1ifpy+ph>222:py=222-ph# player loses energy and restarts
ifget_pixel(px,py)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=True#restart()
ifget_pixel(px,py+ph)==get_pixel(rect_x,rect_y)andkeydown(KEY_LEFT):F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=True#restart()
ifget_pixel(px+pw,py)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=True#restart()
ifget_pixel(px+pw,py+ph)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=True#restart()
#player touches laser
ifget_pixel(px+pw,py)==get_pixel(rect_x+5,rect_y):F(px,py,pw,ph,"red")move=Falsesleep(0.1)move=True#restart()
ifKEY(KEY_OK):move=Truesleep(0.05)STR("(slow motion)",2,17,"black",board)else:STR("",2,17,board,board)ifKEY(KEY_BACKSPACE):STR("(PAUSED)",70,17,"black",board)whileKEY(KEY_BACKSPACE):passwhilenotKEY(KEY_BACKSPACE):passwhileKEY(KEY_BACKSPACE):STR("",70,17,board,board)passifpx+pw>318:plife+=1px=4py=200clock=0world+=1new_world()clock2=9ifclock2<1:px=4py=200clock=0new_world()score-=500clock2=9plife-=1ifplife<1:p_alive=FalseifKEY(KEY_TOOLBOX):sleep(0.05)F(px,py,pw,ph,bg)pw=4ph=7else:pw=7ph=4F(px+3,py+1,5,3,(R(0,H),R(0,H),R(0,H)))foriinrange(80):forjinrange(70):i=R(0,321)j=R(0,222)F(i,j,randint(3,9),randint(3,9),choice(["black",(0,0,90)]))STR("GAME OVER",100,70,(255,0,0),(0,0,0))STR("Pixels Traveled:"+str(ptravel),50,120,"cyan",(0,0,0))STR("Score:"+str(ptravel),100,170,"yellow",(0,0,0))
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.