fun game.
from kandinsky import fill_rect as F from time import * from random import * from random import randint as R from ion import * from ion import keydown as K from kandinsky import * from kandinsky import draw_string as STR critter_dir=R(1,4) critterx=100 crittery=100 c1=(R(0,125),R(0,125),R(0,125)) c2=(255,0,0) critterclock=0 rectx=300 recty=100 rectw=20 recth=40 rectc="black" H=255 RAND=(R(0,H),R(0,H),R(0,H)) 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() F(0,0,320,222,NR) fell=False jump=False fall=False jump_c=0 max_j=200 area=R(10,25) bg=(0,0,0) faceLeft=False faceRight=True gy=200 fx=0 fh=R(20,100) fy=100 fw=R(100,200) fc=(R(0,100),R(0,100),R(0,100)) #(R(0,H),R(0,H),R(0,H)) game=True psc=0 pe=20 pscale=5 ph=26 px=30 py=fy-ph pw=20 pc=(0,0,120) pside=25 foodsize=2 foodx=R(40,200) foody=R(40,200) foodw=4*foodsize foodh=4*foodsize groundfall=False groundrise=False def drawfood(): F(foodx,foody,4*foodsize,4*foodsize,(0,250,0)) F(foodx+1*foodsize,foody+1*foodsize,foodsize*2,foodsize*2,(222,0,0)) def pLeft(): global px,py,pw,ph,bg,faceLeft faceLeft=True faceRight=False px-=1 F(px+pw,py,1,ph,bg) F(px,py+ph-4,pw,4,"green") def pRight(): global px,py,pw,ph,bg,faceRight,faceLeft faceRight=True faceLeft=False px+=1 F(px-1,py,1,ph,bg) F(px,py+ph-4,pw,4,"green") def pUp(): global px,py,pw,ph,bg py2=1 F(px,py+ph+1,pw,1,bg) def pDOWN(): global px,py,pw,ph,bg F(px,py-1,pw,1,bg) def drawP(): F(px,py,pw,ph,pc) if faceRight: F(px,py,pw,ph,pc) F(px+11,py+5,7,8,"cyan") if faceLeft: F(px,py,pw,ph,pc) F(px+1,py+5,7,8,"cyan") F(0,0,322,222,bg) for i in range(0,322): i+=R(2,6) F(i,R(0,15),R(6,12),R(5,25),choice(["black",(R(0,30),R(0,30),R(0,30))])) F(0,gy,322,100,(0,120,0)) world=0 while game: STR("Energy:"+str(round(pe)),2,0,"cyan",(0,0,0)) fall=True F(fx,fy,fw,fh,fc) if fall: py+=1 F(px-2,py-1,pw+2,5,bg) drawP() if K(KEY_LEFT): faceRight=False pLeft() if K(KEY_RIGHT): faceLeft=False pRight() if K(KEY_BACKSPACE) and jump_c<=max_j: F(px,py+ph-4,pw,4,(R(0,H),R(0,H),R(0,H))) jump_c+=1 jump=True else: fall=True if py+ph>=fy and py<fy and px+pw>=fx and px<=fx+fw: py=fy-ph fall=False jump_c=0 fill_rect(px,py,pw,ph+2,bg) if py>fy+fw:fall=True if jump_c==max_j: jump_c=0 fall=True jump=False if jump: fall=False jump=False py-=2 fill_rect(px,py+ph+1,pw,1,bg) jump_c+=1 if py<40: py=40 if px<1: px=1 if px>322: foodx=R(-50,410) foody=R(-40,20) fx=R(20,200) fy=R(130,190) fw=R(30,150) fh=R(100,200) area+=1 px=1 F(0,50,322,222,bg) F(fx,fy,fw,fh,fc) F(0,gy,322,100,(0,0,0)) if area>R(5,12): area=1 world+=1 px=2 pe+=R(5,10) fx=R(20,200) fy=R(130,190) fw=R(30,150) fh=R(100,200) fc=(R(150,H),R(150,H),R(150,H)) bg=(R(0,100),R(0,40),R(0,100)) F(0,0,322,222,bg) F(0,gy,322,100,(0,0,0)) psc+=5 foodx=R(-40,410) foody=R(-200,-20) for i in range(0,322): i+=R(2,6) F(i,R(0,15),R(6,12),R(5,25),choice(["black",(R(0,30),R(0,30),R(0,30))])) if py+ph>gy and px<=fx-1 or py+ph>=gy and px+pw+1>=fx+fw: py=gy-ph fall=False jump_c=0 max_j=200 #earth #player uses own energy #to help the earth if py+ph>=gy and px<=fx-1 or py+ph>=gy and px+pw+1>=fx+fw: F(px,py,pw,ph,choice([pc,(0,0,0),bg])) pe-=0.01 for i in range(0.0001): i=R(0,322) F(i,gy+R(0,4),R(1,2),R(1,2),choice([(0,255,0),(0,0,0),"cyan"])) if pe<0: game=False F(fx,fy,fw,fh,fc) #platform falling if py+ph>=fy and px+pw>=fx and px<=fx+fw: groundfall=True pass if groundfall: for i in range(3): F(fx,fy-1,fw,1,bg) fy+=1 if K(KEY_OK): STR("(PAUSED)",110,40,(R(0,H),R(0,H),R(0,H)),bg) while K(KEY_OK): pass while not K(KEY_OK): pass while K(KEY_OK): STR(" ",110,40,bg,bg) pass 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(200,st[i][1]) if Sy >= 200: 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)) if gy>222: groundfall=False if keydown(KEY_TOOLBOX) and faceRight==True: fill_rect(px+pw,py+12,322-px,3,(randint(100,255),randint(100,255),randint(100,255))) sleep(0.001) fill_rect(px+pw,py+12,322-px,3,bg) if keydown(KEY_TOOLBOX) and faceLeft==True: fill_rect(0,py+12,px,3,(randint(100,255),randint(100,255),randint(100,255))) sleep(0.001) fill_rect(0,py+12,px,3,bg) groundfall=False STR("World:"+str(world),180,0,"green",(0,0,0)) drawfood() if py>222: py=0 fall=True F(0,0,322,222,bg) fell=True if fell: pe-=10 jump=False F(0,200,322,50,(255,0,0)) if px+pw>=foodx and px<=foodx+foodw and py+ph>=foody and py<=foody: F(foodx,foody,foodw,foodh,bg) for i in range(0.0001): i=R(0,322) F(i,gy+R(0,4),R(1,2),R(1,2),choice(["yellow",(0,0,0),"green"])) foodx=R(-50,410) foody=R(-200,20) pe+=0.2 psc+=R(20,100) F(foodx,foody-1,foodw,1,bg) foody+=1 if foody>195 and foodx<fx or foody>195 and foodx+foodw>fx: foody=195 critterclock+=1 F(critterx,crittery,10,10,c1) F(critterx+2,crittery+2,2,2,"cyan") F(critterx+7,crittery+2,2,2,"cyan") if critter_dir==1: sleep(.005) critterx-=1 F(critterx+11,crittery,1,10,bg) if critter_dir==2: sleep(.005) critterx+=1 F(critterx-1,crittery,1,10,bg) if critter_dir==3: sleep(.005) crittery-=1 F(critterx,crittery+10,10,1,bg) if critter_dir==4: sleep(.005) crittery+=1 F(critterx,crittery-1,10,1,bg) if K(KEY_OK): sleep(0.05) critter_dir=randint(1,4) if critterx<2: critterx=2 critter_dir=choice([2,3,4]) if critterx+10>318: critterx=318-10 critter_dir=choice([1,3,4]) if crittery<2: crittery=2 critter_dir=choice([1,2,4]) if crittery+10>219: crittery>222 critter_dir=choice([1,2,3]) if critterclock>randint(100,200): critter_dir=choice([1,2,3,4]) critterclock=0 F(0,0,322,222,(0,0,0)) STR("GAME OVER",100,100,"green",(0,0,0)) STR("SCORE:"+str(psc),100,140,"white",(0,0,0))