frommathimport*fromcmathimport*fromkandinskyimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromrandomimport*fromrandomimportrandintasRfromionimport*fromtimeimport*enemy_defeated=Falseedir_timer=0echase=Falseeshooting=Falseeshoot_timer=0edir=0ex=R(200,322)ey=R(0,50)ew=R(10,18)eh=R(12,30)ec=(R(0,150),R(0,150),R(0,150))#enemy energy
e_energy=round(ew*eh/4)defdraw_enemy():globalechase,edir,ex,ey,ew,eh,ecF(ex,ey,ew,eh,ec)F(ex+round(ew/5),ey+round(eh/6),round(ew/3),round(ew/5),"red")F(ex,ey,1,eh,"gray")F(ex+ew-1,ey,1,eh,"gray")F(ex,ey,ew,1,"gray")F(ex,ey+eh-1,ew,1,"gray")defmove_enemy():globalechase,edir_timer,edir,ex,ey,ew,eh,ec,bg# edir=choice([0,0,0,1,2,3,4])
edir_timer+=0.01ifedir_timer>=R(1,3):edir_timer=0echase=choice([True,False])ifechase:ifpx<ex:edir=1ifpx>ex:edir=2ifpy<ey:edir=3ifpy>ex:edir=4ifedir==1:ex-=5F(ex+ew,ey,5,eh,bg)eshooting=Trueifedir==2:ex+=5F(ex-5,ey,5,eh,bg)eshooting=Trueifedir==3:ey-=3F(ex,ey+eh,ew,3,bg)ifedir==4:ey+=3F(ex,ey-3,ew,3,bg)defcontain_enemy():globalechase,edir_timer,edir,ex,ey,ew,eh,ec,bg,box_x,box_y,box_w,box_hifex+ew<0:ex=0+ewifex+ew>322:ex=322-ewifey+eh<=0:ey=0edir=1ifey+eh>gy:ey=gy-ehedir=2defspawn_new_enemy():globale_energy,echase,edir_timer,edir,ex,ey,ew,eh,ec,bgechase=Falseenemy_defeated=Falsee_energy=round(ew*eh/4)edir_timer=0edir=0ex=R(0,310)ey=R(0,190)ew=R(10,18)eh=R(12,30)ec=(R(0,155),R(0,155),R(0,155))#////////////////////////
sleep(0.2)bonus_points=R(50,200)px=R(5,250)py=185pw=10ph=16pc=choice(["blue","yellow","cyan","black","white",(R(155,255),R(155,255),R(155,255))])pfaces_left=Falsepfaces_right=Truebg=(0,0,0)#start screen
F(0,0,322,222,bg)F(0,0,3,222,"blue")F(318,0,3,222,"blue")F(0,0,322,4,"blue")F(0,218,322,4,"blue")F(3,3,318,3,"white")F(3,30,318,3,"white")F(3,35,318,2,"white")F(R(260,280),0,R(8,45),222,(R(100,255),R(0,25),R(0,15)))F(0,200,322,5,"cyan")F(px,py,pw,ph,pc)F(px,py,pw,ph,pc)F(px,py-1,pw,1,bg)F(px,py,1,ph,"white")F(px+pw-1,py,1,ph,"white")F(px,py,pw,1,"white")F(px,py+ph,pw,1,"white")whilenotkeydown(KEY_OK)andnotkeydown(KEY_EXE):STR("RECTNINJA",100,10,"white",bg)STR("key [UP] = Float",100,60,(R(0,255),R(0,255),R(0,255)),bg)STR("key [Backspace] = Pause",15,80,"white",bg)STR("Key [Arrows] = Move",15,110,"cyan",bg)STR("Press [OK/EXE] key to Start",10,140,"orange",bg)F(0,200,322,3,"gray")gx=0gy=R(160,210)gw=322gh=6gc="cyan"defdraw_ground():globalgx,gy,gw,gh,gcF(gx,gy,gw,gh,gc)gravty=Truegame=Truehave_key=Falsesh_on=Falselevel_complete=Falsejump=False#sky color
bg=(0,0,R(0,255))fall_speed=1jump_max=1jump_time=0level=1plife=3px=20py=20pw=12ph=18pc=(R(0,90),R(0,90),R(0,90))psc=0sh_time=R(3,6)sh_x=R(2,310)sh_y=R(-200,-50)sh_w=15sh_h=15sh_c=(R(0,255),R(0,255),R(0,255))b_x=25b_y=R(50,150)b_w=R(10,70)b_h=R(6,40)b_c=(R(0,255),R(0,255),R(0,255))b_2_x=0b_2_y=R(30,160)b_2_w=R(10,70)b_2_h=R(6,45)b_2_c=(R(0,255),R(0,255),R(0,255))b_3_x=320-105b_3_y=R(30,160)b_3_w=R(10,70)b_3_h=R(6,30)b_3_c=(R(0,255),R(0,255),R(0,255))box_x=R(2,275)box_y=R(5,170)box_w=R(14,50)box_h=R(14,30)box_c=(R(0,255),R(0,255),R(0,255))defdraw_boxes():globalb_x,b_y,b_w,b_h,b_c,b_2_x,b_2_y,b_2_w,b_2_h,b_2_c,b_3_x,b_3_y,b_3_w,b_3_h,b_3_c,box_x,box_y,box_w,box_h,box_cF(b_x,b_y,b_w,b_h,b_c)F(b_x,b_y,2,b_h,"white")F(b_x+b_w-2,b_y,2,b_h,"white")F(b_x,b_y,b_w,2,"white")F(b_x,b_y+b_h-2,b_w,2,"white")F(b_x+b_w,b_y,1,b_h,bg)F(b_2_x,b_2_y,b_2_w,b_2_h,b_2_c)F(b_2_x,b_2_y,2,b_2_h,"white")F(b_2_x+b_2_w-2,b_2_y,2,b_2_h,"white")F(b_2_x,b_2_y,b_2_w,2,"white")F(b_2_x,b_2_y+b_2_h-2,b_2_w,2,"white")F(b_3_x,b_3_y,b_3_w,b_3_h,b_3_c)F(b_3_x,b_3_y,2,b_3_h,"white")F(b_3_x+b_3_w-2,b_3_y,2,b_3_h,"white")F(b_3_x,b_3_y,b_3_w,2,"white")F(b_3_x,b_3_y+b_3_h-2,b_3_w,2,"white")F(box_x,box_y,3,box_h,box_c)F(box_x+box_w-3,box_y,3,box_h,box_c)F(box_x,box_y,box_w,3,box_c)F(box_x,box_y+box_h-3,box_w,3,box_c)door_x=R(5,300)door_y=R(5,180)door_w=16door_h=24door_c="black"fill_rect(0,0,322,222,bg)whilegame:gravty=Truepsc+=0.01sh_c=(R(0,255),R(0,255),R(0,255))ifsh_on==Falseandhave_key==False:sh_y+=1F(px,py,pw,ph,pc)F(px,py-2,pw,2,bg)F(px,py,1,ph,"gray")F(px+pw-1,py,1,ph,"gray")F(px,py,pw,1,"gray")F(px,py+ph-1,pw,1,"gray")F(sh_x,sh_y,sh_w,sh_h,sh_c)F(sh_x,sh_y-1,sh_w,1,bg)F(sh_x,sh_y,2,sh_h,"white")F(sh_x+sh_w-2,sh_y,2,sh_h,"white")F(sh_x,sh_y,sh_w,2,"white")F(sh_x,sh_y+sh_h-2,sh_w,2,"white")ifkeydown(KEY_LEFT):pfaces_left=Truepfaces_right=Falsepx-=2F(px+pw,py,2,ph,bg)ifkeydown(KEY_RIGHT):pfaces_right=Truepfaces_left=Falsepx+=2F(px-2,py,2,ph,bg)ifpx+pw<0:px=322ifpx>322:px=0ifgravty:py+=choice([0,1])ifpy<0andenemy_defeated:F(0,0,322,222,"black")level+=1plife+=1psc+=bonus_pointswhilenotkeydown(KEY_OK):STR("Level complete.!",20,10,"cyan","black")STR("Bonus Points: "+str(bonus_points),20,55,"white","black")STR("Score:"+str(round(psc)),20,85,"yellow","black")STR("life: "+str(round(plife)),20,120,"purple","black")STR("Press [OK] to continue to",40,160,"magenta","black")STR("the next level.",40,190,"blue","black")#reset and spawn new random world.
bonus_points=R(100,500)bg=(R(0,255),R(0,255),R(0,255))F(0,0,322,222,bg)draw_ground()door_x=R(5,300)door_y=R(5,200)door_c=(R(0,255),R(0,255),R(0,255))key_1_x=R(5,300)key_1_y=R(5,200)b_x=R(300,400)b_y=R(60,150)b_w=R(70,120)b_h=R(6,10)b_c=(R(0,255),R(0,255),R(0,255))b_2_x=R(0,50)b_2_y=R(60,150)b_2_w=R(50,85)b_2_h=R(6,10)b_2_c=(R(0,255),R(0,255),R(0,255))b_3_x=R(225,280)b_3_y=R(60,150)b_3_w=R(40,70)b_3_h=R(6,10)b_3_c=(R(0,255),R(0,255),R(0,255))box_x=R(2,275)box_y=R(5,170)box_w=R(14,50)box_h=R(14,30)box_c=(R(0,255),R(0,255),R(0,255))py=0sh_time=0sh_on=Falsehave_key=Falseenemy_defeated=Falsee_energy=round(ew*eh/4)spawn_new_enemy()ifsh_on:sh_time-=0.0025F(px,py,pw,ph,(R(0,255),R(0,255),R(0,255)))STR("Shield: "+str(round(sh_time)),2,2,"cyan","black")ifsh_time<0:sh_on=Falsesh_time=5STR("",2,2,bg,bg)#game over when plife<1
ifplife<1:game=False# simple Pause/Resume code
ifkeydown(KEY_BACKSPACE):whilenotkeydown(KEY_TOOLBOX):STR("( PAUSED )",110,60,"blue","cyan")STR("(PRESS [TOOLBOX] KEY TO RESUME)",5,140)STR("",110,60,bg,bg)STR("(PRESS [TOOLBOX] KEY TO RESUME)",5,140,bg,bg)F(px+2,py+3,9,7,"white")ifsh_y+sh_h>=gy:sh_y=gy-sh_hifpx+pw>=sh_xandpx<=sh_x+sh_wandpy+ph>=sh_yandpy<sh_y+sh_h:F(sh_x,sh_y,sh_w,sh_h,bg)sh_on=Truesh_x=R(2,310)sh_y=R(-400,-250)ifb_x+b_w<-10:b_x=R(600,900)b_y=R(50,100)#player lands on platforms
#middle bottom board
b_x-=choice([0,1])ifpx+pw>=b_xandpx<=b_x+b_wandpy+ph>=b_yandpy<=b_y:gravty=Falsepy=b_y-phpx-=choice([0,1])F(px+pw,py,1,ph,bg)#left board
ifpx+pw>=b_2_xandpx<=b_2_x+b_2_wandpy+ph>=b_2_yandpy<=b_2_y:gravty=Falsepy=b_2_y-ph#right board
ifpx+pw>=b_3_xandpx<=b_3_x+b_3_wandpy+ph>=b_3_yandpy<=b_3_y:gravty=Falsepy=b_3_y-ph#gy is ground
ifpy+ph>=gy:py=gy-phb_2_y+=choice([0,0,0,1])ifb_x+b_w<-5:b_x=322b_w=R(10,70)b_h=R(6,45)b_c=(R(0,255),R(0,255),R(0,255))ifb_2_y>200:F(b_2_x,b_2_y-1,b_2_w,b_2_h,bg)b_2_y=0b_2_w=R(10,70)b_2_h=R(6,40)b_2_c=(R(0,255),R(0,255),R(0,255))ifb_3_y+b_3_h<0:b_3_y=200b_3_w=R(10,75)b_3_h=R(6,30)b_3_c=(R(0,255),R(0,255),R(0,255))F(b_2_x,b_2_y-1,b_2_w,1,bg)F(b_3_x,b_3_y+b_3_h,b_3_w,1,bg)ifjump:py-=R(1,2)F(px,py+ph,pw,2,bg)jump_max-=0.1ifjump_max<0:jump=Falsejump_max=1ifpy<=1:py=1ifkeydown(KEY_UP):py-=1F(px,py+ph,pw,2,bg)draw_ground()draw_enemy()draw_boxes()move_enemy()contain_enemy()ifpx+pw>=box_xandpx<=box_x+box_wandpy<=box_y+2andpy>=box_y+2:py=box_y+2gravty=Falseifpx+pw>=box_xandpx<=box_x+box_wandpy+ph>=box_yandpy<=box_y:gravty=Falsepy=box_y-phifkeydown(KEY_OK)andpfaces_right:F(px+pw,py+4,322-px,2,(R(0,255),R(0,255),R(0,255)))F(px+4,py+3,8,6,"red")sleep(0.02)F(px+pw,py+4,322-px,2,bg)ifkeydown(KEY_OK)andpfaces_left:F(0,py+4,px,2,(R(0,255),R(0,255),R(0,255)))F(px,py+3,8,6,"red")sleep(0.02)F(0,py+4,px,2,bg)#player shoots enemy
ifkeydown(KEY_OK)andpfaces_leftandex+ew<pxandey+eh>=py+4andey<=py+6:e_energy-=1edir=R(3,4)ey+R(-5,5)psc+=R(2,5)STR(str(round(e_energy)),180,0)F(ex+R(-3,3),ey+R(-3,3),ew,eh,"red")ifkeydown(KEY_OK)andpfaces_rightandex>=px+pwandey+eh>=py+4andey<=py+6:e_energy-=1ey+R(-5,5)edir=R(3,4)psc+=R(2,5)STR(str(round(e_energy)),180,0)F(ex+R(-3,3),ey+R(-3,3),ew,eh,"red")#player gets caught or hit :-(
ifpx+pw>=exandpx<=ex+ewandpy+ph>=eyandpy<=ey+ehandsh_on==False:plife-=0.02F(px+R(-5,5),py+R(-5,5),pw,ph,"red")ife_energy<0:F(ex,ey,ew,eh,(R(0,120),0,0))edir_timer=0edir=0enemy_defeated=Truedoor_y=200F(door_x,0,20,222,(R(0,255),R(0,255),R(0,255)))F(door_x,0,2,222,"cyan")F(door_x+18,0,2,222,"cyan")ifpx>=door_xandpx<=door_x+20andenemy_defeated:py-=5door_y-=5#game over
sleep(1)F(0,0,322,222,"black")STR("GAME OVER",100,90,"red","black")sleep(1)STR("SCORE:",100,140,"white","black")sleep(1.1)STR(str(round(psc)),170,140,"cyan","black")
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.