drone316.py

Created by wperez274

Created on February 01, 2023

14 KB

Faced paced game. Avoid missiles, walls, etc.

Questions?:

wperez274@gmail.com

Good luck.


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 ion import *
from time import *
#calculator screen width, height in pixels
SW=322
SH=222

sleep(0.4)
bg=(R(0,50),R(0,50),R(0,50))
F(0,0,SW,SH,bg)

while not keydown(KEY_OK) and not keydown(KEY_EXE):
  STR("DRONE 3.14",100,10,"green",(20,0,40))
  STR("KEYs [Arrow] = 8 Directions",30,60,"yellow",bg)
  STR("KEY [OK] = Shoot",65,80,"white",bg)
  STR("KEY [Backspace] = Pause/Resume",10,100,"orange",bg)
  STR("(Press [OK] or [EXE] to Start)",15,160,"gray",bg)


laser_on=False

bg=(R(0,255),R(0,155),R(0,255))




#background effect
#harmless to player
back_x=0
back_y=190


stars_x=R(1200,1500)
stars_y=R(40,100)
stars_w=stars_h=R(0,2)
stars_c=(R(100,255),R(100,255),R(100,255))



wave=0
level=1
p_lives=3
pe=30
px=7
py=100
pw=12
ph=7
pc=(40,12,65)
pscore=0

fuel_x=R(500,800)
fuel_y=R(30,170)
fuel_w=fuel_h=9
fuel_c="green"

fuel_border_c=(R(0,255),R(0,255),R(0,255))

shield_on=False
shield_time=20
shield_x=R(350,500)
shield_y=R(22,200)
shield_w=8
shield_h=50
shield_c="pink"

shield_border_c=(R(0,255),R(0,255),R(0,255))

missle_x=R(300,500)
missle_y=R(500,1000)
missle_w=missle_h=2
missle_c=(R(0,55),R(0,55),R(0,55))

missle_border_c=(R(0,255),R(0,255),R(0,255))

#chases player
meteor_x=R(500,1000)
meteor_y=R(0,20)
meteor_w=R(25,100)
meteor_h=R(5,10)
meteor_c="red"

meteor_border_c=(R(0,255),R(0,255),R(0,255))

rect_x=R(550,1000)
rect_y=R(-50,200)
rect_w=R(40,100)
rect_h=R(80,150)
rect_c=(R(0,255),R(0,255),R(0,255))

rect_border_c=(R(0,255),R(0,255),R(0,255))

giant_rect_x=R(-100,500)
giant_rect_y=R(-1200,-800)
giant_rect_w=R(120,250)
giant_rect_h=R(120,450)
giant_rect_c=(R(0,55),R(0,15),R(0,25))

giant_border_c=(R(0,255),R(0,255),R(0,255))
black_x=R(500,800)
black_y=R(30,200)
black_w=black_h=R(50,150)
black_c="black"

black_border_c=(R(0,255),R(0,255),R(0,255))


F(0,0,SW,SH,bg)
F(0,0,SW,24,"black")


# main loop  
while p_lives>0:
  
  STR("Level:"+str(level),240,2,(20,12,45),(225,205,215))
  
  
  
  if level>3:
    black_x-=choice([0,1])
  
  fuel_x-=choice([0,1])
  rect_x-=choice([0,2,3])
  giant_rect_y+=choice([0,1,2])
  
  
  if level>6:
    meteor_x-=choice([0,1,2,4])
    meteor_y+=choice([0,2])

  F(px,py,pw,ph,pc)

  if laser_on:
    F(px,py,1,ph,"cyan")
    F(px+pw-1,py,1,ph,"cyan")
    F(px,py,pw,1,"cyan")
    F(px,py+ph-1,pw,1,"cyan")
  
  if laser_on==False:
    F(px,py,1,ph,"gray")
    F(px+pw-1,py,1,ph,"gray")
    F(px,py,pw,1,"gray")
    F(px,py+ph-1,pw,1,"gray")

#fuel
  F(fuel_x,fuel_y,fuel_w,fuel_h,fuel_c)
#erase trail residue
  F(fuel_x+fuel_w,fuel_y,1,fuel_h,bg)
#border/outline
  F(fuel_x,fuel_y,2,fuel_h,fuel_border_c)
  F(fuel_x+fuel_w-2,fuel_y,2,fuel_h,fuel_border_c)
  F(fuel_x,fuel_y,fuel_w,2,fuel_border_c)
  F(fuel_x,fuel_y+fuel_h-2,fuel_w,2,fuel_border_c)

#enemies below:
  F(rect_x,rect_y,rect_w,rect_h,rect_c)
  F(rect_x+rect_w,rect_y,5,rect_h,bg)

  F(rect_x,rect_y,1,rect_h,rect_border_c)
  F(rect_x+rect_w-1,rect_y,1,rect_h,rect_border_c)
  F(rect_x,rect_y,rect_w,1,rect_border_c)
  F(rect_x,rect_y+rect_h-1,rect_w,1,rect_border_c)
  
#giant rect
  F(giant_rect_x,giant_rect_y,giant_rect_w,giant_rect_h,giant_rect_c)
  F(giant_rect_x,giant_rect_y-2,giant_rect_w,2,bg)

  F(giant_rect_x,giant_rect_y,1,giant_rect_h,giant_border_c)
  F(giant_rect_x+giant_rect_w-1,giant_rect_y,1,giant_rect_h,giant_border_c)
  F(giant_rect_x,giant_rect_y,giant_rect_w,1,giant_border_c)
  F(giant_rect_x,giant_rect_y+giant_rect_h-1,giant_rect_w,1,giant_border_c)
  

  F(meteor_x,meteor_y,meteor_w,meteor_h,meteor_c)
  F(meteor_x+meteor_w,meteor_y,4,meteor_h,bg)
  F(meteor_x,meteor_y-2,meteor_w,2,bg)
  
  F(meteor_x,meteor_y,1,meteor_h,meteor_border_c)
  F(meteor_x+meteor_w-1,meteor_y,1,meteor_h,meteor_border_c)
  F(meteor_x,meteor_y,meteor_w,1,meteor_border_c)
  F(meteor_x,meteor_y+meteor_h-1,meteor_w,1,meteor_border_c)
  
#black box  
  F(black_x,black_y,black_w,black_h,black_c)
  F(black_x+black_w,black_y,2,black_h,bg)

#outline  
  F(black_x,black_y,1,black_h,black_border_c)  
  F(black_x+black_w-1,black_y,1,black_h,black_border_c)  
  F(black_x,black_y,black_w,1,black_border_c)  
  F(black_x,black_y+black_h-1,black_w,1,black_border_c)
#energy
  F(7,5,round(pe),10,"red")
#energy box/ border  
  F(5,3,105,2,"white")
  F(5,15,105,2,"white")
  F(5,3,2,14,"white")
  F(107,3,2,14,"white")
  
  if rect_x+rect_w<0:
    rect_x=R(250,400)
    rect_y=R(-60,200)
    rect_w=R(40,100)
    rect_h=R(80,150)
    rect_c=(R(0,255),R(0,255),R(0,255))
    pscore+=R(50,100)
    pe+=0.3
    wave+=1
    
  if wave>R(15,25):
    wave=0
    p_lives+=1
    sleep(1)
    F(0,0,SW,SH,"black")
    F(0,15,SW,3,"blue")
    F(0,18,SW,52,"cyan")
    F(0,70,SW,3,"blue")
    
    while not keydown(KEY_OK):
      
      STR("Level "+"["+str(level)+"]"+" cleared!!",70,36)
      STR("Lives: "+str(p_lives),100,100,"green","black")
      STR("Press [OK] to proceed",40,180,"orange","black")
    
    px=8
    py=100
    level+=1
    rect_x=R(500,1000)
    meteor_x=R(800,1200)
    black_x=R(1000,1400)
    shield_x=R(500,1000)
    missle_x=R(800,1500)
    giant_rect_x=R(-100,500)
    giant_rect_y=R(-1200,-800)

    rect_border_c=(R(0,255),R(0,255),R(0,255))
    meteor_border_c=(R(0,255),R(0,255),R(0,255))
    missle_border_c=(R(0,255),R(0,255),R(0,255))
    shield_border_c=(R(0,255),R(0,255),R(0,255))
    fuel_border_c=(R(0,255),R(0,255),R(0,255))
    giant_border_c=(R(0,255),R(0,255),R(0,255))
    black_border_c=(R(0,255),R(0,255),R(0,255))
      
        
    bg=(R(0,255),R(0,255),R(0,255))
    F(0,22,SW,SH,bg)

  if meteor_x+meteor_w<0-R(5,20):
    meteor_x=R(1400,3000)
    meteor_y=R(-20,150)
    meteor_w=R(25,100)
    meteor_h=R(5,10)
    


  if meteor_y+meteor_h>SH+R(20,50):
    meteor_x=R(200,800)
    meteor_y=R(-50,50)
    meteor_w=R(25,100)
    meteor_h=R(5,10)

  if pe>40:
    F(px,py,2,ph,"cyan")
    F(px+pw-2,py,2,ph,"red")
    F(px,py,pw,2,"cyan")
    F(px,py+ph-2,pw,2,"cyan")
  

  if keydown(KEY_OK):
    laser_on=True


    F(px+pw,py+1,SW-px,3,(R(0,25),R(100,255),R(100,255)))
    sleep(0.001)
    F(px+pw,py+1,SW-px,3,bg)
      

#limit energy
  if pe>=100:
    pe=100


#player shoots meteor
  if keydown(KEY_OK) and laser_on and meteor_y+meteor_h>=py+1 and meteor_y<=py+4:
    F(meteor_x,meteor_y,meteor_w,meteor_h,"black")
    sleep(0.04)
    F(meteor_x,meteor_y,meteor_w,meteor_h,bg)
    meteor_x=R(300,900)
    meteor_y=R(-200,-50)


#player shoots missle

  if keydown(KEY_OK) and laser_on and missle_y+missle_h>=py+1 and missle_y<=py+4:
    F(missle_x+R(-20,20),missle_y+R(-20,20),R(1,3),R(1,3),"gray")
    sleep(0.1)
    F(missle_x,missle_y,missle_w,missle_h,"blue")
    missle_x=R(300,900)
    missle_y=R(-200,-50)




#pause/resume game    
  if keydown(KEY_BACKSPACE):
    STR("(PAUSED)",110,50)
    while keydown(KEY_BACKSPACE):
      pass
    while not keydown(KEY_BACKSPACE):
      pass
    while keydown(KEY_BACKSPACE):
      STR("        ",110,50,bg,bg)    


#////keys/////////////


#player flies
  if keydown(KEY_LEFT):
    px-=3
    F(px+pw,py,3,ph,bg)

  if keydown(KEY_RIGHT):
    px+=3
    F(px-3,py,3,ph,bg)

  if keydown(KEY_UP):
    py-=2
    F(px,py+ph,pw,2,bg)

  if keydown(KEY_DOWN):
    py+=2
    F(px,py-2,pw,2,bg)

#




  if py<22:
    py=22
    F(0,py,SW,2,"red")
    F(0,0,SW,22,"black")
    pe-=0.2
  if py+ph>221:
    py=221-ph
    F(0,221,SW,2,"red")
    F(0,0,SW,22,"black")
    pe-=0.2
  if px<3:
    px=3
  if px+pw>318:
    px=318-pw
  if meteor_y>=py:
    meteor_y-=1
# collision, not good
  if px+pw>=rect_x and px<=rect_x+rect_w and py+ph>=rect_y and py<=rect_y+rect_h:
    pe-=0.3
    F(px,py,pw,ph,"red")
    F(rect_x,rect_y,rect_w,rect_h,pc)
    F(0,0,SW,22,"black")
    shield_on=False    
    
  
  if px+pw>=meteor_x and px<=meteor_x+meteor_w and py+ph>=meteor_y and py<=meteor_y+meteor_h:
    pe-=0.7
    F(px,py,pw,ph,"red")
    F(0,0,SW,22,"black")
    F(0,25,SW,SH,"red")
    sleep(0.05)
    F(0,0,SW,SH,bg)
    shield_on=False    
    

  if px+pw>=giant_rect_x and px<=giant_rect_x+giant_rect_w and py+ph>=giant_rect_y and py<=giant_rect_y+giant_rect_h:
    pe-=2
    F(px,py,pw,ph,"red")
    F(0,0,SW,22,"black")
    F(0,0,SW,SH,(70,0,10))
    sleep(0.05)
    F(0,0,SW,SH,bg)
    shield_on=False
    
    


    
  if fuel_x+fuel_w<0-R(2,10):
    fuel_x=R(700,1000)
    fuel_y=R(25,200)
    fuel_w=fuel_h=R(5,10)

  if black_x+black_w<0-R(20,50):
    black_x=R(500,1000)
    black_y=R(20,200)
    black_w=R(50,150)
    black_y=R(20,200)

#player crashes into 
#black box and losses lot of energy.      
  if px+pw>=black_x and px<=black_x+black_w and py+ph>=black_y and py<=black_y+black_h:
    F(0,0,SW,22,"black")
    F(px,py,pw,ph,"red")
    F(px-2,py,2,ph,"blue")
    F(px+pw,py,2,ph,"blue")
    F(px,py-2,pw,2,"blue")
    F(px,py+ph,pw,2,"blue")
    sleep(0.02)
    F(px-2,py,2,ph,bg)
    F(px+pw,py,2,ph,bg)
    F(px,py-2,pw,2,bg)
    F(px,py+ph,pw,2,bg)
    pe-=2
    shield_on=False    
          
#player grabs random fuel capsule
  if px+pw>=fuel_x and px<=fuel_x+fuel_w and py+ph>=fuel_y and py<=fuel_y+fuel_h:
    F(px,py,pw,ph,"cyan")
    F(px-2,py,2,ph,"pink")
    F(px+pw,py,2,ph,"pink")
    F(px,py-2,pw,2,"pink")
    F(px,py+ph,pw,2,"pink")
    sleep(0.2)
    F(px-2,py,2,ph,bg)
    F(px+pw,py,2,ph,bg)
    F(px,py-2,pw,2,bg)
    F(px,py+ph,pw,2,bg)
    pe+=fuel_w*2
    F(fuel_x,fuel_y,fuel_w,fuel_h,bg)
    fuel_x=R(500,1000)
    fuel_y=R(30,200)
    fuel_w=fuel_h=R(4,12)
    fuel_c=(R(0,255),R(0,255),R(0,255))
  
  if pe<8:
    F(px,py,pw,ph,choice(["red","white",bg]))
    F(px,py+ph,2,2,"red")
    F(px,py-1,pw,1,bg)
    py+=choice([0,0,1])
    
    

  if meteor_y<py:
    meteor_y+-R(1,2)
    
  if meteor_y>py:
    meteor_y-=R(1,2)

    
  missle_y-=R(1,2)
  
  if missle_x<= -R(10,20):
    missle_x=R(100,400)
    missle_y=R(250,500)
    missle_c=(R(0,255),R(0,255),R(0,255))


  if missle_y<=R(-100,-50):
    missle_y=R(400,800)
    missle_x=R(100,400)
    missle_c=(R(0,255),R(0,255),R(0,255))

  missle_w=R(1,2)

    
  if missle_x<px+6 and shield_on==False:
    missle_x+=2
    
  if missle_x>px+6 and shield_on==False:
    missle_x-=2
  
  
#/////////////////////////  

# player gets hit:(
# energy loss is high.

  if px+pw>=missle_x and px<=missle_x+missle_w and py+pw>=missle_y and py<=missle_y+missle_h and shield_on==False:
    F(px,py,pw,ph,"red")
    F(px+R(-20,20),py+R(-20,20),R(1,3),R(1,3),"green")
    missle_c=(R(0,255),R(0,255),R(0,255))
    pe-=1.5
    sleep(0.05)
    
    


  F(missle_x,missle_y,missle_w,missle_h,missle_c)

  if missle_y<=230:
    F(missle_x-6,218,11,4,"white")
    F(missle_x-7,218,1,4,bg)
    F(missle_x+7,218,1,4,bg)


  F(shield_x,shield_y,shield_w,shield_h,shield_c)
  F(shield_x+shield_w,shield_y,2,shield_h,bg)

  shield_x-=1

  shield_c=choice([bg,'blue','white'])
  
  if shield_x<=R(-20,-10):
    shield_x=R(1000,2000)
    shield_y=R(24,180)
      
  

  if px+pw>=shield_x and px<=shield_x+shield_w and py+pw>=shield_y and py<=shield_y+shield_h:
    shield_on=True

  
  
  if shield_on:
    shield_time-=0.05
    pc=choice([bg,'blue','white'])
    
  if shield_time<=0:
    shield_on=False
    shield_time=20
    pc=(40,12,65)
 
    
  pe-=0.01      
  
  
  if giant_rect_y>R(230,250):
    giant_rect_x=R(-100,500)
    giant_rect_y=R(-1200,-800)
    giant_rect_w=R(120,250)
    giant_rect_h=R(120,450)
    giant_rect_c=(R(0,55),R(0,15),R(0,25))



#slow down/change velocity
  if keydown(KEY_TOOLBOX):
    sleep(0.01)
      
  
  F(0,22,SW,2,"cyan")
  F(0,24,SW,2,"blue")


#spaceship spills fuel 
  if pe<20:
    F(px+R(1,10),py+R(1,12),R(1,3),R(1,3),"green")


  if pe<=0:
    sleep(0.5)
    pe=30
    #p_lives-=1
    rect_x=500
    meteor_x=750
    missle_y=R(500,1000)
    black_x=1000
    giant_rect_y=R(-1400,-1000)
    num_rock_x=1500
    px=10
    py=100
    F(0,90,SW,2,(0,0,255))
    F(0,92,SW,30,(0,255,255))
    F(0,120,SW,2,(0,0,255))
    
    sleep(1)    
    p_lives-=1
    STR("Lives: "+str(p_lives),120,96)
    sleep(1)  
    F(0,24,SW,200,bg)
      
    
  STR("x"+str(p_lives),120,2,"cyan","black")    


  if shield_on:
    STR("\u2126",153,2,choice(["cyan",bg]),(0,0,0))


  F(back_x,back_y,322,2,"red")

  F(back_x,back_y+2,322,150,'black')

  if keydown(KEY_UP):
    back_y+=1
    F(back_x,back_y-1,322,1,bg)
  
  if keydown(KEY_DOWN):
    back_y-=1
    F(back_x,back_y+2,322,1,bg)
    
  if back_y<=190:
    back_y=190
    
  if back_y>=219:
    back_y=219
      
  if py+ph>=back_y:
    py=back_y-ph
    F(back_x,back_y,322,2,"red")
    F(0,0,322,222,"red")
    sleep(0.1)
    F(0,0,322,222,bg)
    
    pe-=0.2
        

  if level>=15:
    F(stars_x,stars_y,stars_w,stars_h,stars_c)
    F(stars_x+5,stars_y,5,stars_h,bg)
    stars_x-=choice([2,5])

  if stars_x<=-20:
    stars_x=R(300,500)
    stars_y=py+R(-10,10)
    stars_w=stars_h=R(0,3)
    stars_c=choice([
    'blue','red','green','white'
    ])
    
  if stars_x<=250 and stars_y<py:
    stars_y+=choice([0,1])
    F(stars_x,stars_y-1,stars_w,1,bg)

  if stars_x<=250 and stars_y>py:
    stars_y-=choice([0,1])
    F(stars_x,stars_y+2,stars_w,1,bg)
  
  if px+pw>=stars_x and px<=stars_x+stars_w and py+ph>=stars_y and py<=stars_y+stars_h and shield_on==False:
    F(px,py,pw,ph,"red")
    F(px+R(-20,20),py+R(-20,20),R(1,3),R(1,3),"green")
    sleep(0.05)
    pe-=1.8
    
    


  if fuel_x<=280:
    fuel_y+=R(-2,2)
    fuel_x-=choice([0,1,2])
    
  if fuel_y<22:
    fuel_y=22
  if fuel_y>180:
    fuel_y=180
        


#debugtool
  if keydown(KEY_EXE):
    sleep(0.2)
    wave=25

  if level>=6:
    missle_w=missle_h=round(level/3)

#game over    
sx=450
sleep(1.2)
F(0,0,SW,SH,(0,0,0))
STR("Written by: Wilson",11,7,(R(100,255),R(100,255),R(100,255)),"black")


for i in range(10):
  F(px+R(-20,20),py+R(-20,20),R(1,3),R(1,3),"green")
sleep(1)



end_border=(R(0,255),R(0,255),R(0,255))
while p_lives<=0 and not keydown(KEY_OK):
  
  F(0,0,2,SH,end_border)
  F(318,0,2,SH,end_border)
  
  F(0,0,SW,2,end_border)
  F(0,219,SW,2,end_border)
  
  
  F(0,0,322,222,(0,0,0))

  if rect_x<250:
    rect_y+=R(-2,2)


  sleep(0.05)
  sx-=8
  if sx<170:
    sx=170
  STR("GAME OVER",100,80,(R(10,25),R(100,255),R(0,25)),"black")
  STR("SCORE:",100,120,(R(200,255),R(200,255),R(200,255)),"black")
  STR(str(pscore)+" ",sx,120,(R(100,255),R(100,255),R(100,255)),"black")

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.