space_test_flight_v_3.py

Created by wperez274

Created on February 18, 2022

5.84 KB

A fast paced and challenging game where you must avoid crashing into walls or objects..

Good luck!


#By: Wilson
from math import *
from random import *
from random import randint as R
from kandinsky import *
from kandinsky import fill_rect as F
from kandinsky import draw_string as STR
from time import *
from ion import *

#start menu
bg=(0,0,0)
sleep(0.1)
F(0,0,322,222,bg)
while not keydown(KEY_OK):
  STR("Space Test Flight",20,15,"cyan",bg)
  STR("Enter at your own risk",30,50,(randint(150,255),0,0),bg)
  STR("key [BACKSPACE] = Pause/Resume",12,90,"orange",bg)
  STR("keys [ARROW] = MOVE",70,120,(200,205,210),bg)
  STR("Key [OK] = SHOOT framed rects.",10,150,"yellow",bg)
  STR("( Press [OK] to Start )",50,190,(randint(0,25),randint(150,255),0),bg)

r=R(0,255)
g=R(0,255)
b=R(0,255)

life=3
score=0
game=True
bg=(R(0,55),R(0,25),R(0,25))

mtargets_destroyed=0
level=1

ceil_c=(R(200,255),R(200,255),R(200,255))
ground_c=(R(0,155),R(0,155),R(0,155))

me=R(2,6)
mx=R(40,260)
my=R(20,150)
mw=R(10,20)
mh=R(10,20)

ground_y=my

framex=56
framey=65
framew=200
frameh=100
framec="cyan"

F(0,0,322,222,bg)
while game:
  r+=1
  g+=1
  b+=1
  if r>255:r=0
  if g>255:g=0
  if b>255:b=0

  STR("Life:"+str(round(life)),0,0,"cyan",(0,0,0))
  STR("AREA:"+str(level),80,0,"green",(0,0,0))
  STR("Destroyed:"+str(mtargets_destroyed),180,0,"yellow",(0,0,0))
  
  
  F(framex,framey,3,frameh,"cyan")
  F(framex+framew,framey,3,frameh,"cyan")
  F(framex,framey,framew,3,"cyan")
  F(framex,framey+frameh,framew+2,3,"cyan")
  mc=(r,g,b)
  sleep(0.06)
  F(mx,my,mw,mh,mc)
  
  F(mx,my,mw,2,choice(["white","black"]))
  F(mx,my+mh,mw,2,choice(["white","black"]))
  F(mx,my,2,mh,choice(["white","black"]))
  F(mx+mw-2,my,2,mh,choice(["white","black"]))
  mx-=R(1,3)
  my-=R(1,2)
  mw+=R(2,6)
  mh+=R(2,5)
  
  if keydown(KEY_LEFT):
    mx+=5
    life-=0.01
  
  if keydown(KEY_RIGHT):
    mx-=5
    life-=0.01
  if keydown(KEY_DOWN):
    my-=7
    life-=0.01
  if keydown(KEY_UP):
    my+=5
    life-=0.01
  if mx+mw<0 or mx>321 or my>222 or my+mh<0 or mh>250:
    bg=(R(0,150),R(0,150),R(0,150))
    F(0,0,322,222,bg)
    me=R(2,6)
    mx=R(40,250)
    my=R(20,150)
    mw=R(10,60)
    mh=R(10,60)
    r=R(0,255)
    g=R(0,255)
    b=R(0,255)
    life+=0.2
    score+=20
    score+=R(10,20)
    
  if mx+mw>=50 and mh>=140 and mx<=250 and my+mh>65 and my<=165:
    fill_rect(0,0,322,222,choice(["red","black"]))
    sleep(0.2)
    F(0,0,322,222,bg)
    mx=R(40,250)
    my=R(20,100)
    mw=R(10,60)
    mh=R(15,50)
    life-=0.4
    
  if keydown(KEY_LEFT) or keydown(KEY_RIGHT) or keydown(KEY_UP) or keydown(KEY_DOWN):
    life-=0.01
  if life<=0:
    game=False
#rect/wall hit    
  
  if keydown(KEY_OK):
    F(round((framex+framew/2))-25,round((framey+frameh/2))-2,50,2,"gray")
    F(round((framex+framew/2))-2,round((framey+frameh/2))-25,2,50,"gray")
    
  if mx>=framex and mx+mw<=framex+framew and my>=framey and my+mh<=framey+frameh:
    F(round((framex+framew/2))-25,round((framey+frameh/2))-4,50,4,"red")
    F(round((framex+framew/2))-4,round((framey+frameh/2))-25,4,50,"red")
    F(framex,framey,framew,3,"red")
    F(framex,framey+frameh,framew,3,"red")
    F(framex,framey,3,frameh,"red")
    F(framex+framew,framey,3,frameh,"red")

  if keydown(KEY_OK) and mx>=framex and mx+mw<=framex+framew and my>=framey and my+mh<=framey+frameh:
    F(mx,my,mx,mh,"red")
    F(framex,framey,framew,frameh,choice(["white","red",bg]))
    F(round((framex+framew/2))-25,round((framey+frameh/2))-2,50,2,(R(0,255),R(0,255),R(0,255)))
    F(round((framex+framew/2))-2,round((framey+frameh/2))-25,2,50,(R(0,255),R(0,255),R(0,255)))
    STR("TARGET WAS HIT!",130,200,"green",(0,0,0))    
    me-=0.5
    life+=0.2
    score+=R(10,25)
    mc=(R(20,255),R(20,255),R(20,255))
    

  if mx>=framex and mx+mw<=framex+framew and my>=framey and my+mh<=framey+frameh:
    F(framex,framey,3,frameh,"red")
    F(framex+framew,framey,3,frameh,"red")
    F(framex,framey,framew,3,"red")
    F(framex,framey+frameh,framew+2,3,"red")
  

  if keydown(KEY_BACKSPACE):
    STR("(PAUSED)",110,100,(R(0,255),R(0,255),R(0,255)),bg)
    while keydown(KEY_BACKSPACE):
      pass
    while not keydown(KEY_BACKSPACE):
      pass
    while keydown(KEY_BACKSPACE):
      STR("        ",110,100,bg,bg)
      pass
  
  F(mx-322,my,744,R(1,3),(R(0,30),R(0,30),R(0,30)))
  F(mx-322,my+mh,744,R(1,3),(R(0,30),R(0,30),R(0,30)))

#target destroyed
  if me<1:
    me=R(3,6)
    mtargets_destroyed+=1
    life+=1
    score+=randint(50,100)
    F(mx,my,mw,mh,"red")
    F(mx,my,mw,mh,bg)
    STR("TARGET DESTROYED!!",90,200,"cyan",(0,0,0))
    
    for i in range(R(5,20)):
      for j in range(R(5,20)):
        i=mx+R(0,mw)
        j=my+R(0,mh)
        F(i,j,R(2,5),R(2,5),choice([mc,bg]))

    mx=R(40,200)
    my=R(20,200)
    mc=(R(20,255),R(20,255),R(20,255))
    mw=R(40,150)
    mh=R(20,120)
    
  F(framex,framey+3,framew,3,"white")
  F(framex,framey+frameh-3,framew,3,"white")
  F(framex+3,framey,3,frameh,"white")
  F(framex+framew-3,framey,3,frameh,"white")
    


#ceiling & ground colors
  
  
  if keydown(KEY_UP):
    F(0,my-R(11,13),322,3,"white")

  if keydown(KEY_DOWN):
    F(0,my+mh+R(11,12),322,2,"black")

  if mtargets_destroyed>R(4,8):
    level+=1
    sleep(0.5)
    while not keydown(KEY_OK):

      STR("Level completed!",100,50,"white",(0,0,0))
      STR("Press [OK] to continue mission",10,160,"cyan",(0,0,0))
    
    
    mtargets_destroyed=0
    ceil_c=(R(200,255),R(200,255),R(200,255))
    ground_c==(R(0,155),R(0,155),R(0,155))
    bg=(R(0,255),R(0,255),R(0,255))
    F(0,0,322,222,bg)
    F(0,my-10,322,10,ceil_c)
    F(0,my+mh+1,322,10,ground_c)

  
  F(0,my-10,322,10,ceil_c)
  F(0,my+mh+1,322,10,ground_c)



sleep(0.2)
F(0,0,322,222,(255,0,0))
sleep(0.1)
F(0,0,322,222,(0,0,0))
sleep(0.1)
F(0,0,322,222,(255,0,0))
sleep(0.2)
F(0,0,322,222,(0,0,0))
sleep(0.2)

F(0,20,322,2,"red")
F(0,200,322,2,"red")

STR("GAME OVER",100,100,(R(200,255),R(200,255),R(200,255)),(0,0,0))
sleep(1)
STR("SCORE: "+str(score),100,140,(R(100,255),R(100,255),R(100,255)),(0,0,0))

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.