from math import * from random import * from kandinsky import * from ion import * from time import * txt=(randint(200,255),randint(200,255),randint(200,255)) bg=(randint(0,50),randint(0,50),randint(0,50)) 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,txt,bg) startimer=0 #amount of stars nb=randint(20,60) st = [0]*nb pr = [0]*nb #background maybe eraser NR="black" def point(): return [randrange(320),0,randrange(1,10)] for i in range(nb): st[i] = point() fill_rect(0,0,320,222,NR) #color definitions via RGB Decimal BLACK=(0,)*3 RED=(255,0,0) DARK_RED=(125,0,0) WHITE=(255,)*3 BLUE=(0,0,255) YELLOW=(255,255,0) MAGENTA=(255,0,255) GREEN=(0,255,0) BLACK=(0,)*3 CYAN=(0,255,255) world=1 #bg=WHITE game=True psc=0 pl=3 pe=30 px=10 py=100 pw=9 ph=5 pc=WHITE #dark matter mx=randint(350,500) my=randint(30,100) mw=randint(20,50) mh=randint(30,70) mc=(randint(0,55),randint(0,55),randint(0,55)) enemies_destroyed=0 et=0 efast=False #enemy energy 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) #ceiling for i in range(0,322): i+=1 fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(125,0,0),(0,0,0),"red"])) #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),(0,0,0),(120,0,0)])) fill_rect(0,0,322,22,(0,0,0)) #main loop while game: #enemy random speedup et+=0.01 if et>randint(2,5): et=0 efast=choice([0,1,1]) draw_string("| World:"+str(world)+" |",108,2,bg,BLACK) draw_string("Player[",5,0,CYAN,BLACK) fill_rect(73,4,round(pe/3),11,pc) fill_rect(px,py,pw,ph,pc) fill_rect(px+4,py+1,4,2,CYAN) draw_string("Enemy[",240,0,"green",(0,0,0)) fill_rect(298,4,round(ee),11,RED) #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") #rects reach left if ex < -randint(10,30): ee=randint(5,10) fill_rect(258,4,round(ee)+10,11,BLACK) ex=randint(250,350) ey=randint(37,170) ec=(randint(0,255),randint(0,255),randint(0,255)) pe-=randint(3,5) fill_rect(73+int(pe/3),4,2,11,BLACK) fill_rect(px,py,pw,ph,RED) #[0,0,1] is a choice list of True or False 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)])) #player shoots if keydown(KEY_OK): fill_rect(px+pw-2,py,2,ph,"red") fill_rect(px+pw,py+1,322-px,3,(randint(100,255),randint(100,255),randint(100,255))) sleep(0.001) 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) #enemy is hit. if keydown(KEY_OK) and py+1 >= ey and py+1 <= ey+eh and px+pw<=ex+ew: fill_rect(298,2,25,15,BLACK) for i in range(randint(2,10)): for j in range(randint(2,10)): i=ex+randint(0,7) j=ey+randint(0,7) fill_rect(i,j,randint(2,5),randint(2,5),choice([CYAN,BLACK,bg,ec])) fill_rect(258,4,round(ee),11,BLACK) ee-=0.06 psc+=randint(2,5) pe+=0.02 #enemy destroyed if ee<1: ee=randint(4,12) ex=randint(250,500) ey=randint(37,170) ec=(randint(0,255),randint(0,255),randint(0,255)) enemies_destroyed+=1 pe+=3 pc=(randint(50,200),randint(50,200),randint(50,200)) psc+=randint(10,20) if enemies_destroyed>randint(5,15): enemies_destroyed=0 ee=randint(4,12) ex=randint(250,500) ey=randint(37,170) ec=(randint(0,255),randint(0,255),randint(0,255)) bg=(randint(0,255),randint(0,255),randint(0,255)) fill_rect(0,23,322,222,bg) pe+=3 pc=(randint(50,200),randint(50,200),randint(50,200)) psc+=randint(10,20) world+=1 #ceiling for i in range(0,322): i+=1 fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))])) #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([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))])) #player crashes into ceiling if py<=36: py=randint(35,36) pe-=2 fill_rect(73+int(pe/3),4,2,11,BLACK) fill_rect(px,py,pw,ph,RED) for i in range(0,322): i+=1 fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))])) #player crashes into ground if py>=180: py=randint(179,180) pe-=2 fill_rect(73+int(pe/3),4,2,11,BLACK) fill_rect(px,py,pw,ph,RED) for i in range(0,322): i+=1 lava_y=randint(180,210) fill_rect(i,lava_y,randint(2,5),200,choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))])) 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,(randint(0,255),randint(0,255),randint(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 #player low on energy 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) startimer+=0.1 if startimer>randint(3,7): startimer=0 for i in range(nb): st[i][1] += randrange(1,int(50/st[i][2])) z = st[i][2] Sx = st[i][0] Sy = min(240,st[i][1]) if Sy >= 240: st[i] = point() if pr[i] != 0: set_pixel(pr[i][0],pr[i][1],bg) pr[i] = [int(Sx),int(Sy)] r=randint(0,200) g=randint(0,200) b=randint(0,200) set_pixel(pr[i][0],pr[i][1],color(r,g,b)) fill_rect(mx,my,mw,mh,mc) fill_rect(mx+mw+1,my,1,mh,bg) mx-=1 if mx+mw<0-randint(10,20): mx=randint(400,600) mw=randint(20,50) mh=randint(30,100) my=randint(30,180-mh) mc=(randint(0,55),randint(0,55),randint(0,55)) if px+pw>=mx and px<=mx and py+ph>=my and py<=my+mh: px-=1 pe-=0.5 fill_rect(0,0,322,20,bg) fill_rect(px,py,pw,ph,"red") if px>=mx and px+pw<=mx and py>=my and py+ph<=my+mh: px=mx+mw+2 pe-=0.2 #game over draw_string("GAME OVER",100,100,choice(["black","cyan","white"]),bg) draw_string("SCORE:"+str(psc),100,140,choice(["gray","green","yellow"]),bg)