frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*txt=(randint(200,255),randint(200,255),randint(200,255))bg=(randint(0,50),randint(0,50),randint(0,50))fill_rect(0,0,322,222,bg)clock=0whilenotkeydown(KEY_OK):clock+=0.40ifclock<1:foriinrange(20):forjinrange(20):i=randint(0,321)j=randint(0,20)k=randint(0,321)l=randint(150,222)fill_rect(i,j,randint(20,50),randint(20,70),choice(["red","black"]))fill_rect(k,l,randint(20,50),randint(20,70),choice(["red","black"]))draw_string("G-22 Raptor",100,110,txt,bg)startimer=0#amount of stars
nb=randint(20,60)st=[0]*nbpr=[0]*nb#background maybe eraser
NR="black"defpoint():return[randrange(320),0,randrange(1,10)]foriinrange(nb):st[i]=point()fill_rect(0,0,320,222,NR)#color definitions via RGB Decimal
BLACK=(0,)*3RED=(255,0,0)DARK_RED=(125,0,0)WHITE=(255,)*3BLUE=(0,0,255)YELLOW=(255,255,0)MAGENTA=(255,0,255)GREEN=(0,255,0)BLACK=(0,)*3CYAN=(0,255,255)world=1#bg=WHITE
game=Truepsc=0pl=3pe=30px=10py=100pw=9ph=5pc=WHITE#dark matter
mx=randint(350,500)my=randint(30,100)mw=randint(20,50)mh=randint(30,70)mc=(randint(0,55),randint(0,55),randint(0,55))enemies_destroyed=0et=0efast=False#enemy energy
ee=5ex=280ey=100ew=15eh=15ec=(randint(0,255),randint(0,255),randint(0,255))fill_rect(0,0,322,222,bg)#ceiling
foriinrange(0,322):i+=1fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(125,0,0),(0,0,0),"red"]))#ground
foriinrange(0,322):i+=1lava_y=randint(180,210)fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(0,0,0),(120,0,0)]))fill_rect(0,0,322,22,(0,0,0))#main loop
whilegame:#enemy random speedup
et+=0.01ifet>randint(2,5):et=0efast=choice([0,1,1])draw_string("| World:"+str(world)+" |",108,2,bg,BLACK)draw_string("Player[",5,0,CYAN,BLACK)fill_rect(73,4,round(pe/3),11,pc)fill_rect(px,py,pw,ph,pc)fill_rect(px+4,py+1,4,2,CYAN)draw_string("Enemy[",240,0,"green",(0,0,0))fill_rect(298,4,round(ee),11,RED)#moving aircraft
ex-=1fill_rect(ex,ey,5,3,ec)fill_rect(ex-5,ey+5,5,3,ec)fill_rect(ex,ey+10,5,3,ec)#erase spacecraft trail
fill_rect(ex+6,ey,5,3,bg)fill_rect(ex+1,ey+5,5,3,bg)fill_rect(ex+6,ey+10,5,3,bg)fill_rect(ex-5,ey+5,5,3,"red")#rects reach left
ifex<-randint(10,30):ee=randint(5,10)fill_rect(258,4,round(ee)+10,11,BLACK)ex=randint(250,350)ey=randint(37,170)ec=(randint(0,255),randint(0,255),randint(0,255))pe-=randint(3,5)fill_rect(73+int(pe/3),4,2,11,BLACK)fill_rect(px,py,pw,ph,RED)#[0,0,1] is a choice list of True or False
efast=choice([0,0,1])et=0foriinrange(0,322):i+=1lava_y=randint(180,210)fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(120,0,0),(0,0,0)]))#player shoots
ifkeydown(KEY_OK):fill_rect(px+pw-2,py,2,ph,"red")fill_rect(px+pw,py+1,322-px,3,(randint(100,255),randint(100,255),randint(100,255)))sleep(0.001)fill_rect(px+pw,py+1,322-px,3,bg)ifkeydown(KEY_LEFT):px-=1fill_rect(px+pw,py,1,ph,bg)ifkeydown(KEY_RIGHT):px+=1fill_rect(px-1,py,1,ph,bg)ifkeydown(KEY_RIGHT):px+=1fill_rect(px-1,py,1,ph,bg)ifkeydown(KEY_UP):py-=1fill_rect(px,py+ph,pw,1,bg)ifkeydown(KEY_DOWN):py+=1fill_rect(px,py-1,pw,1,bg)#enemy is hit.
ifkeydown(KEY_OK)andpy+1>=eyandpy+1<=ey+ehandpx+pw<=ex+ew:fill_rect(298,2,25,15,BLACK)foriinrange(randint(2,10)):forjinrange(randint(2,10)):i=ex+randint(0,7)j=ey+randint(0,7)fill_rect(i,j,randint(2,5),randint(2,5),choice([CYAN,BLACK,bg,ec]))fill_rect(258,4,round(ee),11,BLACK)ee-=0.06psc+=randint(2,5)pe+=0.02#enemy destroyed
ifee<1:ee=randint(4,12)ex=randint(250,500)ey=randint(37,170)ec=(randint(0,255),randint(0,255),randint(0,255))enemies_destroyed+=1pe+=3pc=(randint(50,200),randint(50,200),randint(50,200))psc+=randint(10,20)ifenemies_destroyed>randint(5,15):enemies_destroyed=0ee=randint(4,12)ex=randint(250,500)ey=randint(37,170)ec=(randint(0,255),randint(0,255),randint(0,255))bg=(randint(0,255),randint(0,255),randint(0,255))fill_rect(0,23,322,222,bg)pe+=3pc=(randint(50,200),randint(50,200),randint(50,200))psc+=randint(10,20)world+=1#ceiling
foriinrange(0,322):i+=1fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))#bottom/ ground
foriinrange(0,322):i+=1lava_y=randint(180,210)fill_rect(i,lava_y,randint(2,5),200,choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))#player crashes into ceiling
ifpy<=36:py=randint(35,36)pe-=2fill_rect(73+int(pe/3),4,2,11,BLACK)fill_rect(px,py,pw,ph,RED)foriinrange(0,322):i+=1fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))#player crashes into ground
ifpy>=180:py=randint(179,180)pe-=2fill_rect(73+int(pe/3),4,2,11,BLACK)fill_rect(px,py,pw,ph,RED)foriinrange(0,322):i+=1lava_y=randint(180,210)fill_rect(i,lava_y,randint(2,5),200,choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))ifpx<1:px=1ifpx+pw>322:px=322-pwifpe<1:game=False#pause game
ifkeydown(KEY_BACKSPACE):draw_string("(PAUSED)",110,100,(randint(0,255),randint(0,255),randint(0,255)),bg)whilekeydown(KEY_BACKSPACE):passwhilenotkeydown(KEY_BACKSPACE):passwhilekeydown(KEY_BACKSPACE):draw_string("",110,100,bg,bg)pass#player low on energy
ifpe<20:fill_rect(px,py+ph,1,1,choice([(120,0,0),(255,0,0),bg,"black"]))fill_rect(px,py-1,pw,1,bg)py+=randint(0,1)ifefast:foriinrange(randint(1,3)):ex-=1fill_rect(ex+ew,ey,2,eh,bg)startimer+=0.1ifstartimer>randint(3,7):startimer=0foriinrange(nb):st[i][1]+=randrange(1,int(50/st[i][2]))z=st[i][2]Sx=st[i][0]Sy=min(240,st[i][1])ifSy>=240:st[i]=point()ifpr[i]!=0:set_pixel(pr[i][0],pr[i][1],bg)pr[i]=[int(Sx),int(Sy)]r=randint(0,200)g=randint(0,200)b=randint(0,200)set_pixel(pr[i][0],pr[i][1],color(r,g,b))fill_rect(mx,my,mw,mh,mc)fill_rect(mx+mw+1,my,1,mh,bg)mx-=1ifmx+mw<0-randint(10,20):mx=randint(400,600)mw=randint(20,50)mh=randint(30,100)my=randint(30,180-mh)mc=(randint(0,55),randint(0,55),randint(0,55))ifpx+pw>=mxandpx<=mxandpy+ph>=myandpy<=my+mh:px-=1pe-=0.5fill_rect(0,0,322,20,bg)fill_rect(px,py,pw,ph,"red")ifpx>=mxandpx+pw<=mxandpy>=myandpy+ph<=my+mh:px=mx+mw+2pe-=0.2#game over
draw_string("GAME OVER",100,100,choice(["black","cyan","white"]),bg)draw_string("SCORE:"+str(psc),100,140,choice(["gray","green","yellow"]),bg)
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.