This script is agame.
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=(0,0,0) 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)) level=1 wave=0 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" 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" 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)) #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" 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)) 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)) black_x=R(500,800) black_y=R(30,200) black_w=black_h=R(50,150) black_c="black" 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") F(fuel_x,fuel_y,fuel_w,fuel_h,fuel_c) F(fuel_x+fuel_w,fuel_y,1,fuel_h,bg) F(fuel_x,fuel_y,2,fuel_h,"white") F(fuel_x+fuel_w-2,fuel_y,2,fuel_h,"white") F(fuel_x,fuel_y,fuel_w,2,"white") F(fuel_x,fuel_y+fuel_h-2,fuel_w,2,"white") 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,"gray") F(rect_x+rect_w-1,rect_y,1,rect_h,"gray") F(rect_x,rect_y,rect_w,1,"gray") F(rect_x,rect_y+rect_h-1,rect_w,1,"gray") #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,"green") F(giant_rect_x+giant_rect_w-1,giant_rect_y,1,giant_rect_h,"green") F(giant_rect_x,giant_rect_y,giant_rect_w,1,"green") F(giant_rect_x,giant_rect_y+giant_rect_h-1,giant_rect_w,1,"green") 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,choice(['brown','black','purple',bg])) F(meteor_x+meteor_w-1,meteor_y,1,meteor_h,choice(['brown','black','purple',bg])) F(meteor_x,meteor_y,meteor_w,1,choice(['brown','black','purple',bg])) F(meteor_x,meteor_y+meteor_h-1,meteor_w,1,choice(['brown','black','purple',bg])) #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,"blue") F(black_x+black_w-1,black_y,1,black_h,"blue") F(black_x,black_y,black_w,1,"blue") F(black_x,black_y+black_h-1,black_w,1,"blue") #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(8,15) or keydown(KEY_VAR): 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") 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) 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,bg) 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) #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 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("[Shield]",153,2,choice(["cyan",bg]),(0,0,0)) #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) 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")