[]][][][][[][][][][ GAME Z ][][][][][][][][][][[]
Key [Backspace] = Pause/Unpause. Use [ARROWS] to Avoid Rects. ——————————————————
from math import * from random import * from kandinsky import * from ion import * from time import * bg=(40,40,80) fill_rect(0,0,322,222,bg) while not keydown(KEY_OK): fill_rect(0,50,322,5,"white") draw_string("__GAME Z__",100,35,"white",bg) draw_string("Key [Backspace] = Pause/Unpause",5,110,"green",bg) draw_string("Use [ARROWS] to Avoid Rects",15,140,"cyan",bg) sleep(0.1) draw_string("( Press [OK] to START )",25,190,"white",bg) game=True bg=(randint(0,60),randint(0,60),randint(0,60)) psc=0 pe=35 px=20 py=100 pw=10 ph=5 pc="white" pstep=1 rect_x=randint(300,500) rect_y=randint(20,200) rect_w=20 rect_h=10 rect_c="red" #rects can chase or change #shape dimension rect_t=0 rect_g=False rect_chase=False rect_v=0 # move rect def move_Rect(): global rect_x,rect_y,rect_w,rect_h,rect_c # sleep(0.01) rect_x-=1 fill_rect(rect_x+rect_w,rect_y,1,rect_h,bg) #move player def move_Left(): global px,py,pw,ph,pc px-=1 fill_rect(px+pw,py,1,ph,bg) def move_Right(): global px,py,pw,ph,pc,bg px+=1 fill_rect(px-1,py,1,ph,bg) def move_Up(): global px,py,pw,ph,pc,bg py-=1 fill_rect(px,py+ph,pw,1,bg) def move_Down(): global px,py,pw,ph,pc,bg py+=1 fill_rect(px,py-1,pw,1,bg) def keyListen(): if keydown(KEY_LEFT): move_Left() if keydown(KEY_RIGHT): move_Right() if keydown(KEY_UP): move_Up() if keydown(KEY_DOWN): move_Down() def pause(): 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 def drawGame(): draw_string("Energy:"+str(int(pe)),12,0,"white",bg) draw_string("Score:"+str(int(psc)),190,0,"cyan",bg) fill_rect(0,0,4,222,"red") fill_rect(0,20,322,3,"gray") fill_rect(0,218,322,3,"gray") fill_rect(px,py,pw,ph,pc) fill_rect(rect_x,rect_y,rect_w,rect_h,rect_c) fill_rect(0,0,322,222,bg) def rect_grow(): pass while game: rect_chase=choice([1,0,1,0,0,0]) drawGame() keyListen() move_Rect() if rect_x<0-rect_w-20: rect_x=randint(250,322) rect_y=randint(-40,210) rect_w=randint(20,150) rect_h=randint(40,210) rect_c=(randint(0,255),randint(0,255),randint(0,255)) pe+=randint(0,2) psc+=randint(15,35) bg=(randint(0,60),randint(0,60),randint(0,60)) fill_rect(0,0,322,222,bg) # if player gets hit, energy # lost and push back if px+pw >= rect_x and px <= rect_x+rect_w and py+ph >= rect_y and py <= rect_y+rect_h: fill_rect(px,py,pw,ph,"red") pe-=0.1 px-=1 if pe<1: game=False if rect_chase: if int(rect_y+rect_h/2) < py: rect_y+=1 fill_rect(rect_x,rect_y-1,rect_w,1,bg) if rect_y>py: rect_y-=1 fill_rect(rect_x,rect_y+rect_h,rect_w,1,bg) if py+ph > 218: py = 218-ph fill_rect(px,py,pw,ph,"gray") pe-=0.02 if py < 23: py = 23 fill_rect(px,py,pw,ph,"gray") pe-=0.02 if px < 3: px = 3 fill_rect(px,py,pw,ph,"red") pe -= 0.2 if px+pw>322: px=322-pw if keydown(KEY_BACKSPACE): pause() #game over for i in range(100): for j in range(90): i=randint(0,321) j=randint(0,222) fill_rect(i,j,randint(3,9),randint(3,9),(choice([0,15,20]),0,randint(0,150))) draw_string("GAME OVER",100,90,(255,)*3,(0,)*3) draw_string("SCORE: "+str(psc),100,120,"cyan",(0,)*3)