# Game By: Wilson
frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*RED=(255,0,0)BLACK=(0,0,0)WHITE=(255,255,255)CYAN=(0,255,255)GREEN=(0,255,0)BLUE=(0,0,255)bg=BLACKfill_rect(0,0,322,222,bg)whilenotkeydown(KEY_OK):fill_rect(0,10,322,3,BLUE)fill_rect(0,50,322,3,BLUE)draw_string("Pythagoras World",50,22,"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)sleep(0.2)fill_rect(0,0,322,222,(0,0,0))fill_rect(0,20,322,2,"gray")fill_rect(0,200,322,2,"gray")whilenotkeydown(KEY_OK):draw_string("________TIPS:_______",40,50,"gray",(0,0,0))draw_string("Rects with values higher",10,100,"white",(0,0,0))draw_string("than [40] are hard to destroy.",10,130,"white",(0,0,0))draw_string("Avoid the Dark Matter!",20,160,"cyan",(0,0,0))game=Truebg=(randint(0,255),randint(0,255),randint(0,255))psc=0pe=35px=20py=100pw=10ph=5pc=(randint(200,255),randint(200,255),randint(200,255))rect_x=randint(300,500)rect_y=randint(20,200)rect_w=randint(20,60)rect_h=randint(20,60)rect_c=(randint(0,255),randint(0,255),randint(0,255))rectmass=(rect_w*rect_h)/5#rects can chase or change
#shape dimension
rect_t=0rect_g=Falserect_chase=Falserect_v=0# dark matter!
darkm_x=randint(322,500)darkm_y=randint(22,200)darkm_w=randint(20,80)darkm_h=randint(20,80)darkm_c=(randint(0,25),randint(0,25),randint(0,25))# move rect
defmove_Rect():globalrect_x,rect_y,rect_w,rect_h,rect_crect_x-=1fill_rect(rect_x+rect_w,rect_y,1,rect_h,bg)# move meteor
defmove_darkmatter():globaldarkm_x,darkm_y,darkm_w,darkm_hdarkm_x-=1fill_rect(darkm_x+darkm_w,darkm_y,1,darkm_h,bg)#move player
defmove_Left():globalpx,py,pw,ph,pcpx-=1fill_rect(px+pw,py,1,ph,bg)defmove_Right():globalpx,py,pw,ph,pc,bgpx+=1fill_rect(px-1,py,1,ph,bg)defmove_Up():globalpx,py,pw,ph,pc,bgpy-=1fill_rect(px,py+ph,pw,1,bg)defmove_Down():globalpx,py,pw,ph,pc,bgpy+=1fill_rect(px,py-1,pw,1,bg)# when keys pressed
defkeyListen():ifkeydown(KEY_BACKSPACE):pause()ifkeydown(KEY_LEFT):move_Left()ifkeydown(KEY_RIGHT):move_Right()ifkeydown(KEY_UP):move_Up()ifkeydown(KEY_DOWN):move_Down()# game is paused/unpaused
defpause():ifkeydown(KEY_BACKSPACE):draw_string("(PAUSED)",110,100,(randint(0,255),randint(0,255),randint(0,255)),bg)whilekeydown(KEY_BACKSPACE):passwhilenotkeydown(KEY_BACKSPACE):passwhilekeydown(KEY_BACKSPACE):draw_string("",110,100,bg,bg)pass# draw the main things
defdrawGame():draw_string("Player[",5,0,"cyan",(0,0,0))fill_rect(73,4,round(pe/3),11,pc)draw_string("Enemy[",200,0,"green",(0,0,0))fill_rect(258,4,round(rectmass*0.02),11,(255,0,0))fill_rect(0,0,4,222,"red")fill_rect(darkm_x,darkm_y,darkm_w,darkm_h,darkm_c)fill_rect(px,py,pw,ph,pc)fill_rect(rect_x,rect_y,rect_w,rect_h,rect_c)# Game over when pe is less
# than zero.
defgameEnd():globalbg,pscforiinrange(100):forjinrange(100):i=randint(0,321)j=randint(0,222)fill_rect(i,j,randint(2,5),randint(2,5),choice(["black","white","gray"]))draw_string("GAME OVER",100,90,(randint(0,255),randint(0,255),randint(200,255)),(0,0,0))draw_string("SCORE: "+str(psc),100,120,(randint(200,255),randint(200,255),randint(200,255)),(0,0,0))defrect_spawn():globalrect_x,rect_y,rect_w,rect_w,rect_c,rectmassrect_x=randint(250,322)rect_y=randint(36,140)rect_w=randint(20,100)rect_h=randint(40,150)rect_c=(randint(0,255),randint(0,255),randint(0,255))rectmass=(rect_w*rect_h)/6fill_rect(0,22,322,222,bg)defdrawlava():foriinrange(0,322):i+=1fill_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))]))#ground
foriinrange(0,322):i+=1lava_y=randint(205,220)fill_rect(i,lava_y,randint(2,5),30,choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))drawlava()whilegame:# sometimes rect will follow
rect_chase=choice([1,0,1,0,0,0])drawGame()keyListen()move_Rect()move_darkmatter()# when rectangle reaches left wall
ifrect_x<0-rect_w-randint(10,25):rect_spawn()pe-=2fill_rect(73+int(pe/3),4,2,11,(0,0,0))fill_rect(px,py,pw,ph,(255,0,0))fill_rect(258,4,70,11,(0,0,0))foriinrange(0,322):i+=1fill_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))]))foriinrange(0,322):i+=1lava_y=randint(205,220)fill_rect(i,lava_y,randint(2,5),30,choice([(randint(0,75),randint(0,75),randint(0,75)),(0,0,0),(randint(0,55),randint(0,55),randint(0,55))]))# if player gets hit, energy
ifpx+pw>=rect_xandpx<=rect_x+rect_wandpy+ph>=rect_yandpy<=rect_y+rect_h:fill_rect(px,py,pw,ph,"red")pe-=0.1fill_rect(73+int(pe/3),4,2,11,(0,0,0))px-=1# dark matter is unbreakable
ifpx+pw>=darkm_xandpx<=darkm_x+darkm_wandpy+ph>=darkm_yandpy<=darkm_y+darkm_h:fill_rect(px,py,pw,ph,choice(["black","red"]))pe-=2fill_rect(73+int(pe/3),4,2,11,(0,0,0))sleep(0.01)ifpe<1:game=Falseifrect_chase:ifint(rect_y+rect_h/2)<py:rect_y+=1fill_rect(rect_x,rect_y-1,rect_w,1,bg)ifrect_y>py:rect_y-=1fill_rect(rect_x,rect_y+rect_h,rect_w,1,bg)ifpy+ph>218:py=218-phpe-=0.02fill_rect(px,py,pw,ph,"red")fill_rect(73+int(pe/3),4,2,11,(0,0,0))ifpy<23:py=23pe-=0.02fill_rect(px,py,pw,ph,"red")fill_rect(73+int(pe/3),4,2,11,(0,0,0))# player touches lava on left
ifpx<3:px=3fill_rect(px,py,pw,ph,"red")fill_rect(73+int(pe/3),4,2,11,(0,0,0))pe-=0.2ifpx+pw>322:px=322-pwifkeydown(KEY_OK):fill_rect(px+3,py,322,4,(randint(0,255),randint(0,255),randint(0,255)))sleep(0.002)fill_rect(px+3,py,322,4,bg)# player is low on energy
ifpe<=20:fill_rect(px+randint(-3,3),py,randint(2,4),randint(2,4),"orange")fill_rect(px,py,pw,ph,choice([RED,BLACK,bg]))fill_rect(px,py-1,pw,1,bg)py+=choice([0,0,1,0])ifdarkm_x<0-darkm_w-randint(10,20):darkm_x=randint(500,800)darkm_y=randint(22,200)darkm_w=randint(40,100)darkm_h=randint(50,120)darkm_c=(randint(0,35),randint(0,35),randint(0,35))# rects enemy shot
ifkeydown(KEY_OK)andpy>=rect_yandpy+ph<=rect_y+rect_handpx+pw<=rect_x+rect_w:fill_rect(px,py,pw,ph,"green")pe+=0.005rectmass-=6fill_rect(258+round(rectmass*0.02),4,2,11,(0,0,0))psc+=1fill_rect(rect_x,rect_y,rect_w,rect_h,"cyan")fill_rect(rect_x,rect_y,rect_w,rect_h,bg)foriinrange(randint(5,20)):forjinrange(randint(5,20)):i=rect_x+randint(0,rect_w)j=rect_y+randint(0,rect_h)fill_rect(i,j,randint(2,5),randint(2,5),choice(["cyan","black",bg,rect_c,bg]))# rectmass reflects strengh of rectangles
#player crashes into ceiling if py<=36:
ifpy<36:py=randint(35,36)pe-=0.5fill_rect(73+int(pe/3),4,2,11,(0,0,0))fill_rect(px,py,pw,ph,(255,0,0))drawlava()#player crashes into ground
ifpy>200:py=randint(199,200)pe-=0.5fill_rect(73+int(pe/3),4,2,11,(0,0,0))fill_rect(px,py,pw,ph,(255,0,0))drawlava()#rectangle destroyed
ifrectmass<1:rect_spawn()pe+=(rect_w*rect_h)*0.0005psc+=randint(15,35)bg=(randint(0,255),randint(0,255),randint(0,255))fill_rect(0,22,322,222,bg)fill_rect(0,0,322,20,(0,0,0))drawlava()#game over
gameEnd()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.