from math import * from random import * from kandinsky import * from ion import * from time import * bg="black" fill_rect(0,0,322,222,bg) while not keydown(KEY_OK): draw_string("""=============================== Game Q ================================= key [*Arrows] Key Pad = Move key [Backspace] = Pause/Resume ( Press [OK] to Start ) """,0,0,"white",bg) fill_rect(0,6,322,5,(randint(0,100),randint(0,100),randint(0,100))) fill_rect(0,42,322,5,"red") detected=False bg=(0,0,0) game=True # enemy rectangle ex=randint(0,300) ey=randint(0,20) ew=randint(50,200) eh=randint(6,12) #speed factor used #in a for loop es=2 ec="red" # lava ftimer=0 fx=randint(0,310) fy=randint(-45,-20) fw=randint(10,40) fh=randint(6,10) fc="red" #player penergy=50 pscore=0 px=110 py=210 pw=15 ph=5 ps=10 pc="cyan" def move_left(): global px,py,pw,ph for i in range(8): px-=1 fill_rect(px+pw,py,3,ph,bg) if px<1: px=1 # player moves right # to go faster, just # increase int in range() def move_right(): global px,py,pw,ph for i in range(8): px+=1 fill_rect(px-2,py,2,ph,bg) if px+pw>321: px=321-pw def move_enemy(): global es, ey for i in range(es): sleep(0.005) ey+=1 def move_food(): global fx,fy,bg fx+=choice([-1,1]) fill_rect(fx,fy-1,fw,1,bg) fill_rect(fx,fy,fw,fh,fc) fy+=1 fill_rect(0,0,322,222,bg) while penergy>0: ftimer+=0.2 if ftimer>randint(1,2): move_food() move_enemy() draw_string("SCORE:"+str(int(pscore)),5,2,"white",bg) draw_string("Energy[",140,2,"white",bg) fill_rect(210,6,int(penergy),12,"cyan") fill_rect(ex,ey,ew,eh,ec) fill_rect(ex,ey-2,ew,2,bg) fill_rect(px,py,pw,ph,pc) if keydown(KEY_LEFT): pscore+=randint(0,1) penergy-=0.01 move_left() if keydown(KEY_RIGHT): penergy-=0.01 pscore+=randint(0,1) move_right() # enemy missed player if ey>222+eh+randint(10,20): ey=randint(0,30) ex=randint(0,310) ew=randint(50,220) eh=randint(10,25) ec=(randint(50,155),randint(50,155),randint(50,155)) penergy+=0.1 detected=choice([0,1]) fill_rect(0,0,322,222,"black") pscore+=5 if keydown(KEY_BACKSPACE): draw_string("(PAUSED)",110,100,"white",bg) while keydown(KEY_BACKSPACE): pass while not keydown(KEY_BACKSPACE): pass while keydown(KEY_BACKSPACE): draw_string(" ",110,100,bg,bg) pass # player is detected if detected: if ex<px: for i in range(es): sleep(0.0001) ex+=1 if ex>px: for i in range(es): sleep(0.0001) ex-=1 if px+pw>=ex and px<=ex+ew and py+ph>=ey and py<=ey+eh: penergy-=0.5 fill_rect(px,py,pw,ph,"red") #lava respawn if fy>240: fx=randint(0,310) fy=randint(-45,-20) fw=randint(40,120) fh=randint(6,10) fc="red"#(randint(100,255),randint(100,255),randint(100,255)) # player gets hit and losses # a significant amount # of energy. if px+pw>=fx and px<=fx+fw and py+ph>=fy and py<=fy+fh: penergy-=2 #fc=(randint(220,255),randint(220,255),randint(220,255)) fill_rect(px,py,pw,py,"red") fill_rect(210,6,int(penergy),12,fc) if keydown(KEY_OK): for i in range(0,py): fill_rect(px+4,0,5,i,"red") fill_rect(px+4,0,5,i,bg) fill_rect(0,0,322,222,"black") draw_string("GAME OVER",100,100,"green","black") draw_string("SCORE:"+str(pscore),100,140,"white","black")