Advertisement
Guest User

Untitled

a guest
Feb 1st, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.49 KB | None | 0 0
  1. from math import *
  2. from kandinsky import *
  3. from ion import *
  4. from random import *
  5. boolsaut,compteur_saut,L_saut=False,0,[int(-0.4*(x/4)**2+70) for x in range(-52,52)]+[0]
  6. #L_saut=[int(-1*(x/6)**2+70) for x in range(-50,50)]
  7.  
  8. #length side +
  9. side,y_floor=15,200
  10. x,y=0,y_floor-side
  11. c=0# just a counter for the rgb effect on the cube
  12.  
  13. #usually colors variable name begins with "c_" and then the object it relates to
  14. c_sky,c_cloud=(169, 204, 227),(160,160,160)
  15.  
  16. fill_rect(0,0,320,222,c_sky)
  17. #fill_rect(0,0,320,222,(0,0,0))
  18.  
  19.  
  20.  
  21. score=0
  22. #variable for the square: length of each part
  23. c_1=side//7
  24. c_2=side//12
  25. c_3=side-c_1*2-c_2*2
  26. c_col_1=(255,255,255)
  27. c_col_3=(255,255,255)
  28. def display_square():
  29.   c_1=side//7
  30.   c_2=side//8
  31.   c_3=side-c_1*2-c_2*2
  32.  
  33.   #fill_rect(x,y,cote,cote,c_col_1)
  34.   fill_rect(x,y,side,c_1,c_col_1)
  35.   fill_rect(x,y+side-c_1,side,c_1,c_col_1)
  36.   fill_rect(x,y+c_1,c_1,c_3+c_2*2,c_col_1)
  37.   fill_rect(x+side-c_1,y+c_1,c_1,c_3+c_2*2,c_col_1)
  38.  
  39.   fill_rect(x+c_1,y+c_1,side-2*c_1,c_2,c_carre)
  40.   fill_rect(x+c_1,y+c_1+c_2+c_3,side-2*c_1,c_2,c_carre)
  41.   fill_rect(x+c_1,y+c_1+c_2,c_2,c_3,c_carre)
  42.   fill_rect(x+c_1+c_2+c_3,y+c_1+c_2,c_2,c_3,c_carre)
  43.  
  44.   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)
  45. #carre  
  46. def hsv_to_rgb(h, s=1.0, v=1.0):#rgb effect, feel free to use it in your own project
  47.       h = (h%360)/360
  48.       if s == 0.0: v*=255; return (v, v, v)
  49.       i = int(h*6.) # XXX assume int() truncates!
  50.       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
  51.       if i == 0: return (v, t, p)
  52.       if i == 1: return (q, v, p)
  53.       if i == 2: return (p, v, t)
  54.       if i == 3: return (p, q, v)
  55.       if i == 4: return (t, p, v)
  56.       if i == 5: return (v, p, q)
  57. #  
  58. def wipe_out_previous_square(b):
  59.   fill_rect(x-b,y-b,2*b+side,b,c_sky)
  60.   fill_rect(x-b,y,b,side,c_sky)
  61.   fill_rect(x+side,y,b,side,c_sky)
  62.   fill_rect(x-b,y+side,2*b+side,y_floor-y-side,c_sky)
  63. #
  64. ###laser
  65. L_projectiles=[]
  66. w_projectile=8
  67. h_projectile=6
  68. v_projectile=4
  69.  
  70. ##### SKY PART
  71. offset=0#counter for clouds
  72. 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}
  73. [0,0,2,1,1,0,0,0,0,2,1,1,0,0,0,2,1,1,0,0,0],
  74. [0,2,1,1,1,1,0,0,2,1,1,1,1,0,2,1,1,1,1,0,0],
  75. [2,1,1,1,1,1,0,2,1,1,1,1,1,0,2,1,1,1,1,1,0]]  
  76. def display_clouds():
  77.   global L_clouds,offset
  78.   if offset ==16:
  79.     offset=0
  80.     L_clouds=[[i[-1]]+i[:-1]for i in L_clouds]
  81.   else:offset+=1
  82.   h,l=14,16
  83.   for i,p in enumerate(L_clouds):
  84.     for j,q in enumerate(p):
  85.       if q==1:
  86.         x_nuage,y_nuage=-1*l+offset+j*l,20+i*h
  87.         fill_rect(x_nuage,y_nuage,l,h,c_cloud)
  88.       if q==2:
  89.         x_nuage,y_nuage=-1*l+offset+j*l+15,20+i*h
  90.         fill_rect(x_nuage,y_nuage,2,h,c_sky)
  91.  
  92. #ground
  93. y_ground1,y_ground2,c_herbe,c_ground1,c_ground2=y_floor+(222-y_floor)//3,215,(25, 111, 61 ),(160, 64, 0 ),(96,48,0)
  94. def display_ground():
  95.   fill_rect(0,y_floor,320,222-y_floor,c_herbe)
  96.   fill_rect(0,y_ground1,320,222-y_ground1,c_ground1)
  97.   for i in range(80):#320
  98.     random = randint(0,20)
  99.     h =random*(y_ground2-y_ground1)//20
  100.     fill_rect(i*4,y_ground1,4,h,c_herbe)
  101.   for i in range(190):#190
  102.     xground,yground=randint(0,320),randint(y_ground2-4,222)
  103.     fill_rect(xground,yground,3,3,c_ground2)
  104.   L_col=[(88,140,0),(0,88,24),(0,168,0)]
  105.   for i in range(320):#320
  106.     cground,xground,yground=L_col[randint(0,2)],randint(0,320),randint(y_floor,y_ground1)
  107.     fill_rect(xground,yground,2,2,cground)
  108. display_ground()
  109. #ground
  110.  
  111. c_carre=(148, 49, 38)
  112. fill_rect(x,y,side,side,c_carre)
  113.  
  114. Direction=1
  115. bool_tir=True
  116. while True:
  117.  
  118.   precedent_y=y
  119.    # direction du carre = direct du laser
  120.   if keydown(KEY_LEFT):
  121.     Direction=-1
  122.     if x>0:
  123.       fill_rect(x+side-2,y,2,side,c_sky)
  124.       x-=2
  125.  
  126.   elif keydown(KEY_RIGHT):
  127.     Direction=1
  128.     if x+side<=320:
  129.       fill_rect(x,y,2,side,c_sky)
  130.       x+=2
  131.  
  132.   if keydown(KEY_OK):
  133.     if y==y_floor-side:
  134.       boolsaut=True
  135.   if keydown(KEY_TOOLBOX):
  136.     if side<230:
  137.         side+=1
  138.         y-=1
  139.         x-=side%2
  140.         #w_projectile=cote//3
  141.         #h_projectile=cote//4
  142.  
  143.   elif keydown(KEY_BACKSPACE):
  144.     if side>8:
  145.         fill_rect(x,y-1,side,3,c_sky)
  146.         fill_rect(x+side-1,y+1,1,side-1,c_sky)
  147.         if boolsaut:
  148.           fill_rect(x-1,y+side-1,side+3,1,c_sky)
  149.        
  150.          
  151.          
  152.         fill_rect(x,y,2,side,c_sky)
  153.         x+=side%2
  154.         side-=1
  155.         y+=1
  156.         #w_projectile=cote//3
  157.         #h_projectile=cote//4
  158.  
  159.    
  160.   if keydown(KEY_HOME):
  161.     if bool_tir:
  162.       bool_tir=False
  163.     #while keydown(KEY_HOME):True
  164.       if len(L_projectiles)<15:
  165.         if Direction==1:
  166.           L_projectiles.append([x+side+3, y+4, 1,side//3,side//4])
  167.         else:
  168.           L_projectiles.append([x-3-w_projectile, y+4, -1,side//3,side//4])
  169.     elif not(keydown(KEY_HOME)):
  170.         bool_tir=True  
  171.    
  172.  
  173.   if len(L_projectiles)!=0:
  174.       for i in L_projectiles:
  175.           if i[0]>320 or i[0]<0-i[3]:
  176.               L_projectiles.remove(i)
  177.           else:
  178.               if i[2]==1:
  179.                 x_eff_projectile=i[0]
  180.               else:
  181.                 x_eff_projectile=i[0]+i[3]-v_projectile
  182.  
  183.               fill_rect(x_eff_projectile,i[1],v_projectile, i[4], c_sky)
  184.               i[0]+=v_projectile*i[2]
  185.               fill_rect(i[0],i[1],i[3], i[4], (0,0,0))
  186.               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)
  187.        
  188.      
  189.      
  190.      
  191.   if boolsaut:
  192.       y=y_floor-side-L_saut[compteur_saut]
  193.       compteur_saut+=1
  194.      
  195.       if compteur_saut== len(L_saut):
  196.         compteur_saut=0
  197.         boolsaut=False
  198.         #y=y_sol-cote
  199.       if precedent_y<y:
  200.         fill_rect(x-2,y-4,side+4,4,c_sky)
  201.       else:
  202.         fill_rect(x-2,y+side,side+4,precedent_y-y,c_sky)
  203.        
  204.       display_square()
  205.  
  206.   #nettoyage_de_printemps(5)
  207.  
  208.  
  209.   #displaying and refreshing the square
  210.   display_square()
  211.  
  212.   #displaying and refreshing the clouds
  213.   display_clouds()
  214.  
  215.   #little alien
  216.   fill_rect(300,150,20,50,(255,0,0))
  217.   fill_rect(304,160,4,4,(255,255,0))
  218.   fill_rect(312,160,4,4,(255,255,0))
  219.   fill_rect(304,170,12,2,(255,255,0))
  220.  
  221.   #
  222.   #aff_ground()
  223.    
  224.  
  225.   #colorful
  226.   c+=1
  227.   c_carre=hsv_to_rgb(c)
  228.  
  229.   #score=""
  230.   draw_string("score= ;)",230,2,c_carre,c_sky)
  231. #200eme ligne YES boys we did it,YYEEEEESSSSSS
  232. #sus
  233. #hehehehehe
  234.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement