frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromrandomimportrandintasRfromionimportkeydownasK#just plug in the RGB Tuples to save space
H=255r=R(0,H)g=R(0,H)b=R(0,H)#random tuple
RAND=(R(0,H),R(0,H),R(0,H))cyan=(0,H,H)red=(H,0,0)dark_red=(135,0,0)dark_green=(0,135,0)white=(H,H,H)black=(0,0,0)green=(0,H,0)blue=(0,0,H)SW=322SH=222world_count=0world=1game=Truebg=(R(0,H),R(0,H),R(0,H))#player
pdir=0psc=0pe=9pl=3pc=blue#enemy
ee=R(6,15)edash=Falseet=0echase=Falseedir=0jump,count,L_jump=False,0,[int(-0.4*(x/4)**2+70)forxinrange(-52,52)]+[0]#player the size or width
side=17#player x
x=15#grd height
y_floor=R(120,180)eh=R(20,40)ec=(R(0,H),R(0,H),R(0,H))ex=R(300,400)ey=y_floor-ehew=R(15,30)y=y_floor-sidedr=Falsedrx=280dry=y_floor-28drw=22drh=28score=0L_bullets=[]#width and height of bullets
w_bullet=8h_bullet=6#velocity of bullets
v_bullet=4offset=0cherbe=(R(0,H),R(0,H),R(0,H))cgrd1=(R(50,H),R(50,H),R(50,H))cgrd2=(R(0,H),R(0,H),R(0,H))#ground
ccarre=bluedefpause():STR("(PAUSED)",110,40,(R(0,H),R(0,H),R(0,H)),bg)whileK(KEY_OK):passwhilenotK(KEY_OK):passwhileK(KEY_OK):STR("",110,40,bg,bg)passF(0,0,322,222,bg)#grd random pattern grass
ccarre=black#right
Direction=1shoot=True#main loop
F(0,y_floor,322,80,black)#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"]))fill_rect(i,randint(16,20),randint(5,15),randint(5,25),choice([(125,0,0),(0,0,0),"red"]))whilegame:F(x,y,side,side,pc)et+=0.1STR("Lives:"+str(round(pl)),4,0,cyan,bg)STR("World:"+str(world),105,0,black,bg)STR("Score:"+str(psc),210,0,white,bg)F(ex,ey,ew,eh,ec)#enemy moves
ifedir==1:ex-=1F(ex+ew,ey,1,eh,bg)ifedir==2:ex+=1F(ex-1,ey,1,eh,bg)ifedir==3:ey-=1F(ex,ey+eh,ew,1,bg)ifedir==4:ey+=1F(ex,ey-1,ew,1,bg)ifey+eh>y_floor:ey=y_floor-eh#player energy loss
ifx+side>=exandx<=ex+ewandy+side>=eyandy<=ey+eh:F(x,y,side,side,red)F(0,0,322,20,bg)sleep(0.001)pe-=0.3ifpl<2:F(x,y,side,side,bg)ifpe<1:pe=9pl-=1F(0,0,322,20,bg)ifpe>9:pe=1pl+=1F(0,0,322,20,bg)#game is over when plife < 1
ifpl<1:game=Falseforiinrange(100):forjinrange(100):i=R(x,x+side)j=R(y,y+side)F(i,j,R(2,5),R(2,5),choice([black,dark_red,red]))ifK(KEY_OK):pause()precedent_y=yifK(KEY_LEFT):pdir=1Direction=-1ifx>0:F(x+side-2,y,2,side,bg)x-=2elifK(KEY_RIGHT):pdir=2Direction=1ifx+side<=320:F(x,y,2,side,bg)x+=2#jump
ifK(KEY_BACKSPACE):ify==y_floor-side:jump=True#player shoots
ifK(KEY_TOOLBOX):ifshoot:shoot=False# 1 = right
iflen(L_bullets)<15:ifDirection==1:L_bullets.append([x+side+3,y+4,1,side//3,side//4])else:L_bullets.append([x-3-w_bullet,y+4,-1,side//3,side//4])elifnot(K(KEY_TOOLBOX)):shoot=True#bullets fired (L_bullets)
iflen(L_bullets)!=0:foriinL_bullets:#bullets reach left or right
ifi[0]>320ori[0]<0-i[3]:L_bullets.remove(i)else:ifi[2]==1:x_eff_bullet=i[0]else:x_eff_bullet=i[0]+i[3]-v_bulletF(x_eff_bullet,i[1],v_bullet,i[4],bg)i[0]+=v_bullet*i[2]#player bullets color
F(i[0],i[1],i[3],i[4],(R(0,H),R(0,H),R(0,H)))F(i[0]+(i[3]//6)+1,i[1]+(i[4]//6)+1,i[3]-(i[3]//6)*2-2,i[4]-(i[4]//6)*2-2,ccarre)ifjump:y=y_floor-side-L_jump[count]count+=1ifcount==len(L_jump):count=0jump=Falseifprecedent_y<y:F(x-2,y-4,side+4,4,bg)else:F(x-2,y+side,side+4,precedent_y-y,bg)F(x,y,side,side,pc)ifey<22:ey=22ifey+eh>200:ey=200-ehify<ey:edir=choice([3,4])ify>ey:edir=choice([3,4])ifex+ew<-R(10,20):ee+=R(1,3)ew=R(15,60)eh=R(15,60)ex=R(250,400)ey=R(20,y_floor-eh)ec=(R(0,100),R(0,100),R(0,100))pl-=1echase=FalseF(ex,ey,ew,eh,ec)F(x,y,side,side,red)#enemy defeated
ifee<1andx+side>=300andy+side>=y_floor-30:ee=R(12,35)F(0,y_floor,322,120,(R(0,H),R(0,H),R(0,H)))psc+=R(25,100)pe+=2ew=R(15,60)eh=R(15,60)ex=R(220,400)ey=R(20,y_floor-ey+eh)ec=(R(0,H),R(0,H),R(0,H))pe+=2echase=Falseworld+=1bg=(R(0,H),R(0,H),R(0,H))y_floor=R(120,180)x=10y=y_floor-sideF(0,0,322,222,bg)r=R(0,H)g=R(0,H)b=R(0,H)F(0,y_floor,322,120,(r,g,b))#enemy destroyed
ifee<1:ex+=R(1,3)foriinrange(10):forjinrange(10):i=R(ex,ex+ew)j=R(ey,ey+eh)F(i,j,R(2,5),R(2,5),choice([black,bg]))#door pops up
F(300,y_floor-30,16,30,(R(0,H),R(0,H),R(0,H)))foriinrange(0,10):i+=1lavay=R(200,220)F(i,lavay,4,40,(R(0,50),R(0,50),R(0,50)))ex-=1F(ex+ew,ey,1,eh,bg)ifK(KEY_TOOLBOX)andy+4>=eyandy+4<=ey+ehandx>exandpdir==1andee>=1:F(ex,ey,ew,eh,red)F(0,0,322,20,bg)psc+=1pe+=0.04ee-=0.1ifK(KEY_TOOLBOX)andy+4>=eyandy+4<=ey+ehandx<exandpdir==2andee>=1:F(ex,ey,ew,eh,red)F(0,0,322,20,bg)psc+=1pe+=0.04ee-=0.1ifK(KEY_UP):F(x+7,25,3,y-25,red)sleep(0.01)F(x+7,25,3,y-25,bg)ifK(KEY_UP)andx+9>=exandx+7<=ex+ewandee>=1:F(ex,ey,ew,eh,red)F(0,0,322,20,bg)psc+=1pe+=0.04ee-=0.2dash=R(0,2)ifdash:foriinrange(2):ex-=R(0,1)F(ex+ew-1,ey,2,eh,bg)#player
pc=(0,R(150,H),R(150,H))#enemy leaves cloud
F(ex+ew,ey+R(1,eh),R(2,4),R(1,3),(R(0,40),R(0,40),R(0,40)))#grass and flowers
ify+side>=y_floor:y=y_floor-sideforiinrange(0.0001):i=R(0,322)F(i,y_floor+R(0,4),R(1,2),R(1,2),choice([green,black,red]))STR("GAME OVER",100,90,black,bg)STR("SCORE:"+str(psc),100,120,cyan,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.