frommathimport*fromkandinskyimport*fromionimport*fromrandomimport*booljump,compteur_saut,L_saut=False,0,[int(-0.4*(x/4)**2+70)forxinrange(-52,52)]+[0]#L_saut=[int(-1*(x/6)**2+70) for x in range(-50,50)]
#length side +
side=15y_floor=200x=12y=y_floor-side# just a counter for the rgb effect on the cube
c=0#usually colors variable name begins with "c_" and then the object it relates to
c_sky=(randint(200,255),randint(200,255),randint(200,255))c_cloud=(randint(0,255),randint(0,255),randint(0,255))fill_rect(0,0,320,222,c_sky)score=0#variable for the square: length of each part
c_1=side//7c_2=side//12c_3=side-c_1*2-c_2*2#player colors
c_col_1=(randint(0,255),randint(0,255),randint(0,255))c_col_3=(255,255,255)defdisplay_square():c_1=side//7c_2=side//8c_3=side-c_1*2-c_2*2fill_rect(x,y,side,c_1,c_col_1)fill_rect(x,y+side-c_1,side,c_1,c_col_1)fill_rect(x,y+c_1,c_1,c_3+c_2*2,c_col_1)fill_rect(x+side-c_1,y+c_1,c_1,c_3+c_2*2,c_col_1)fill_rect(x+c_1,y+c_1,side-2*c_1,c_2,c_carre)fill_rect(x+c_1,y+c_1+c_2+c_3,side-2*c_1,c_2,c_carre)fill_rect(x+c_1,y+c_1+c_2,c_2,c_3,c_carre)fill_rect(x+c_1+c_2+c_3,y+c_1+c_2,c_2,c_3,c_carre)fill_rect(x+c_1+c_2,y+c_1+c_2,side-(c_1+c_2)*2,side-(c_1+c_2)*2,c_col_3)#carre
defhsv_to_rgb(h,s=1.0,v=1.0):#rgb effect, feel free to use it in your own project
h=(h%360)/360ifs==0.0:v*=255;return (v,v,v)i=int(h*6.)# XXX assume int() truncates!
f=(h*6.)-i;p,q,t=int(255*(v*(1.-s))),int(255*(v*(1.-s*f))),int(255*(v*(1.-s*(1.-f))));v*=255;i%=6ifi==0:return (v,t,p)ifi==1:return (q,v,p)ifi==2:return (p,v,t)ifi==3:return (p,q,v)ifi==4:return (t,p,v)ifi==5:return (v,p,q)#
defwipe_out_previous_square(b):fill_rect(x-b,y-b,2*b+side,b,c_sky)fill_rect(x-b,y,b,side,c_sky)fill_rect(x+side,y,b,side,c_sky)fill_rect(x-b,y+side,2*b+side,y_floor-y-side,c_sky)#
###laser
#length or amount i guess
L_projectiles=[]#width and height of bullets
w_projectile=8h_projectile=6#velocity of bullets
v_projectile=4##### SKY PART
offset=0#counter for clouds
L_clouds=[[0]*9+[2,1,1]+[0]*9,#here you can easily change the aspect of clouds (2 is meant to be directly placed at the left of 1) {1 = a square of a cloud and 2 is the part to erase}
[0,0,2,1,1,0,0,0,0,2,1,1,0,0,0,2,1,1,0,0,0],[0,2,1,1,1,1,0,0,2,1,1,1,1,0,2,1,1,1,1,0,0],[2,1,1,1,1,1,0,2,1,1,1,1,1,0,2,1,1,1,1,1,0]]defdisplay_clouds():globalL_clouds,offsetifoffset==16:offset=0L_clouds=[[i[-1]]+i[:-1]foriinL_clouds]else:offset+=1h,l=14,16fori,pinenumerate(L_clouds):forj,qinenumerate(p):ifq==1:x_nuage,y_nuage=-1*l+offset+j*l,20+i*hfill_rect(x_nuage,y_nuage,l,h,c_cloud)ifq==2:x_nuage,y_nuage=-1*l+offset+j*l+15,20+i*hfill_rect(x_nuage,y_nuage,2,h,c_sky)#ground
y_ground1=y_floor+(222-y_floor)//3#grass on dirt
y_ground2=215#3 different colors for 3 different things
c_herbe=(25,111,61)c_ground1=(160,64,0)c_ground2=(96,48,0)defdisplay_ground():fill_rect(0,y_floor,320,222-y_floor,c_herbe)fill_rect(0,y_ground1,320,222-y_ground1,c_ground1)foriinrange(80):#320
random=randint(0,20)h=random*(y_ground2-y_ground1)//20fill_rect(i*4,y_ground1,4,h,c_herbe)foriinrange(190):#190
xground,yground=randint(0,320),randint(y_ground2-4,222)fill_rect(xground,yground,3,3,c_ground2)L_col=[(88,140,0),(0,88,24),(0,168,0)]foriinrange(320):#320
cground,xground,yground=L_col[randint(0,2)],randint(0,320),randint(y_floor,y_ground1)fill_rect(xground,yground,2,2,cground)display_ground()#ground
c_carre=(148,49,38)fill_rect(x,y,side,side,c_carre)Direction=1bool_shoot=True#main loop
whileTrue:precedent_y=yifkeydown(KEY_LEFT):Direction=-1ifx>0:fill_rect(x+side-2,y,2,side,c_sky)x-=2elifkeydown(KEY_RIGHT):Direction=1ifx+side<=320:fill_rect(x,y,2,side,c_sky)x+=2ifkeydown(KEY_BACKSPACE):ify==y_floor-side:booljump=True#increase size
ifkeydown(KEY_PLUS):ifside<230:side+=1y-=1x-=side%2#decrease size
elifkeydown(KEY_MINUS):ifside>8:fill_rect(x,y-1,side,3,c_sky)fill_rect(x+side-1,y+1,1,side-1,c_sky)ifbooljump:fill_rect(x-1,y+side-1,side+3,1,c_sky)fill_rect(x,y,2,side,c_sky)x+=side%2side-=1y+=1#player shoots
ifkeydown(KEY_TOOLBOX):ifbool_shoot:bool_shoot=Falseiflen(L_projectiles)<15:ifDirection==1:L_projectiles.append([x+side+3,y+4,1,side//3,side//4])else:L_projectiles.append([x-3-w_projectile,y+4,-1,side//3,side//4])elifnot(keydown(KEY_TOOLBOX)):bool_shoot=Trueiflen(L_projectiles)!=0:foriinL_projectiles:ifi[0]>320ori[0]<0-i[3]:L_projectiles.remove(i)else:ifi[2]==1:x_eff_projectile=i[0]else:x_eff_projectile=i[0]+i[3]-v_projectilefill_rect(x_eff_projectile,i[1],v_projectile,i[4],c_sky)i[0]+=v_projectile*i[2]fill_rect(i[0],i[1],i[3],i[4],(0,0,0))fill_rect(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,c_carre)ifbooljump:y=y_floor-side-L_saut[compteur_saut]compteur_saut+=1ifcompteur_saut==len(L_saut):compteur_saut=0booljump=False#y=y_sol-cote
ifprecedent_y<y:fill_rect(x-2,y-4,side+4,4,c_sky)else:fill_rect(x-2,y+side,side+4,precedent_y-y,c_sky)display_square()display_square()display_clouds()c+=1c_carre=hsv_to_rgb(c)
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.