wilson_357111317

drone16.py

Nov 19th, 2021 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.72 KB | None | 0 0
  1.  
  2. from kandinsky import *
  3. from ion import *
  4. from time import *
  5. from random import *
  6.  
  7. big_font=[(20,20,8,50,(255,)*3)]
  8.  
  9. bg=(0,20,100)
  10.  
  11. time=0
  12.  
  13. def menu():
  14.   global time
  15.  
  16.   fill_rect(0,0,322,222,bg)
  17.   while not keydown(KEY_OK):
  18.     draw_string("         DRONE16        ",0,25)
  19.     draw_string("[Backspace] = Pause/Unpause",5,80,"cyan",bg)
  20.     for i in big_font:
  21.       fill_rect(*i)
  22.  
  23.    
  24.     time+=1    
  25.     if time>0 and time<500:
  26.       draw_string("PRESS [OK] key to start",40,160,(0,255,255),(0,20,100))
  27.      
  28.     if time>500 and time<800:
  29.         draw_string("                         ",40,160,(0,20,100),(0,20,100))
  30.      
  31.     if time>800:
  32.       time=0
  33.  
  34.      
  35.   if keydown(KEY_OK):
  36.     menu=0
  37.  
  38. menu()
  39.  
  40. paused=False
  41.  
  42. score=0
  43. clock=0
  44. star_size=1
  45. star_colors=["white",
  46. "yellow",
  47. "orange",
  48. "red",
  49. "blue"
  50. ]
  51.  
  52. C=(randint(0,255),randint(0,255),randint(0,255))
  53. R=(randint(0,255),randint(0,255),randint(0,255))
  54. c=randint(0,322)
  55. d=randint(0,222)
  56.  
  57. R=randint(0,70)
  58. G=randint(0,70)
  59. B=randint(0,70)
  60.  
  61. rr=40
  62. gg=25
  63. bb=100
  64.  
  65. r=randint(0,80)
  66. g=randint(10,50)
  67. b=randint(15,25)
  68.  
  69. r2=randint(5,55)
  70. g2=randint(5,55)
  71. b2=randint(5,55)
  72.  
  73. energy=50
  74. energy_x=randint(5,250)
  75. energy_y=randint(10,200)
  76. energy_width=9
  77. energy_height=15
  78. energy_timer=0
  79. # background color
  80. background_color=(randint(0,100),randint(0,100),randint(0,100))
  81.  
  82. RC=(randint(0,230),randint(0,230),randint(0,230))
  83. move=True
  84. game_end=False
  85. p_timer=0
  86. p_dir_LEFT=1
  87. p_dir_RIGHT=2
  88. p_dir_UP=3
  89. p_dir_DOWN=4
  90. p_x=10
  91. p_y=100
  92. sleep_slow=1/10**4
  93. p_speed_fast=1/10**9
  94. p_pace=1
  95. p_speed_range=2
  96. p_width=10
  97. p_height=4
  98. p_color="white"
  99. SCREEN_width=321
  100. SCREEN_height=222
  101.  
  102. bar_width=randint(15,40)
  103. bar_height=randint(170,210)
  104. bar_x=randint(170,265-bar_width)
  105. bar_y=randint(10,200)
  106. bar_color=(r,g,b)
  107.  
  108. bar_width2=randint(15,40)
  109. bar_height2=randint(170,210)
  110. bar_x2=randint(170,265-bar_width)
  111. bar_y2=randint(10,200)
  112. bar_color2=(r,g,b)
  113.  
  114. bar_dir_LEFT=False
  115. bar_dir_RIGHT=False
  116. bar_dir_UP=False
  117. bar_dir_DOWN=False
  118. bar_UP=False
  119. timer_bar=0
  120.  
  121. fill_rect(0,0,322,222,background_color)
  122. fill_rect(262,45,122,222,"black")
  123.  
  124. bit_color=(randint(0,150),randint(0,150),randint(0,150))  
  125. ascii=randint(33,126)
  126. bit=chr(int(ascii))
  127. # Main loop
  128. while not game_end and not paused:
  129.   score+=randint(0,1)
  130.   clock+=1
  131.   if clock>0 and clock<30:
  132.     c=randint(0,322)
  133.     d=randint(0,90)
  134.  
  135.  
  136.   draw_string("S:"+str(score),260,6,(169,169,169),background_color)
  137.  
  138.   draw_string(str(bit),energy_x,energy_y,(255,)*3,bit_color)  
  139.   draw_string("E:"+str(energy),260,24,(169,)*3,background_color)
  140.  
  141.   energy+=0.002
  142.   bar_x-=1
  143.   bar_x2-=1
  144.   energy_timer+=1
  145.  
  146.   fill_rect(0,0,265,5,(40,0,0))
  147.   fill_rect(0,217,265,4,(40,0,0))
  148.  
  149.   if bar_x < -bar_width-1:
  150.     bar_x=randint(170,265-bar_width)
  151.     bar_y=randint(-50,150)
  152.     bar_width=randint(15,40)
  153.     bar_height=randint(120,200)
  154.     r=randint(5,255)
  155.     g=randint(5,255)
  156.     b=randint(5,255)
  157.     bar_color=(r,g,b)
  158.     clock=0
  159.     c=randint(0,322)
  160.     d=randint(0,90)
  161.  
  162.  
  163.  
  164.    
  165.   if bar_x2 < -bar_width2-1:
  166.     bar_x2=randint(150,200-bar_width)
  167.     bar_y2=randint(-30,0)
  168.     bar_width2=randint(20,50)
  169.     bar_height2=randint(80,150)
  170.     r2=randint(5,55)
  171.     g2=randint(5,55)
  172.     b2=randint(5,55)
  173.     bar_color2=(r2,g2,b2)
  174.    
  175.   fill_rect(bar_x,bar_y,bar_width,bar_height,bar_color)
  176.   fill_rect(bar_x+bar_width+1,bar_y,1,bar_height,background_color)
  177.  
  178.   fill_rect(bar_x2,bar_y2,bar_width2,bar_height2,bar_color2)
  179.   fill_rect(bar_x2+bar_width2+1,bar_y2,1,bar_height2,background_color)
  180.  
  181.   fill_rect(p_x,p_y,p_width,p_height,p_color)
  182.   fill_rect(p_x,p_y,p_width,p_height,p_color)
  183.          
  184.   if p_x+10 > bar_x and p_x<=bar_x+bar_width and p_y+4 >= bar_y and p_y <= bar_y+bar_height or p_x+10 > bar_x2 and p_x<=bar_x2+bar_width2 and p_y+4 >= bar_y2 and p_y <= bar_y2+bar_height2:
  185.     energy-=0.5
  186.     fill_rect(p_x,p_y,p_width,p_height,"red")
  187.  
  188.   if energy<1:
  189.     game_end=True
  190.   if p_x+10>265:
  191.     p_x=265-10
  192.     move=False
  193.   else:
  194.     move=True
  195.  
  196.   if p_x+p_width >= energy_x and p_y+p_height >= energy_y and p_y <= energy_y+energy_height or p_x <= bar_x+bar_width and p_y+p_height >= bar_y and p_y <= energy_y+energy_height:
  197.     energy+=2
  198.     fill_rect(p_x,p_y,p_width,p_height,"green")
  199.     draw_string(".",energy_x,energy_y,background_color,background_color)      
  200.     energy_x=randint(-20,250)
  201.     energy_y=randint(-20,300)
  202.     energy_timer=0
  203.     score+=randint(5,20)
  204.     bit_color=(randint(0,95),randint(0,95),randint(0,95))  
  205.     ascii=randint(33,126)
  206.     bit=chr(int(ascii))
  207.    
  208.  
  209.  
  210.  
  211.   if energy_timer>randint(400,600):
  212.     draw_string(" ",energy_x,energy_y,background_color,background_color)      
  213.     energy_x=randint(5,250)
  214.     energy_y=randint(5,210)
  215.     energy_timer=0
  216.     bit_color=(randint(0,95),randint(0,95),randint(0,95))  
  217.     ascii=randint(33,126)
  218.     bit=chr(int(ascii))
  219.  
  220.   if p_x<(SCREEN_width-SCREEN_width):
  221.     move=False
  222.     p_x=SCREEN_width-SCREEN_width
  223.   else:
  224.     move=True
  225.   if p_y<5:
  226.     move=False
  227.     p_y=5
  228.   else:
  229.     move=True
  230.   if p_y>SCREEN_height-10:
  231.     move=False
  232.     p_y=SCREEN_height-10
  233.   else:
  234.     move=True
  235.   if move:
  236.     if keydown(KEY_RIGHT):
  237.       move=True
  238.       energy-=0.002
  239.       sleep(sleep_slow)
  240.       p_x+=p_pace
  241.       fill_rect(p_x-1,p_y,1,4,background_color)
  242.      
  243.       if keydown(KEY_OK):
  244.         move=True
  245.         for i in range(p_speed_range):
  246.           p_x+=1
  247.           fill_rect(p_x-1,p_y,1,10,background_color)
  248.     if keydown(KEY_LEFT):
  249.       move=True
  250.       energy-=0.002
  251.       sleep(sleep_slow)
  252.       p_x-=p_pace
  253.       fill_rect(p_x+10,p_y,1,10,background_color)
  254.      
  255.       if keydown(KEY_OK):
  256.         move=True
  257.         energy-=0.005
  258.         for i in range(p_speed_range):
  259.           p_x-=1
  260.           fill_rect(p_x+10,p_y,1,10,background_color)
  261.     if keydown(KEY_UP):
  262.       move=True
  263.       energy-=0.002
  264.       sleep(sleep_slow)
  265.       p_y-=1
  266.       fill_rect(p_x,p_y+4,10,1,background_color)
  267.      
  268.       if keydown(KEY_OK):
  269.         move=True
  270.         energy-=0.005
  271.         for i in range(p_speed_range):
  272.           p_y-=1
  273.           fill_rect(p_x,p_y+4,10,1,background_color)
  274.      
  275.     if keydown(KEY_DOWN):
  276.       move=True
  277.       energy-=0.002
  278.       sleep(sleep_slow)
  279.       p_y+=1
  280.       fill_rect(p_x,p_y-1,10,1,background_color)
  281.       if keydown(KEY_OK):
  282.         move=True
  283.         energy-=0.005
  284.         for i in range(p_speed_range):
  285.           p_y+=1
  286.           fill_rect(p_x,p_y-1,10,1,background_color)
  287.      
  288.     if keydown(KEY_BACKSPACE):
  289.       draw_string("(PAUSED)",100,10,"white",background_color)
  290.       draw_string("OK Key = Fast Speed",70,50,"white",background_color)
  291.       while keydown(KEY_BACKSPACE):
  292.         pass
  293.       while not keydown(KEY_BACKSPACE):
  294.         pass
  295.       while keydown(KEY_BACKSPACE):
  296.         draw_string("        ",100,10,background_color,background_color)
  297.         draw_string("                    ",70,50,background_color,background_color)
  298.         pass
  299.     if keydown(KEY_SHIFT):
  300.       draw_string("(PAUSED)",100,10,"white",background_color)
  301.       draw_string("OK Key = Fast Speed",70,50,"white",background_color)
  302.       while keydown(KEY_SHIFT):
  303.         pass
  304.       while not keydown(KEY_SHIFT):
  305.         pass
  306.       while keydown(KEY_SHIFT):
  307.         draw_string("        ",100,10,background_color,background_color)
  308.         draw_string("                    ",70,50,background_color,background_color)
  309.         pass
  310.      
  311.  
  312. for i in range(150):
  313.     for j in range(110):
  314.       i=randint(0,321)
  315.       j=randint(0,222)
  316.       fill_rect(i,j,randint(3,9),randint(3,9),(choice([100,150,200]),0,randint(0,50)))
  317.  
  318. draw_string("GAME OVER",100,70,(255,)*3,(0,)*3)      
  319. draw_string("Score: "+str(score),100,120,(0,255,0),(0,)*3)
  320. fill_rect(0,0,322,40,(269,)*3)
  321. fill_rect(0,182,322,40,(269,)*3)
  322.  
Advertisement
Add Comment
Please, Sign In to add comment