Advertisement
wilson_357111317

cubic_duel.py

Nov 24th, 2021 (edited)
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.16 KB | None | 0 0
  1.  
  2. # "Cubic Duel"
  3. # Written By: Wilson
  4. from math import *
  5. from ion import *
  6. from time import *
  7. from random import *
  8. from kandinsky import *
  9. from ion import keydown as KEY
  10. from ion import KEY_LEFT as LEFT
  11. from ion import KEY_RIGHT as RIGHT
  12. from ion import KEY_UP as UP
  13. from ion import KEY_DOWN as DOWN
  14. from ion import KEY_OK as OK
  15. from ion import KEY_BACKSPACE as BS
  16. from kandinsky import fill_rect as FILL
  17. from kandinsky import draw_string as STRING
  18. from random import randint as R
  19.  
  20. time=0
  21. bg=(0,0,0)
  22. def start_menu():
  23.   global time
  24.  
  25.   FILL(0,0,322,222,bg)
  26.   FILL(0,0,322,60,(0,0,120))
  27.   STRING("CUBIC DUEL",100,10,"cyan",(0,0,120))
  28.  
  29.   sleep(0.2)
  30.   while not KEY(KEY_OK):
  31.     STRING("KEYs [Arrow] = 8 Directions",6,80,"gray",bg)
  32.     STRING("KEY [OK] = Attack/Run",6,100,"cyan",bg)
  33.     STRING("KEY [Backspace] = Pause/UnPause",6,120,"green",bg)
  34.     STRING("( Press [OK] KEY to Start)",8,180,"white",bg)
  35.  
  36. start_menu()
  37.  
  38. game=True
  39.  
  40. bg=(randint(0,220),randint(0,220),randint(0,220))
  41.  
  42. p_attacks=False
  43. penergy=80
  44. pscore=0
  45. pdir=0
  46. px=4
  47. py=213
  48. ps=8
  49. pc=(119,25,71)
  50.  
  51.  
  52. echase=0
  53. e_run=False
  54. echase_clock=0
  55. edir=0
  56. eclock=0
  57. e_energy=200
  58. ex=R(200,300)
  59. ey=R(60,200)
  60. es=10
  61. ec=(0,)*3
  62.  
  63.  
  64. FILL(0,0,322,222,bg)
  65. FILL(0,18,322,2,(100,)*3)
  66. FILL(0,208,20,4,(0,)*3)
  67.  
  68. FILL(3,3,es,es,(0,)*3)
  69. FILL(10,5,2,2,(255,0,0))
  70.    
  71. while game:
  72.  
  73.   FILL(0,208,20,4,(0,)*3)
  74.   FILL(0,211,20,12,(38,71,107))
  75.   FILL(px,py,ps,ps,pc)
  76.   FILL(ex,ey,es,es,ec)
  77.   FILL(px+2,py+2,1,1,(0,255,255))
  78.   FILL(px+5,py+2,1,1,(0,255,255))
  79.   pscore+=2
  80.   eclock+=1
  81.   echase_clock+=1
  82.  
  83.   if echase_clock>R(50,100):
  84.     echase=R(0,2)
  85.     echase_clock=0
  86.   if echase:
  87.     if px+ps-2<ex:
  88.       edir=1
  89.     if px>ex+es-2:
  90.       edir=2
  91.     if py+ps-2<ey:
  92.       edir=3
  93.     if py>ey+es-2:
  94.       edir=4
  95.      
  96.   if eclock > R(50,100):
  97.     edir=R(1,4)
  98.     eclock=R(-50,0)
  99.  
  100.   if edir==1:
  101.     sleep(.005)
  102.     ex-=1
  103.     FILL(ex+10,ey,1,es,bg)
  104.     FILL(ex+2,ey+2,3,1,(255,0,0))
  105.     FILL(ex,ey+6,3,2,(50,150,0))
  106.     if echase:
  107.       for q in range(3):
  108.         ex-=1
  109.         FILL(ex+es+2,ey,2,es,bg)
  110.        
  111.   if edir==2:
  112.     sleep(.005)
  113.     ex+=1
  114.     FILL(ex-1,ey,1,es,bg)
  115.     FILL(ex+6,ey+2,3,1,(255,0,0))
  116.     FILL(ex+7,ey+6,3,2,(50,150,0))
  117.     if echase:
  118.       for q in range(3):
  119.         ex+=1
  120.         FILL(ex-2,ey,2,es,bg)
  121.      
  122.   if edir==3:
  123.     sleep(.005)
  124.     ey-=1
  125.     FILL(ex,ey+es,es,1,bg)
  126.     FILL(ex+2,ey+1,4,1,(255,0,0))
  127.    
  128.  
  129.   if edir==4:
  130.     sleep(.005)
  131.     ey+=1
  132.     FILL(ex,ey-1,es,1,bg)
  133.     FILL(ex+2,ey+9,4,1,(255,0,0))
  134.  
  135.  
  136.   if pdir==1:
  137.     for w in range(2):
  138.       px-=1
  139.       FILL(px+ps,py,1,ps,bg)
  140.     if KEY(OK):
  141.       p_attacks=True
  142.       for w in range(8):
  143.         px-=1
  144.         FILL(px+ps,py,2,ps,bg)
  145.  
  146.    
  147.   if pdir==2:
  148.     for w in range(2):
  149.       px+=1
  150.       FILL(px-1,py,1,ps,bg)
  151.     if KEY(OK):
  152.       p_attacks=True
  153.       for w in range(8):
  154.         px+=1
  155.         FILL(px-2,py,2,ps,bg)
  156.  
  157.  
  158.   if pdir==3:
  159.     for w in range(2):
  160.       py-=1
  161.       FILL(px,py+ps,ps,1,bg)
  162.     if KEY(OK):
  163.       p_attacks=True
  164.       for w in range(4):
  165.         py-=1
  166.         FILL(px,py+ps,ps,2,bg)
  167.  
  168.   if pdir==4:
  169.     for w in range(2):
  170.       py+=1
  171.       FILL(px,py-1,ps,1,bg)
  172.     if KEY(OK):
  173.       p_attacks=True
  174.       for w in range(4):
  175.         py+=1
  176.         FILL(px,py-2,ps,2,bg)
  177.    
  178.   #player moves diagonal
  179.   if pdir==5:
  180.     px-=1
  181.     FILL(px+ps,py,1,ps,bg)
  182.     py-=1
  183.     FILL(px,py+ps,ps,1,bg)
  184.   if pdir==6:
  185.     px+=1
  186.     FILL(px-1,py,1,ps,bg)
  187.     py-=1
  188.     FILL(px,py+ps,ps,1,bg)
  189.  
  190.   if pdir==7:
  191.     px-=1
  192.     FILL(px+ps,py,1,ps,bg)
  193.     py+=1
  194.     FILL(px,py-1,ps,1,bg)
  195.   if pdir==8:
  196.     px+=1
  197.     FILL(px-1,py,1,ps,bg)
  198.     py+=1
  199.     FILL(px,py-1,ps,1,bg)
  200.  
  201.   if KEY(LEFT) or KEY(KEY_FOUR):
  202.     pdir=1
  203.   if KEY(RIGHT) or KEY(KEY_SIX):
  204.     pdir=2
  205.   if KEY(UP) or KEY(KEY_EIGHT):
  206.     pdir=3
  207.   if KEY(DOWN) or KEY(KEY_TWO):
  208.     pdir=4
  209.  
  210.   if KEY(KEY_SEVEN):pdir=5
  211.   if KEY(KEY_NINE):pdir=6
  212.   if KEY(KEY_ONE):pdir=7
  213.   if KEY(KEY_THREE):pdir=8
  214.   if KEY(KEY_FIVE):pdir=0
  215.  
  216.   if KEY(LEFT) and KEY(UP):
  217.     pdir=5
  218.   if KEY(RIGHT) and KEY(UP):
  219.     pdir=6
  220.   if KEY(LEFT) and KEY(DOWN):
  221.     pdir=7
  222.   if KEY(RIGHT) and KEY(DOWN):
  223.     pdir=8
  224.    
  225.   if px<1:
  226.     px=1
  227.   if px+ps>321:
  228.     px=321-ps
  229.   if py<20:
  230.     py=20
  231.   if py+ps>222:
  232.     py=222-ps
  233.  
  234.   if ex<1:
  235.     ex=1
  236.     edir=choice([2,3,4])
  237.   if ex+es>321:
  238.     ex=321-es
  239.     edir=choice([1,3,4])
  240.   if ey<20:
  241.     ey=20
  242.     edir=choice([1,2,4])
  243.   if ey+es>222:
  244.     ey=222-es
  245.     edir=choice([1,2,3])
  246.        
  247.   if KEY(BS):
  248.       FILL(0,20,322,222,"white")
  249.       STRING("( PAUSED )",110,35)
  250.       STRING("KEYs [Arrow] = 8 Directions",6,80)
  251.       STRING("KEY [OK] = Attack/Run",6,100)
  252.       STRING("KEY [Backspace] = Pause/UnPause",6,120)
  253.       STRING("( Press [OK] KEY to Rerume)",8,180)
  254.  
  255.       while KEY(BS):
  256.         pass
  257.       while not KEY(BS):
  258.         pass
  259.       while KEY(BS):
  260.         FILL(0,20,322,222,bg)
  261.         STRING("          ",110,35,bg,bg)
  262.         STRING("        ",6,80,bg,bg)
  263.         STRING("                                ",6,100,bg,bg)
  264.         STRING("                           ",6,120,"white",bg)
  265.         STRING("                                  ",8,180,(255,)*3,bg)
  266.    
  267.    
  268.   if px<=16:
  269.     if py>211:
  270.       penergy+=0.001
  271.     if py+ps >= 207 and py+ps <= 210:
  272.       py=206-ps
  273.       pdir=0
  274.    
  275.     if py <= 211 and py >= 210:
  276.       py=212
  277.       pdir=0
  278.     if py+ps>=207 and py<=210 or py+ps>=207 and py+ps<=210:
  279.       px=18
  280.       pdir=0  
  281.  
  282.   if ex<=17:
  283.     if ey+es >= 208:
  284.       ex=17
  285.       edir=choice([2,3,4])
  286.       echase=R(0,1)
  287.  
  288.   if px+ps >= ex and px <= ex+es and py+ps >= ey and py <= ey+es:
  289.     FILL(px,py,ps,ps,(105,0,0))
  290.     FILL(px-choice([0,1,2,3,-1,-2,-3,]),py+choice([1,2,3]),2,2,(105,0,0))
  291.     FILL(px,py,ps,ps,(105,0,0))
  292.     # player energy loss
  293.     penergy-=1
  294.     FILL(px-choice([0,1,2,-8,-9,-10]),py+ps,2,2,(0,50,0))
  295.     if p_attacks:
  296.       p_attacks=False
  297.       edir=choice([1,2,3,4])
  298.       #enemy stops for a sec and
  299.       #loses energy.
  300.       echase=False
  301.       e_energy-=1
  302.       # player gains energy
  303.       # when sword hits
  304.       # cubic monster.
  305.       penergy+=2
  306.       pscore+=R(5,20)
  307.       FILL(20,5,322,5,bg)
  308.       FILL(ex+R(-10,20),ey+R(-10,20),R(1,2),R(1,2),(0,)*3)
  309.     FILL(px,py,ps,ps,(105,0,0))
  310.     penergy-=0.05
  311.     FILL(px-choice([0,1,2,-8,-9,-10]),py+ps,2,2,(0,50,0))
  312.    
  313.  
  314.     if echase:
  315.       for q in range(3):
  316.         ex-=1
  317.         FILL(ex+es+2,ey,2,es,bg)
  318.  
  319.   STRING(str(int(penergy)),300,0)    
  320.    
  321.    
  322.   if penergy<1:game=0
  323.  
  324.          
  325.   if KEY(OK):
  326.     if pdir==1:
  327.       for w in range(322):
  328.         FILL(px-12,py+3,R(8,14),R(1,2),(255,)*3)
  329.     if pdir==2:
  330.       for w in range(322):
  331.         w=px+R(10,15)
  332.         FILL(px+5,py+3,R(8,14),R(1,2),(255,)*3)
  333.    
  334.     FILL(20,5,int(e_energy),5,(255,0,0))
  335.    
  336. for i in range(150):
  337.     for j in range(110):
  338.       i=randint(0,321)
  339.       j=randint(0,222)
  340.       fill_rect(i,j,randint(3,9),randint(3,9),(choice([50,100,150]),0,randint(0,50)))
  341.  
  342. STRING("GAME OVER",100,70,(255,)*3,(125,40,50))      
  343. STRING("Score: "+str(pscore),100,120,(255,)*3,(125,40,50))
  344. FILL(0,0,322,40,(269,)*3)
  345. FILL(0,182,322,40,(269,)*3)
  346.  
  347.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement