# BY:
# WILSON
frommathimport*fromkandinskyimport*fromkandinskyimportfill_rectasFILLfromkandinskyimportdraw_stringasSTRfromrandomimport*fromionimport*fromtimeimport*bg=(0,0,0)FILL(0,0,322,222,bg)#home menu
FILL(0,10,322,5,"orange")FILL(0,60,322,5,"orange")FILL(0,180,322,3,"white")whilenotkeydown(KEY_OK):STR("GAME X Reloaded",80,30,"white",bg)STR("Key [OK] = SHOOT",50,80,"orange","black")STR("Key [Backspace] = Pause/Unpause",2,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)#beginning
game=True#speed of oncoming rectangles
rectspeed=0.5#slow speed
G=1*10**-2#medium speed
G2=1*10**-3#fast speed
G3=1*10**-8#background
bg=(randint(0,50),randint(0,50),randint(0,50))back_x=0back_y=0# player
pe=40px=40py=round(222/2)ps=0pc="cyan"pw=12ph=5fire=Falseammo_timer=0ammo_x=randint(600,900)ammo_y=randint(20,200)ammo_w=6ammo_h=6ammo_c=(randint(180,255),randint(180,255),randint(180,255))bullets=35bx=pxby=py+2bw=8bh=5bc="red"rect_x=back_x+randint(160,300)rect_y=back_y+randint(80,200)rect_w=randint(20,200)rect_h=randint(20,200)#just a tuple used for
#randomizing medium to light
#colors.
R=(randint(50,200),randint(50,200),randint(50,250))#rectangle color
rect_c=(randint(50,200),randint(50,200),randint(50,250))#screen
FILL(back_x,back_y,500,222,bg)#screen color
FILL(0,0,322,222,bg)#rectangle location, abstract think.
x=y=[10,30,60,90,120,150,180,210,240,270,300]#not sure if i need this
rw=randint(20,70)#not sure why this
foriinx:FILL(back_x+i,back_y,randint(40,60),randint(0,100),R)# MAIN GAME LOOP
#pe is player energy
whilepe>0:FILL(ammo_x,ammo_y,ammo_w,ammo_h,ammo_c)FILL(px,py,pw,ph,pc)FILL(px,py,3,2,(0,0,80))FILL(rect_x,rect_y,rect_w,rect_h,rect_c)STR("SCORE:"+str(int(ps)),90,0,"white",R)STR("E:"+str(int(pe)),2,0,"cyan",R)ifkeydown(KEY_LEFT):FILL(px+pw,py,1,ph,bg)px-=1FILL(rect_x,rect_y,1,rect_h,bg)#dont put this in the
#main loop because then
#the rect will not be able
#to push player back less
#than 20
ifpx<10:px=20ifpx+9<0:px=321ifkeydown(KEY_RIGHT):FILL(px-1,py,1,ph,bg)px+=1ifpx>60:px=60FILL(px-1,py,1,18,bg)FILL(rect_x+rect_w,rect_y,2,rect_h,bg)ifpx-9>321:px=0ifkeydown(KEY_UP):FILL(px,py+18,10,1,bg)rect_y+=1FILL(rect_x,rect_y-1,rect_w,1,bg)ifkeydown(KEY_DOWN):# py+=1
FILL(px,py-1,10,1,bg)rect_y-=1FILL(rect_x,rect_y+rect_h,rect_w,1,bg)ifpy<-18:py=222ifpy>222:py=0FILL(rect_x+rect_w,rect_y,2,rect_h,bg)ifrect_x+rect_w<-randint(10,40):pc=(randint(100,255),randint(100,255),randint(100,255))FILL(0,0,322,222,bg)bg=(randint(0,50),randint(0,50),randint(0,50))pe+=2ps+=randint(5,25)rect_x=back_x+randint(180,300)rect_y=randint(-10,190)rect_w=randint(10,200)rect_h=randint(10,200)rect_c=(randint(100,250),randint(100,250),randint(100,250))x=y=[10,30,60,90,120,150,180,210,240,270,300]rw=randint(20,70)FILL(0,0,322,222,bg)R=(randint(50,200),randint(50,200),randint(50,250))foriinx:FILL(back_x+i,back_y,randint(40,60),randint(0,100),R)#player collision
#player gets hit and losses
#energy
ifpx+pw>=rect_xandpx<=rect_x+rect_wandpy+ph>=rect_yandpy<=rect_y+rect_h:FILL(px,py,pw,ph,"red")pe-=0.5px-=1ifpx<0:px=40py=round(222/2)# rects gets shot
ifkeydown(KEY_OK)andfire==Trueandpy>=rect_yandpy+ph<=rect_y+rect_h:FILL(px,py,pw,ph,"green")pe+=1ps+=randint(10,20)fill_rect(rect_x,rect_y,rect_w,rect_h,"red")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(i,j,randint(2,5),randint(2,5),choice([rect_c,bg]))rect_x=randint(322,500)rect_y=randint(20,200)rect_c=(randint(50,200),randint(50,200),randint(50,250))rect_w=randint(20,200)rect_h=randint(20,200)ifkeydown(KEY_BACKSPACE):STR("( PAUSED )",110,100,"white",bg)whilekeydown(KEY_BACKSPACE):passwhilenotkeydown(KEY_BACKSPACE):passwhilekeydown(KEY_BACKSPACE):STR("",110,100,bg,bg)#time acceleration
accel=2*10**-4rectspeed+=accelforiinrange(rectspeed):rect_x-=1ifbullets>0:fire=Trueelse:fire=Falseifkeydown(KEY_OK)andbullets>0:bullets-=0.2fill_rect(px+3,py,322,5,"cyan")fill_rect(px+3,py,322,5,bg)#player gets more ammo
ifpx+pw>=ammo_xandpx<=ammo_x+ammo_wandpy+ph>=ammo_yandpy<=ammo_y+ammo_h:pe+=2bullets+=40FILL(ammo_x,ammo_y,ammo_w,ammo_h,bg)ammo_x=randint(2000,5000)ammo_y=randint(20,200)FILL(px,py,pw,ph,(80,0,0))FILL(ammo_x,ammo_y,ammo_w,ammo_h,bg)ammo_x-=1#ammo package gravitates
#to player
ifammo_y<py:ammo_y+=1ifammo_y>py:ammo_y-=1STR("Ammo:"+str(bullets),250,0,"white",R)#game over
foriinrange(100):forjinrange(90):i=randint(0,321)j=randint(0,222)FILL(i,j,randint(3,9),randint(3,9),(choice([100,150,200]),0,randint(0,50)))STR("GAME OVER",100,90,(255,)*3,(0,)*3)STR("SCORE: "+str(ps),100,120,"cyan",(0,)*3)
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.