fromkandinskyimport*fromrandomimportrandintasrfromrandomimportchoicefromtimeimportsleepfrommathimportsqrtfromionimportkeydowncarte=[[0]*32foriinrange(20)]# 640 tiles to explore
col={"b":(248,248,248),"ui":(148,113,222),"p":(42,142,242),"h":(242,160,176),"w":(40,200,140),"l":(163,22,33)}p={"x":1,"y":5,"vie":3,"level":False}#Player
game={"L":1,"R":6,"E":0}# Level Radar EMP
w={"x":0,"y":0,"e":0,"v":0}#win, bonus
defwait(keys=(0,1,2,3,4,52)):# input keyboard
whileTrue:forkinkeys:ifkeydown(k):whilekeydown(k):Truereturnkdefreset():foryinrange(0,20,1):forxinrange(0,32,1):ifx==0orx==31ory==0ory==19:carte[y][x]=666else:carte[y][x]=0defmine():reset()m=22whilem>0:y,x=r(2,18),r(2,29)ifcarte[y][x]!=666:carte[y][x]=666m-=1n=10*game["L"]-30whilen>0:y,x=r(1,18),r(2,29)ifcarte[y][x]!=666andcount(y,x)>0:carte[y][x]=666n-=1y,x=r(1,18),1p["x"],p["y"],=1,ycarte[y][x]=0x,y=r(10,42),choice((0,19))ifx>=28:x,y=31,r(3,17)carte[y][x]=42w["x"],w["y"]=x,ydefbonus():w["e"],w["v"]=r(1,5-game["L"]//10),r(1,5-game["L"]//8)t,e,v=0,w["e"],w["v"]whilet<1000and(e>0orv>0):y,x=r(1,18),r(2,29)ife>0andcount(y,x)==0andcarte[y][x]==0:carte[y][x]=2e-=1elifv>0andcount(y,x)==0andcarte[y][x]==0:carte[y][x]=1v-=1w["e"],w["v"]=w["e"]-e,w["v"]-vdefcount(y,x):"""Number of bombs in the neighborhood"""b=0foriinrange(-1,2,1):forjinrange(-1,2,1):ifx+i<0orx+i>31ory+j<0ory+j>19:b+=1if0<=x+i<=31and0<=y+j<=19andcarte[y+j][x+i]==666:b+=1returnbdefui():fill_rect(0,200,320,22,(148,113,222))draw_string("nsi.xyz/escape",10,202,(242,)*3,(148,113,222))stats()draw_heart(27,20.7)defstats():txt=""forkingame.keys():txt+=k+str(game[k])+""draw_string(txt,270-10*len(txt),202,col["b"],col["ui"])draw_string(str(p["vie"])+"",285,202,col["b"],col["ui"])defdraw_heart(x,y):"""heart Pixel Art 10x10"""xi,yi=0,0fori,jinenumerate((1,2,3,2,3,3,1,4,1,39,2,8,3,6,5,4,7,2)):#heart
whilej>0:ifi%2==1:fill_rect(int(10*x)+(xi%10),int(10*y)+yi,1,1,col["h"])xi,yi,j=xi+1,(xi+1)//10,j-1defdraw_emp(x,y):"""Plus sign Pixel Art 10x10"""fill_rect(int(x*10+4),int(y*10+2),2,6,col["w"])fill_rect(int(x*10+2),int(y*10+4),6,2,col["w"])defdraw_robot(x,y):"""Robot head Pixel Art 10x10"""fill_rect(x*10,y*10,10,10,col["p"])fill_rect(x*10+2,y*10+2,2,2,col["b"])fill_rect(x*10+6,y*10+2,2,2,col["b"])fill_rect(x*10+2,y*10+6,6,2,col["b"])fill_rect(x*10+4,y*10+6,2,1,col["p"])defgo(y,x):"""Darken each square and move the player"""p["x"],p["y"]=x,yifx<0orx>31ory<0ory>19:returnrestart()elifcarte[y][x]==666:carte[y][x]=0p["vie"]-=1stats()ifp["vie"]==0:p["level"]=Truestats()elifcarte[y][x]==42:returnwin()elifcarte[y][x]==1:carte[y][x]=0p["vie"]+=1elifcarte[y][x]==2:carte[y][x]=0game["E"]+=1radar()forx0inrange(32):fory0inrange(20):ifdistance(x,y,x0,y0)>game["R"]+0.49anddistance(x,y,x0,y0)<22:# (x0,y0) != (x,y)
g=get_pixel(10*x0,10*y0)[0]ifg!=0:c=max(0,g-16)fill_rect(x0*10,y0*10,10,10,(c,c,c))defradar(d=1):x,y=p["x"],p["y"]foriinrange(-d,d+1,1):forjinrange(-d,d+1,1):ifi==0andj==0:draw_robot(x,y)elifdistance(i,j)<=d+0.5and0<=y+j<20and0<x+i<32:c=248-24*count(y+j,x+i)fill_rect((x+i)*10,(y+j)*10,10,10,(c,c,c))ifcarte[y+j][x+i]==2:draw_emp(x+i,y+j)ifcarte[y+j][x+i]==1:draw_heart(x+i,y+j)out()defout():"If the exit is within a reasonable distance from the player it is displayed"# w["x"], w["y"]
ifdistance(w["x"],w["y"],p["x"],p["y"])<=game["R"]+1.9:fill_rect(w["x"]*10,w["y"]*10,10,10,col["w"])defrestart():p["vie"]-=1p["level"]=Truedefwin():p["vie"]=p["vie"]+1p["level"]=Truegame["L"]+=1defemp(d=1):game["E"]-=1forxinrange(-d,d+1,1):foryinrange(-d,d+1,1):xe,ye=p["x"]+x,p["y"]+yifdistance(x,y)<d+0.5and0<xe<31and0<ye<19andcarte[ye][xe]notin{42,1}:carte[ye][xe]=0radar(max(game["R"],d)+3)definit():fill_rect(0,0,320,200,(0,0,0))game["R"]=max(2,5-game["L"]//8)# Radar range
game["E"]=max(game["E"],min(game["L"],9))# EMP count
mine()bonus()ui()radar(game["R"])level()defdistance(a,b,c=0,d=0):returnsqrt((a-c)**2+(b-d)**2)deflevel():n=game["L"]end=Falseifn==43orp["vie"]<1:end=Trueui,b=col["ui"],col["b"]fill_rect(80,40,160,120,ui)draw_string("EXPLORE ESCAPE",90,50,b,ui)draw_string("lvl "+str(min(n,42)),90+40*(not9<n<31),80,b,ui)if9<n<31:draw_string(str(bin(w["x"]))[1:],170,80,b,ui)ifnotend:draw_string(str(w["e"])+" XMP Bonus",90,110,b,ui)draw_string(str(w["v"])+" life Bonus",90,130,b,ui)draw_heart(10.5,13.3)draw_emp(10.5,11.3)wait()fill_rect(80,40,160,120,(0,0,0))elifn==43:draw_string("GAME COMPLETE",90,120,b,ui)q()else:draw_string("GAME OVER",110,120,b,ui)q()defq():wait()p["vie"]=-1whilep["vie"]>-1:p["level"]=Falseinit()whilenotp["level"]andp["vie"]>0:k=wait()ifk==4ork==52:ifgame["E"]>0:emp(int(-0.00657*game["L"]**2+0.27619*game["L"]+2.1))else:go(p["y"]-1*(k==1)+1*(k==2),p["x"]-1*(k==0)+1*(k==3))radar(game["R"])stats()
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.