frommathimport*fromkandinskyimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromionimport*fromionimportkeydownasKEYfromionimportKEY_LEFTasLEFTfromionimportKEY_RIGHTasRIGHTfromionimportKEY_UPasUPfromionimportKEY_DOWNasDOWNfromrandomimport*fromrandomimportrandintasRfromtimeimport*H=255SW=321SH=222bg=(40,0,60)F(0,0,SW,SH,bg)#left line
F(0,0,2,222,"cyan")#right line
F(319,0,2,222,"cyan")#top line
F(0,0,322,3,"cyan")#bottom line
F(0,219,322,3,"cyan")whilenotKEY(KEY_OK)andnotKEY(KEY_EXE):F(0,35,322,3,"cyan")STR("MAZE ESCAPE",100,10,"white",bg)STR("KEYs [Arrow] = 8 Directions",6,70,"white",bg)STR("KEY [OK] = Slow Motion",20,100,"yellow",bg)STR("KEY [Backspace] = Pause/UnPause",6,130,"gray",bg)STR("KEY [Toolbox] = fire laser",20,170,"green",bg)STR("( Press [OK],[EXE] to Start )",20,200,"white",bg)board="cyan"F(0,0,SW,36,board)p_alive=Truemove=Truebg=(R(0,H),R(0,H),R(0,H))world=1score=0bonus_points=0plife=3px=2py=180pw=7ph=6ptravel=0#leave this
rect_x=300rect_y=0rect_size=0laser_w=10clock=R(2,5)clock2=9#player
set_pixel(px,py,"blue")#rects
set_pixel(rect_x,rect_y,"black")p=(px,py,pw,ph,"blue")#generate new_world
defnew_world():globalbg,clock,fuel_x,fuel_yfuel_x=R(5,300)fuel_y=R(40,200)ammo_x=R(5,300)ammo_y=R(40,200)F(0,39,322,222,(50,20,70))sleep(0.2)whilenotkeydown(KEY_OK):STR("Maze Escaped!",100,80,"cyan",(50,20,70))STR("( Press [OK] to continue )",50,140,"white",(50,20,70))F(0,60,322,2,"red")F(0,180,322,2,"red")bg=(R(10,H),R(10,H),R(10,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)#this may be width of parallel rects
F(i,j,randint(4,7),randint(9,25),"black")clock+=1F(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")ammo_amount=3ammo_x=R(5,300)ammo_y=R(40,200)ammo_w=5ammo_h=8ammo_c="red"fuel_clock=0fuel_x=R(5,300)fuel_y=R(40,200)fuel_w=6fuel_h=6fuel_c="white"#main loop
whilep_alive:clock+=1F(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("Ammo:"+str(round(ammo_amount)),240,2,(0,0,80),board)F(0,36,322,3,"black")F(0,219,322,3,"black")ifnotKEY(LEFT):clock2-=0.01#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(px,py,1,ph,"cyan")F(px+pw-1,py,1,ph,"cyan")F(px,py,pw,1,"cyan")F(px,py+ph-1,pw,1,"cyan")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
ifget_pixel(px,py)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.08move=Falsesleep(0.1)move=Trueifget_pixel(px,py+ph)==get_pixel(rect_x,rect_y):# and keydown(KEY_LEFT):
F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=Trueifget_pixel(px+pw,py)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.03move=Falsesleep(0.1)move=Trueifget_pixel(px+pw,py+ph)==get_pixel(rect_x,rect_y):F(px,py,pw,ph,"red")plife-=0.05move=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#///////////////////////////
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=2py=180#clock fr rect amount
clock=R(1,3)world+=1new_world()clock2=9ifclock2<1:clock2=9# amount of rects are
# added based
# on clock value
# the higher the range in
# clock (below), the less
# rects are added.
clock=R(6,17)F(px,py,pw,ph,"red")sleep(0.4)F(px,py,pw,ph,bg)sleep(0.4)ifplife<=0:p_alive=FalseF(px,py,pw,ph,"red")F(px+3,py+1,5,3,(R(0,H),R(0,H),R(0,H)))#fuel box
F(fuel_x,fuel_y,fuel_w,fuel_h,fuel_c)#outline just for looks
F(fuel_x,fuel_y,1,fuel_h,"blue")F(fuel_x+fuel_w-1,fuel_y,1,fuel_h,"blue")F(fuel_x,fuel_y,fuel_w,1,"blue")F(fuel_x,fuel_y+fuel_h-1,fuel_w,1,"blue")#ammo box
F(ammo_x,ammo_y,ammo_w,ammo_h,ammo_c)#outline just for looks
F(ammo_x,ammo_y,1,ammo_h,"blue")F(ammo_x+ammo_w-1,ammo_y,1,ammo_h,"blue")F(ammo_x,ammo_y,ammo_w,1,"blue")F(ammo_x,ammo_y+ammo_h-1,ammo_w,1,"blue")#player gets ammo
ifpx+pw>=ammo_xandpx<=ammo_x+ammo_wandpy+ph>=ammo_yandpy<=ammo_y+ammo_h:F(ammo_x,ammo_y,ammo_w,ammo_h,bg)sleep(0.4)F(px,py,pw,ph,"purple")ammo_x=R(5,300)ammo_y=R(40,200)ammo_amount+=7ifammo_amount>20:ammo_amount=20#player gets energy
ifpx+pw>=fuel_xandpx<=fuel_x+fuel_wandpy+ph>=fuel_yandpy<=fuel_y+fuel_h:F(fuel_x,fuel_y,fuel_w,fuel_h,bg)sleep(0.4)F(px,py,pw,ph,"cyan")fuel_x=R(5,300)fuel_y=R(40,200)plife+=1ifkeydown(KEY_TOOLBOX):ammo_amount-=0.6F(220,2,95,22,"cyan")ifammo_amount<0:ammo_amount=0ifammo_amount>0:F(px+pw+5,py+1,32,2,choice(["white","cyan"]))sleep(0.03)F(px+pw+5,py+1,32,2,bg)F(px,py,pw,ph,"red")sleep(2)#game over
sx=450F(0,0,322,222,(0,0,0))draw_string("Written by: Wilson",11,7,"white","black")whileplife<0andnotkeydown(KEY_OK):F(0,1,322,5,"cyan")F(0,217,322,5,"cyan")F(0,0,5,222,"cyan")F(316,0,5,222,"cyan")sleep(0.05)sx-=8ifsx<170:sx=170draw_string("GAME OVER",100,80,(randint(100,255),0,randint(0,55)),"black")draw_string("SCORE:",100,120,"orange","black")draw_string(str(score)+"",sx,120,"cyan","black")ifworld>1:draw_string("Worlds Survived: "+str(world-1),60,160,"gray","black")else:draw_string("Worlds Survived: "+str(0),60,160,"gray","black")draw_string("You need more practice",40,190,"white","black")
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.