space_test_flight.py

Created by wperez274

Created on February 17, 2022

4.08 KB

Test your flight skills in an unrelenting environment. As an Astronaut, you must perfect your skills.

Good luck!

Sincerely,

Wilson


#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 time import *
from ion import *

#start menu
bg=(40,0,30)
sleep(0.1)
F(0,0,322,222,bg)
while not keydown(KEY_OK):
  draw_string("Space Test Flight",20,20,"cyan",bg)
  draw_string("Enter at your own risk",30,100,(randint(150,255),0,0),bg)
  draw_string("key [BACKSPACE] = Pause/Resume",12,160,"white",bg)
  draw_string("( Press [OK] to Start )",50,190,(randint(0,25),randint(150,255),0),bg)

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

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

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"

fill_rect(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

  draw_string("Life:"+str(round(life)),2,200,"green",bg)
  draw_string("[ARROW] Keys = MOVE",110,200,"cyan",bg)
  draw_string("Key [OK]=SHOOT framed rect.",10,0,"white",bg)
#NOTE: the player window is
# 50-250 for column
# 65-165 for rows

# player frame  
  fill_rect(framex,framey,3,frameh,"cyan")
  fill_rect(framex+framew,framey,3,frameh,"cyan")
  fill_rect(framex,framey,framew,3,"cyan")
  fill_rect(framex,framey+frameh,framew+2,3,"cyan")
  mc=(r,g,b)
  sleep(0.06)
  fill_rect(mx,my,mw,mh,mc)
  
  fill_rect(mx,my,mw,2,choice(["white","black"]))
  fill_rect(mx,my+mh,mw,2,choice(["white","black"]))
  fill_rect(mx,my,2,mh,choice(["white","black"]))
  fill_rect(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))
    fill_rect(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.6
    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,"red")
    sleep(0.2)
    fill_rect(0,0,322,222,bg)
    mx=R(40,250)
    my=R(20,150)
    mw=R(10,60)
    mh=R(10,120)
    life-=0.2
    
  if keydown(KEY_LEFT) or keydown(KEY_RIGHT) or keydown(KEY_UP) or keydown(KEY_DOWN):
    life-=0.01
  if life<=0:
    game=False
    
  if keydown(KEY_OK) and mx>=framex and mx+mw<=framex+framew and my>=framey and my+mh<=framey+frameh:
    fill_rect(mx,my,mx,mh,"red")
    fill_rect(framex,framey,framew,frameh,choice(["white","red",bg]))
    me-=0.5
    life+=0.2
    score+=R(5,25)

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

  
  #pause game    
  if keydown(KEY_BACKSPACE):
    draw_string("(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):
      draw_string("        ",110,100,bg,bg)
      pass
  
  fill_rect(mx-322,my,744,R(1,3),(R(0,30),R(0,30),R(0,30)))
  fill_rect(mx-322,my+mh,744,R(1,3),(R(0,30),R(0,30),R(0,30)))


  if me<1:
    me=R(3,6)
    life+=1
    score+=randint(50,100)
    fill_rect(mx,my,mw,mh,"red")
    fill_rect(mx,my,mw,mh,bg)
    
    for i in range(randint(5,20)):
      for j in range(randint(5,20)):
        i=mx+randint(0,mw)
        j=my+randint(0,mh)
        F(i,j,randint(2,5),randint(2,5),choice([mc,bg]))

    mx=randint(40,200)
    my=randint(20,200)
    mc=(randint(50,200),randint(50,200),randint(50,250))
    mw=randint(40,150)
    mh=randint(20,120)
    

  F(0,0,322,my-1,(R(150,255),R(150,255),R(150,255)))
  F(0,my+mh+1,322,200,"orange")
 



fill_rect(0,0,322,222,(0,0,0))
draw_string("GAME OVER",100,100,"white",(0,0,0))
draw_string("SCORE: "+str(score),100,140,"yellow",(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.