# Game By: Wilson
frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromrandomimportrandintasRfromionimportkeydownasK#for rgb tuple value
H=255RED=(H,0,0)BLACK=(0,0,0)WHITE=(H,H,H)CYAN=(0,H,H)GREEN=(0,H,0)BLUE=(0,0,H)bg=BLACKF(0,0,322,222,bg)whilenotK(KEY_OK):F(0,10,322,3,BLUE)F(0,50,322,3,BLUE)STR("Pythagoras World",50,22,"white",bg)STR("Key [Backspace] = Pause/Unpause",5,110,"green",bg)STR("Use [ARROWS] to Avoid Rects",15,140,"cyan",bg)sleep(0.1)STR("( Press [OK] to START )",25,190,"white",bg)sleep(0.2)F(0,0,322,222,(0,0,0))F(0,20,322,2,"gray")F(0,200,322,2,"gray")whilenotK(KEY_OK):STR("________TIPS:_______",40,50,"gray",(0,0,0))STR("Rects with values higher",10,100,"white",(0,0,0))STR("than [40] are hard to destroy.",10,130,"white",(0,0,0))STR("Avoid the Dark Matter!",20,160,"cyan",(0,0,0))game=Truebg=(R(0,H),R(0,H),R(0,H))psc=0pe=35px=20py=100pw=10ph=5pc=(R(200,H),R(200,H),R(200,H))rx=R(300,500)ry=R(20,200)rw=R(20,60)rh=R(20,60)r_c=(R(0,H),R(0,H),R(0,H))rmass=(rw*rh)/5#rs can chase or change
#shape dimension
r_t=0r_g=Falser_chase=Falser_v=0# dark matter!
darkmx=R(322,500)darkmy=R(22,200)darkmw=R(20,80)darkmh=R(20,80)darkm_c=(R(0,25),R(0,25),R(0,25))# move r
defmove_Rect():globalrx,ry,rw,rh,r_crx-=1F(rx+rw,ry,1,rh,bg)# move meteor
defmove_darkmatter():globaldarkmx,darkmy,darkmw,darkmhdarkmx-=1F(darkmx+darkmw,darkmy,1,darkmh,bg)#move player
defmove_Left():globalpx,py,pw,ph,pcpx-=1F(px+pw,py,1,ph,bg)defmove_Right():globalpx,py,pw,ph,pc,bgpx+=1F(px-1,py,1,ph,bg)defmove_Up():globalpx,py,pw,ph,pc,bgpy-=1F(px,py+ph,pw,1,bg)defmove_Down():globalpx,py,pw,ph,pc,bgpy+=1F(px,py-1,pw,1,bg)# when keys pressed
defkeyListen():ifK(KEY_BACKSPACE):pause()ifK(KEY_LEFT):move_Left()ifK(KEY_RIGHT):move_Right()ifK(KEY_UP):move_Up()ifK(KEY_DOWN):move_Down()# game is paused/unpaused
defpause():ifK(KEY_BACKSPACE):STR("(PAUSED)",110,100,(R(0,H),R(0,H),R(0,H)),bg)whileK(KEY_BACKSPACE):passwhilenotK(KEY_BACKSPACE):passwhileK(KEY_BACKSPACE):STR("",110,100,bg,bg)pass# draw the main things
defdrawGame():STR("Player[",5,0,"cyan",(0,0,0))F(73,4,round(pe/3),11,pc)STR("Enemy[",200,0,"green",(0,0,0))F(258,4,round(rmass*0.02),11,(H,0,0))F(0,0,4,222,RED)F(darkmx,darkmy,darkmw,darkmh,darkm_c)F(px,py,pw,ph,pc)F(rx,ry,rw,rh,r_c)# Game over when pe is less
# than zero.
defgameEnd():globalbg,pscforiinrange(100):forjinrange(100):i=R(0,321)j=R(0,222)F(i,j,R(2,5),R(2,5),choice([BLACK,"white","gray"]))STR("GAME OVER",100,90,(R(0,H),R(0,H),R(200,H)),(0,0,0))STR("SCORE: "+str(psc),100,120,(R(200,H),R(200,H),R(200,H)),(0,0,0))defr_new():globalrx,ry,rw,rw,r_c,rmassrx=R(250,322)ry=R(36,140)rw=R(20,100)rh=R(40,150)r_c=(R(0,H),R(0,H),R(0,H))rmass=(rw*rh)/6F(0,22,322,222,bg)defdrawlava():foriinrange(0,322):i+=1F(i,R(20,25),R(2,5),R(5,15),choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))#ground
foriinrange(0,322):i+=1lavay=R(205,220)F(i,lavay,R(2,5),30,choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))drawlava()whilegame:# sometimes r will follow
r_chase=choice([1,0,1,0,0,0])drawGame()keyListen()move_Rect()move_darkmatter()# when rangle reaches left wall
ifrx<0-rw-R(10,25):r_new()pe-=2F(73+int(pe/3),4,2,11,(0,0,0))F(px,py,pw,ph,(H,0,0))F(258,4,70,11,(0,0,0))foriinrange(0,322):i+=1F(i,R(20,25),R(2,5),R(5,15),choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))foriinrange(0,322):i+=1lavay=R(205,220)F(i,lavay,R(2,5),30,choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))# if player gets hit, energy
ifpx+pw>=rxandpx<=rx+rwandpy+ph>=ryandpy<=ry+rh:F(px,py,pw,ph,RED)pe-=0.1F(73+int(pe/3),4,2,11,(0,0,0))px-=1# dark matter is unbreakable
ifpx+pw>=darkmxandpx<=darkmx+darkmwandpy+ph>=darkmyandpy<=darkmy+darkmh:F(px,py,pw,ph,choice([BLACK,RED]))pe-=2F(73+int(pe/3),4,2,11,(0,0,0))sleep(0.01)ifpe<1:game=Falseifr_chase:ifint(ry+rh/2)<py:ry+=1F(rx,ry-1,rw,1,bg)ifry>py:ry-=1F(rx,ry+rh,rw,1,bg)ifpy+ph>218:py=218-phpe-=0.02F(px,py,pw,ph,RED)F(73+int(pe/3),4,2,11,(0,0,0))ifpy<23:py=23pe-=0.02F(px,py,pw,ph,RED)F(73+int(pe/3),4,2,11,(0,0,0))# player touches lava on left
ifpx<3:px=3F(px,py,pw,ph,RED)F(73+int(pe/3),4,2,11,(0,0,0))pe-=0.2ifpx+pw>322:px=322-pwifK(KEY_OK):F(px+3,py,322,4,(R(0,H),R(0,H),R(0,H)))sleep(0.002)F(px+3,py,322,4,bg)# player is low on energy
ifpe<=20:F(px+R(-3,3),py,R(2,4),R(2,4),"orange")F(px,py,pw,ph,choice([RED,BLACK,bg]))F(px,py-1,pw,1,bg)py+=choice([0,0,1,0])ifdarkmx<0-darkmw-R(10,20):darkmx=R(500,800)darkmy=R(22,200)darkmw=R(40,100)darkmh=R(50,120)darkm_c=(R(0,35),R(0,35),R(0,35))# rs enemy shot
ifK(KEY_OK)andpy>=ryandpy+ph<=ry+rhandpx+pw<=rx+rw:F(px,py,pw,ph,"green")pe+=0.005rmass-=6F(258+round(rmass*0.02),4,2,11,(0,0,0))psc+=1F(rx,ry,rw,rh,"cyan")F(rx,ry,rw,rh,bg)foriinrange(R(5,20)):forjinrange(R(5,20)):i=rx+R(0,rw)j=ry+R(0,rh)F(i,j,R(2,5),R(2,5),choice(["cyan",BLACK,bg,r_c,bg]))# rmass reflects strengh of rangles
#player crashes into ceiling if py<=36:
ifpy<36:py=R(35,36)pe-=0.5F(73+int(pe/3),4,2,11,(0,0,0))F(px,py,pw,ph,(H,0,0))drawlava()#player crashes into ground
ifpy>200:py=R(199,200)pe-=0.5F(73+int(pe/3),4,2,11,(0,0,0))F(px,py,pw,ph,(H,0,0))drawlava()#rangle destroyed
ifrmass<1:r_new()pe+=(rw*rh)*0.0005psc+=R(15,35)bg=(R(0,H),R(0,H),R(0,H))F(0,22,322,222,bg)F(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.