# GAME BY: WILSON
frommathimport*fromrandomimport*fromkandinskyimport*fromionimport*fromtimeimport*fromkandinskyimportfill_rectasFfromrandomimportrandintasRfromionimportkeydownasKH=255CYAN=(0,H,H)RED=(H,0,0)DARKRED=(135,0,0)DARKGREEN=(0,135,0)WHITE=(H,)*3BLACK=(0,)*3GREEN=(0,H,0)BLUE=(0,0,H)#screen width and height
SCRW=322SCRH=222SCRA=SCRW*SCRH#3 different platforms
GX=0GY=R(22,190)GW=R(20,140)GH=300GC=(R(0,H),R(0,H),R(0,H))GX2=R(80,180)GY2=R(22,190)GW2=R(20,140)GH2=300GC2=(R(0,H),R(0,H),R(0,H))GX3=R(200,290)GY3=R(40,190)GW3=R(20,140)GH3=300GC3=(R(0,H),R(0,H),R(0,H))area=1world=1game=True#back
bg=(R(0,70),R(0,20),R(0,70))#player
psc=0pe=9plife=3px=GX+10py=GY-R(16,25)pw=10ph=15pc=BLUEedash=Falseedash_timer=0eattacks=Falseeruns=Falseedefeated=Falsedooropen=Falseetimer=0echase=Falseedir=0#enemys energy
ex=R(180,280)ey=R(40,100)ew=R(9,28)eh=R(8,25)ee=0.5*ew*ehec=(R(0,H),R(0,H),R(0,H))fballdir=R(3,4)fballx=70fbally=120fballw=10fballh=10fballc=RED#player faces left or right
facingleft=Falsefacingright=Truedoorx=-10doory=-10doorw=16doorh=30doorc=BLACKvel=1xVel=0jumping=FalsejumpCount=0maxJump=22falling=Truedefpause():draw_string("(PAUSED)",110,100,(randint(0,255),randint(0,255),randint(0,255)),bg)whileK(KEY_OK):passwhilenotK(KEY_OK):passwhileK(KEY_OK):draw_string("",110,100,bg,bg)pass#main
F(0,22,319,221,bg)F(0,0,319,20,BLACK)F(0,210,322,50,(R(0,255),0,0))whilegame:etimer+=0.1draw_string("Level:"+str(world),100,2,"yellow",BLACK)draw_string(":["+str(plife),16,2,WHITE,BLACK)draw_string(":[",240,2,GREEN,BLACK)F(259,6,round(ee/4),10,RED)F(2,3,pw-2,ph-2,pc)F(4,5,5,5,CYAN)F(226,3,ew-3,eh-4,ec)F(227,6,5,4,WHITE)ifetimer>R(6,10):etimer=0edir=R(0,4)echase=choice([False,True])#enemy chases player
ifechase:ifex<px:foriinrange(3):edir=2ifex>px:edir=1ifey<py:edir=4ifey>py:edir=3ifdooropen:F(doorx,doory,doorw,doorh,(randint(0,255),randint(0,255),randint(0,255)))F(doorx,doory+doorh,doorw,2,WHITE)# 3 platforms
F(GX,GY,GW,GH,GC)F(GX2,GY2,GW2,GH2,GC2)F(GX3,GY3,GW3,GH3,GC3)#draw player & enemy
F(px,py,pw,ph,pc)F(px+2,py+2,7,5,CYAN)F(ex,ey,ew,eh,ec)F(ex+2,ey+4,8,4,choice([BLACK,WHITE,DARKGREEN]))ifK(KEY_LEFT):px+=-velF(px+pw,py,1,ph,bg)facingleft=Truefacingright=FalseifK(KEY_RIGHT):px+=velF(px-1,py,1,ph,bg)facingright=Truefacingleft=FalseifK(KEY_BACKSPACE)andjumping==Falseandfalling==False:jumping=TruejumpCount=1ifjumping:jumpCount+=1py-=3F(px,py+ph+1,pw,3,bg)#leave this in jumping scope
ifjumpCount==maxJump:jumping=Falsefalling=Trueeliffalling:ifpy+ph<=GYandpy+ph>=GY:falling=Falseelse:falling=True#careful with code here!
ifpx+pw>=GXandpx<=GX+GWandpy+ph>=GY:falling=Falseelse:falling=Trueifpy+ph>=GY+GH:falling=Trueifpx+pw>=GX2andpx<=GX2+GW2andpy+ph>=GY2:falling=Falseifpy+ph>=GY2+GH2:falling=Trueifpx+pw>=GX3andpx<=GX3+GW3andpy+ph>=GY3:falling=Falseifpy+ph>=GY3+GH3:falling=Trueiffalling:sleep(0.0001)py+=velF(px,py-1,pw,1,bg)#player teleports to new world
ifpx>doorxandpx+pw<doorx+doorwandpy+ph>=dooryandpy<=doory+doorhandedefeated==True:px=1bg=(R(0,80),R(0,20),R(0,80))ex=R(180,280)ey=R(40,100)ew=R(10,24)eh=R(8,20)ee=0.5*ew*ehfballw=R(5,15)fballh=fballwworld+=1edefeated=Falseec=(R(0,H),R(0,H),R(0,H))dooropen=Falsepe+=0.4psc+=R(5,10)F(0,22,322,222,bg)F(0,210,322,50,(H,0,0))py=20GX=R(0,10)GY=R(20,190)GW=R(20,140)GH=300GC=(R(0,55),R(0,55),R(0,55))GX2=R(80,180)GY2=R(20,190)GW2=R(20,140)GH2=300GC2=(R(0,25),R(0,25),R(0,25))GX3=R(200,280)GY3=R(40,190)GW3=R(20,140)GH3=300GC3=(R(0,10),R(0,10),R(0,10))ifpx+pw>321:px=321-pwifK(KEY_OK):pause()ifK(KEY_TOOLBOX)andfacingleft:F(0,py+4,px,3,(R(0,H),R(0,H),R(0,H)))sleep(0.0015)F(0,py+4,px,3,bg)ifK(KEY_TOOLBOX)andfacingright:F(px+pw,py+4,322-px,3,(randint(0,255),randint(0,255),randint(0,255)))sleep(0.0015)F(px+pw,py+4,322-px,3,bg)iffacingleft:F(px+1,py+7,1,3,WHITE)facingright=Falseiffacingright:F(px+pw-3,py+7,1,3,WHITE)facingleft=False#enemy is hit
ifK(KEY_TOOLBOX)andfacingleftandex<=pxandpy+4>=eyandpy+4<=ey+eh:F(ex,ey,ew,eh,RED)F(259,6,60,10,BLACK)ee-=0.2psc+=1pe+=0.01ifK(KEY_TOOLBOX)andfacingrightandex>=pxandpy+4>=eyandpy+4<=ey+eh:F(ex,ey,ew,eh,RED)F(259,6,60,10,BLACK)ee-=0.2psc+=1pe+=0.05#enemy destroyed
ifee<1:edefeated=Trueee=0doorx=GX3+4doory=GY3-doorhdooropen=Trueforiinrange(5):forjinrange(5):i=R(ex,ex+ew)j=R(ey,ey+eh)F(i,j,R(2,5),R(2,5),choice([BLACK,DARKRED,RED]))dooropen=Trueifdooropen:F(doorx,doory,doorw,doorh,(randint(0,255),randint(0,255),randint(0,255)))eattacks=Falseechase=Falseetimer=0edir=0ifex<1:ex=1edir=choice([2,3,4])ifex+ew>322:ex=322-ewedir=choice([1,3,4])ifey<=24:ey=24ifey+eh>222:ey=222-ehedir=choice([1,2,3])#enemy moves
ifedir==1:ex-=1F(ex+ew,ey,1,eh,bg)ifedir==2:ex+=1F(ex-1,ey,1,eh,bg)ifedir==3:ey-=1F(ex,ey+eh,ew,1,bg)ifedir==4:ey+=1F(ex,ey-1,ew,1,bg)ifey+eh>210:ey=210-ehee-=0.01F(ex,ey,ew,eh,RED)#boundaries
ifpx<0:px=0ifpy<20:py=20ifpy+ph>210:py=210-phF(px,py,pw,ph,RED)pe-=0.2#player energy loss
ifpx+pw>=exandpx<=ex+ewandpy+ph>=eyandpy<=ey+ehandedefeated==False:F(px,py,pw,ph,RED)sleep(0.001)pe-=0.001*ew*ehee+=0.1edir=R(1,4)ifplife<2:F(px,py,pw,ph,bg)ifee<50:F(ex,ey,ew,eh,"gray")ifpe<1:pe=9plife-=1ifpe>9:pe=1plife+=1ifpx+pw>exandpx<ex+ewandpy+ph>eyandpy+ph<ey+eh:pe-=0.1ee-=0.2py-=2iffbally<22:fbally=22fballdir=4iffbally+fballh>220:fbally=220-fballhfballdir=3F(fballx,fbally,fballw,fballh,bg)fballx=R(20,300)F(fballx,fbally,fballw,fballh,(R(50,255),0,R(0,55)))iffballdir==3:fbally-=1F(fballx,fbally+fballh,fballw,1,bg)iffballdir==4:fbally+=1F(fballx,fbally-1,fballw,1,bg)ifpx+pw>=fballxandpx<=fballx+fballwandpy+ph>=fballyandpy<=fbally+fballh:F(px,py,pw,ph,RED)pe-=0.2ifex+ew>=fballxandex<=fballx+fballwandey+eh>=fballyandey<=fbally+fballh:F(ex,ey,ew,eh,RED)ee-=0.2#game is over when plife < 1
ifplife<1:game=Falsedraw_string("GAME OVER",100,100,WHITE,bg)draw_string("SCORE:"+str(psc),100,140,CYAN,bg)
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.