from math import * from random import * from kandinsky import * from ion import * from time import * from kandinsky import fill_rect as F from kandinsky import draw_string as STR from ion import keydown as K from random import randint as R from random import choice as CH H=255 Mc=200 SW=322 SH=222 txt=(R(Mc,H),R(Mc,H),R(Mc,H)) bg=(R(0,50),R(0,50),R(0,50)) F(0,0,SW,SH,bg) clock=0 while not K(KEY_OK) and not keydown(KEY_EXE): clock+=0.40 if clock<1: for i in range(20): for j in range(20): i=R(0,SW) j=R(0,20) k=R(0,SW) l=R(150,SH) F(i,j,R(20,50),R(20,70),CH(["red","black"])) F(k,l,R(20,50),R(20,70),CH(["red","black"])) STR("G-22 Raptor",100,110,txt,bg) startimer=0 #amount of stars nb=R(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() F(0,0,320,SH,NR) #color definitions via RGB Decimal BLACK=(0,)*3 RED=(H,0,0) DARK_RED=(125,0,0) WHITE=(H,)*3 BLUE=(0,0,H) YELLOW=(H,H,0) MAGENTA=(H,0,H) GREEN=(0,H,0) BLACK=(0,)*3 CYAN=(0,H,H) 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=R(350,500) my=R(30,100) mw=R(20,50) mh=R(30,70) mc=(R(0,55),R(0,55),R(0,55)) enemies_destroyed=0 et=0 efast=False #enemy energy ee=5 ex=280 ey=100 ew=15 eh=15 ec=(R(0,H),R(0,H),R(0,H)) F(0,0,SW,SH,bg) #ceiling for i in range(0,SW): i+=1 F(i,R(20,25),R(2,5),R(5,15),CH([(125,0,0),BLACK,"red"])) #ground for i in range(0,SW): i+=1 lava_y=R(180,210) F(i,lava_y,R(2,5),Mc,CH([(H,0,0),BLACK,BLACK])) F(0,0,SW,22,(0,0,0)) #main loop while game: #enemy random speedup et+=0.01 if et>R(2,5): et=0 efast=CH([0,1,1]) STR("| World:"+str(world)+" |",108,2,bg,BLACK) STR("Player[",5,0,CYAN,BLACK) F(73,4,round(pe/3),11,pc) F(px,py,pw,ph,pc) F(px+4,py+1,4,2,CYAN) STR("Enemy[",240,0,"green",BLACK) F(298,4,round(ee),11,RED) #moving aircraft ex-=1 F(ex,ey,5,3,ec) F(ex-5,ey+5,5,3,ec) F(ex,ey+10,5,3,ec) #erase spacecraft trail F(ex+6,ey,5,3,bg) F(ex+1,ey+5,5,3,bg) F(ex+6,ey+10,5,3,bg) F(ex-5,ey+5,5,3,"red") #rects reach left if ex < -R(10,30): ee=R(5,10) F(258,4,round(ee)+10,11,BLACK) ex=R(250,350) ey=R(37,170) ec=(R(0,H),R(0,H),R(0,H)) pe-=R(3,5) F(73+int(pe/3),4,2,11,BLACK) F(px,py,pw,ph,RED) #[0,0,1] is a CH list of True or False efast=CH([0,0,1]) et=0 for i in range(0,SW): i+=1 lava_y=R(180,210) F(i,lava_y,R(2,5),Mc,CH([(H,0,0),(120,0,0),BLACK])) #player shoots if K(KEY_OK): F(px+pw-2,py,2,ph,"red") F(px+pw,py+1,SW-px,3,(R(100,H),R(100,H),R(100,H))) sleep(0.001) F(px+pw,py+1,SW-px,3,bg) if K(KEY_LEFT): px-=1 F(px+pw,py,1,ph,bg) if K(KEY_RIGHT): px+=1 F(px-1,py,1,ph,bg) if K(KEY_RIGHT): px+=1 F(px-1,py,1,ph,bg) if K(KEY_UP): py-=1 F(px,py+ph,pw,1,bg) if K(KEY_DOWN): py+=1 F(px,py-1,pw,1,bg) #enemy is hit. if K(KEY_OK) and py+1 >= ey and py+1 <= ey+eh and px+pw<=ex+ew: F(298,2,25,15,BLACK) for i in range(R(2,10)): for j in range(R(2,10)): i=ex+R(0,7) j=ey+R(0,7) F(i,j,R(2,5),R(2,5),CH([CYAN,BLACK,bg,ec])) F(258,4,round(ee),11,BLACK) ee-=0.06 psc+=R(2,5) pe+=0.02 #enemy destroyed if ee<1: ee=R(4,12) ex=R(250,500) ey=R(37,170) ec=(R(0,H),R(0,H),R(0,H)) enemies_destroyed+=1 pe+=3 pc=(R(50,Mc),R(50,Mc),R(50,Mc)) psc+=R(10,20) if enemies_destroyed>R(5,15): enemies_destroyed=0 ee=R(4,12) ex=R(250,500) ey=R(37,170) ec=(R(0,H),R(0,H),R(0,H)) bg=(R(0,H),R(0,H),R(0,H)) F(0,23,SW,SH,bg) pe+=3 pc=(R(50,Mc),R(50,Mc),R(50,Mc)) psc+=R(10,20) world+=1 #ceiling for i in range(0,SW): i+=1 F(i,R(20,25),R(2,5),R(5,15),CH([(R(0,75),R(0,75),R(0,75)),BLACK,(R(0,55),R(0,55),R(0,55))])) #bottom/ ground for i in range(0,SW): i+=1 lava_y=R(180,210) F(i,lava_y,R(2,5),Mc,CH([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))])) #player crashes into ceiling if py<=36: py=R(35,36) pe-=2 F(73+int(pe/3),4,2,11,BLACK) F(px,py,pw,ph,RED) for i in range(0,SW): i+=1 F(i,R(20,25),R(2,5),R(5,15),CH([(R(0,75),R(0,75),R(0,75)),BLACK,(R(0,55),R(0,55),R(0,55))])) #player crashes into ground if py>=180: py=R(179,180) pe-=2 F(73+int(pe/3),4,2,11,BLACK) F(px,py,pw,ph,RED) for i in range(0,SW): i+=1 lava_y=R(180,210) F(i,lava_y,R(2,5),Mc,CH([(R(0,75),R(0,75),R(0,75)),BLACK,(R(0,55),R(0,55),R(0,55))])) if px<1: px=1 if px+pw>SW: px=SW-pw if pe<1: game=False #pause game if K(KEY_BACKSPACE): STR("(PAUSED)",110,100,(R(0,H),R(0,H),R(0,H)),bg) while K(KEY_BACKSPACE): pass while not K(KEY_BACKSPACE): pass while K(KEY_BACKSPACE): STR(" ",110,100,bg,bg) pass #player low on energy if pe<20: F(px,py+ph,1,1,CH([(120,0,0),(H,0,0),bg,BLACK])) F(px,py-1,pw,1,bg) py+=R(0,1) if efast: for i in range(R(1,3)): ex-=1 F(ex+ew,ey,2,eh,bg) startimer+=0.1 if startimer>R(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=R(0,Mc) g=R(0,Mc) b=R(0,Mc) set_pixel(pr[i][0],pr[i][1],color(r,g,b)) F(mx,my,mw,mh,mc) F(mx+mw+1,my,1,mh,bg) mx-=1 if mx+mw<0-R(10,20): mx=R(400,600) mw=R(20,50) mh=R(30,100) my=R(30,180-mh) mc=(R(0,55),R(0,55),R(0,55)) if px+pw>=mx and px<=mx and py+ph>=my and py<=my+mh: px-=1 pe-=0.5 F(0,0,SW,20,bg) F(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 STR("GAME OVER",100,100,CH(["black","cyan","white"]),bg) STR("SCORE:"+str(psc),100,140,CH(["gray","green","yellow"]),bg)