g22raptor.py

Created by wperez274

Created on January 31, 2022

4.27 KB

G-22 Raptor Game


key [OK] = Shoot key [Backspace] = Pause / Resume **************

Good Luck!


from math import *
from random import *
from kandinsky import *
from ion import *
from time import *

bg=(36,5,25)

fill_rect(0,0,322,222,bg)
clock=0
while not keydown(KEY_OK):
  clock+=0.40
  
  if clock<1:
    for i in range(20):
      for j in range(20):
      
        i=randint(0,321)
        j=randint(0,20)
        k=randint(0,321)
        l=randint(150,222)
        fill_rect(i,j,randint(20,50),randint(20,70),choice(["red","black"]))
        fill_rect(k,l,randint(20,50),randint(20,70),choice(["red","black"]))


      

    draw_string("G-22 Raptor",100,110,"cyan",bg)




bg=(randint(0,55),randint(0,55),randint(0,55))

game=True
psc=0
pl=3
pe=30
px=10
py=100
pw=9
ph=5
pc="white"


et=0
efast=False
ee=5
ex=280
ey=100
ew=15
eh=15
ec=(randint(0,255),randint(0,255),randint(0,255))


fill_rect(0,0,322,222,bg)

for i in range(0,322):
  i+=1
  lava_y=randint(180,210)
  fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(120,0,0)]))

for i in range(0,322):
  i+=1
  fill_rect(i,randint(0,5),5,randint(2,8),choice([(125,0,0),bg,"red"]))

while game:

  et+=0.01
  if et>randint(2,5):
    et=0
    efast=choice([0,1,1])
  
  draw_string("Energy[",5,0,"cyan",bg)
  fill_rect(76,3,int((pe/3)),12,pc)
  
  
  fill_rect(px,py,pw,ph,pc)
  
#moving aircraft
  
  ex-=1
  fill_rect(ex,ey,5,3,ec)
  fill_rect(ex-5,ey+5,5,3,ec)
  fill_rect(ex,ey+10,5,3,ec)
#erase spacecraft trail  
  fill_rect(ex+6,ey,5,3,bg)
  fill_rect(ex+1,ey+5,5,3,bg)
  fill_rect(ex+6,ey+10,5,3,bg)
  fill_rect(ex-5,ey+5,5,3,"red")
  
  
  if ex < -randint(10,30):
    ex=randint(250,350)
    ey=randint(20,180)
    ec=(randint(0,255),randint(0,255),randint(0,255))
    pe-=3
    fill_rect(76+int(pe/3),3,2,12,bg)
  
    fill_rect(px,py,pw,ph,(100,0,0))
    
    efast=choice([0,0,1])
    et=0
    
    for i in range(0,322):
      i+=1
      lava_y=randint(180,210)
      fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(120,0,0),(0,0,0)]))
              
  if keydown(KEY_OK):
    fill_rect(px+pw,py+1,322-px,3,"red")
    fill_rect(px+pw,py+1,322-px,3,bg)
    
    
  if keydown(KEY_LEFT):
    px-=1
    fill_rect(px+pw,py,1,ph,bg)  
  
  if keydown(KEY_RIGHT):
    px+=1
    fill_rect(px-1,py,1,ph,bg)  
  
  if keydown(KEY_RIGHT):
    px+=1
    fill_rect(px-1,py,1,ph,bg)  
  
  if keydown(KEY_UP):
    py-=1
    fill_rect(px,py+ph,pw,1,bg)  
    
  if keydown(KEY_DOWN):
    py+=1
    fill_rect(px,py-1,pw,1,bg)  
    
  if keydown(KEY_OK) and py+1 >= ey and py+1 <= ey+eh and px+pw<=ex+ew:
    fill_rect(ex-5,ey,randint(5,15),randint(5,15),(120,0,0))
    ee-=0.05
    psc+=randint(2,5)
    pe+=0.02
#enemy destroyed    
  if ee<1:
    ee=randint(5,10)
    ex=randint(250,500)
    ey=randint(20,180)
    ec=(randint(0,255),randint(0,255),randint(0,255))
    bg=(randint(0,255),randint(0,255),randint(0,255))
    fill_rect(0,0,322,222,bg)
    pe+=3
    psc+=randint(10,20)
#ceiling
    for i in range(0,322):
      i+=1
      fill_rect(i,randint(0,5),5,randint(2,8),choice([(125,0,0),bg,"red"]))

      #bottom/ ground
    
    for i in range(0,322):
      i+=1
      lava_y=randint(180,210)
      fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(120,0,0)]))
    
    
  if py>=180:
    py=180
    pe-=2
    fill_rect(76+int(pe/3),3,2,12,bg)
  
    fill_rect(px,py,pw,ph,(120,0,0))
    for i in range(0,322):
      i+=1
      lava_y=randint(180,210)
      fill_rect(i,lava_y,randint(2,5),200,choice([(255,0,0),(120,0,0)]))

  if py<=9:
    py=9
    pe-=2
    fill_rect(76+int(pe/3),3,2,12,bg)
  
    fill_rect(px,py,pw,ph,(120,0,0))
    for i in range(0,322):
      i+=1
      fill_rect(i,randint(0,5),5,randint(2,8),choice([(125,0,0),bg,"red"]))
  
  if px<1:
    px=1
    
  if px+pw>322:
    px=322-pw
  
  if pe<1:
    game=False
#pause game    
  if keydown(KEY_BACKSPACE):
    draw_string("(PAUSED)",110,100,"white",bg)
    while keydown(KEY_BACKSPACE):
      pass
    while not keydown(KEY_BACKSPACE):
      pass
    while keydown(KEY_BACKSPACE):
      draw_string("        ",110,100,bg,bg)
      pass
  if pe<20:
    fill_rect(px,py+ph,1,1,choice([(120,0,0),(255,0,0),bg,"black"]))
    fill_rect(px,py-1,pw,1,bg)
    
    py+=randint(0,1)

  if efast:
    for i in range(randint(1,3)):
      ex-=1
      fill_rect(ex+ew,ey,2,eh,bg)
  


#game over
draw_string("GAME OVER",100,100,"white",bg)      
draw_string("SCORE:"+str(psc),100,140,"cyan",bg)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.