from math import * from random import * from kandinsky import * from ion import * from time import * from kandinsky import fill_rect as F from random import randint as R from ion import keydown as K CYAN=(0,255,255) RED=(255,0,0) DARKRED=(135,0,0) DARKGREEN=(0,135,0) WHITE=(255,255,255) BLACK=(0,0,0) GREEN=(0,255,0) BLUE=(0,0,255) #screen width and height SCRW=322 SCRH=222 SCRA=SCRW*SCRH world=1 game=True bg=(randint(0,35),randint(0,35),randint(0,35)) #player psc=0 pe=9 plife=3 pc=CYAN edash=False edash_timer=0 eattacks=False eruns=False edefeated=False dooropen=False etimer=0 echase=False edir=0 #enemys energy ee=R(100,300) ex=R(180,280) ey=R(40,100) ew=12 eh=18 ec=(R(0,255),R(0,255),R(0,255)) doorx=-10 doory=-10 doorw=9 doorh=20 doorc=(35,20,0) def pause(): draw_string("(PAUSED)",110,100,(randint(0,255),randint(0,255),randint(0,255)),bg) while K(KEY_OK): pass while not K(KEY_OK): pass while K(KEY_OK): draw_string(" ",110,100,bg,bg) pass booljump,compteur_saut,L_saut=False,0,[int(-0.4*(x/4)**2+70) for x in range(-52,52)]+[0] #L_saut=[int(-1*(x/6)**2+70) for x in range(-50,50)] #length side + #side is the size or width side=15 #player x x=15 #player y y_floor=200 #player height i guess.. #player y = height - side i guess? y=y_floor-side # just a counter for the rgb effect on the cube c=0 #background color c_sky=bg #clouds 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//7 c_2=side//12 c_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=(randint(0,255),randint(0,255),randint(0,255)) def display_square(): c_1=side//7 c_2=side//8 c_3=side-c_1*2-c_2*2 fill_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 def hsv_to_rgb(h, s=1.0, v=1.0):#rgb effect, feel free to use it in your own project h = (h%360)/360 if s == 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%=6 if i == 0: return (v, t, p) if i == 1: return (q, v, p) if i == 2: return (p, v, t) if i == 3: return (p, q, v) if i == 4: return (t, p, v) if i == 5: return (v, p, q) # def wipe_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=8 h_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]] def display_clouds(): global L_clouds,offset if offset ==16: offset=0 L_clouds=[[i[-1]]+i[:-1]for i in L_clouds] else:offset+=1 h,l=14,16 for i,p in enumerate(L_clouds): for j,q in enumerate(p): if q==1: x_nuage,y_nuage=-1*l+offset+j*l,20+i*h fill_rect(x_nuage,y_nuage,l,h,c_cloud) if q==2: x_nuage,y_nuage=-1*l+offset+j*l+15,20+i*h fill_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) def display_ground(): fill_rect(0,y_floor,320,222-y_floor,c_herbe) fill_rect(0,y_ground1,320,222-y_ground1,c_ground1) for i in range(80):#320 random = randint(0,20) h =random*(y_ground2-y_ground1)//20 fill_rect(i*4,y_ground1,4,h,c_herbe) for i in range(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)] for i in range(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) #ground random pattern grass display_ground() c_carre=(148, 49, 38) fill_rect(x,y,side,side,c_carre) Direction=1 bool_shoot=True #main loop while True: etimer+=0.1 draw_string("World:"+str(world),100,2,bg,BLACK) draw_string(":["+str(plife),16,2,WHITE,BLACK) draw_string(":[",240,2,GREEN,BLACK) F(259,6,round(ee/4),10,RED) F(2,3,7,13,pc) F(4,5,5,5,CYAN) F(226,3,ew-3,eh-4,ec) F(227,6,5,4,WHITE) if etimer>R(3,7): etimer=0 edir=R(1,4) echase=choice([False,True,True]) #enemy chases player if echase: if ex<x: edir=2 if ex>x: edir=1 if ey<y: edir=4 if ey>y: edir=3 #enemy moves if edir==1: ex-=1 F(ex+ew,ey,1,eh,bg) if edir==2: ex+=1 F(ex-1,ey,1,eh,bg) if edir==3: ey-=1 F(ex,ey+eh,ew,1,bg) if edir==4: ey+=1 F(ex,ey-1,ew,1,bg) if dooropen: F(doorx,doory,doorw,doorh,(randint(0,255),randint(0,255),randint(0,255))) F(doorx,doory+doorh,doorw,2,WHITE) F(ex,ey,ew,eh,ec) F(ex+2,ey+4,8,4,choice([BLACK,WHITE,DARKGREEN])) if keydown(KEY_OK): pause() precedent_y=y if keydown(KEY_LEFT): Direction=-1 if x>0: fill_rect(x+side-2,y,2,side,c_sky) x-=2 elif keydown(KEY_RIGHT): Direction=1 if x+side<=320: fill_rect(x,y,2,side,c_sky) x+=2 if keydown(KEY_BACKSPACE): if y==y_floor-side: booljump=True #increase size if keydown(KEY_PLUS): if side<230: side+=1 y-=1 x-=side%2 #decrease size elif keydown(KEY_MINUS): if side>8: fill_rect(x,y-1,side,3,c_sky) fill_rect(x+side-1,y+1,1,side-1,c_sky) if booljump: fill_rect(x-1,y+side-1,side+3,1,c_sky) fill_rect(x,y,2,side,c_sky) x+=side%2 side-=1 y+=1 #player shoots if keydown(KEY_TOOLBOX): if bool_shoot: bool_shoot=False if len(L_projectiles)<15: if Direction==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]) elif not(keydown(KEY_TOOLBOX)): bool_shoot=True #i guess there is limit of #bullets fired (L_projectiles) if len(L_projectiles)!=0: for i in L_projectiles: #bullets reach left or right if i[0]>320 or i[0]<0-i[3]: L_projectiles.remove(i) else: if i[2]==1: x_eff_projectile=i[0] else: x_eff_projectile=i[0]+i[3]-v_projectile fill_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) if booljump: y=y_floor-side-L_saut[compteur_saut] compteur_saut+=1 if compteur_saut== len(L_saut): compteur_saut=0 booljump=False #y=y_sol-cote if precedent_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+=1 c_carre=hsv_to_rgb(c)