fromkandinskyimport*fromionimport*fromtimeimport*backColor=(255,)*3plateforms_color=(0,0,200)death_color=(0,0,0)shoot_color=(255,100,0)trainee=Falselevel=0classEntity():def__init__(self,x,y,width,height,speed,ma=True):self.x=xself.y=yself.width=widthself.height=heightself.speed=speedself.move_alone=maself.chute=0self.gx=self.x+int(self.width/2)self.gy=self.y+self.heightself.dead=Falseself.drawing=[]self.shooting=Nonedefset_drawing_inverse(self):self.drawing_inverse=[None,]*len(self.drawing)foriinrange(len(self.drawing)):j=self.drawing[i]self.drawing_inverse[i]=[self.width-j[0]-j[2],j[1],j[2],j[3],j[4]]defcontact(self,x1,y1,x2,y2):ifself.x<=x1<=self.x+self.widthorself.x<=x2<=self.x+self.width:ifself.y<=y1<=self.y+self.heightorself.y<=y2<=self.y+self.height:returnTruereturnFalsedefstep(self):x=self.xy=self.yself.move()ifself.x!=xorself.y!=yorlen(shoot):fill_rect(x,y,20,30,backColor)self.draw()ifis_shooting:draw_shoot((0,)*3)defmove(self):globallevelifis_shooting:draw_shoot(backColor)ifself.chute:ifself.chute>0:ifself.tomber():self.y+=self.chuteself.chute+=1else:self.y=plateforms[self.get_plateform()][1]-self.heightifself.y>222:self.dead=Trueelse:self.y+=self.chuteself.chute+=1ifself.move_alone:self.x+=self.speedifself.tomber():self.speed*=-1self.x+=self.speedelse:x=(keydown(3)-keydown(0))ifx:self.speed=abs(self.speed)*xself.x+=self.speedifkeydown(KEY_UP)andnotself.tomber():self.y=plateforms[self.get_plateform()][1]-self.heightself.chute=-10if (notself.tomber()):ifself.contact(points[1][0],points[1][1],points[1][0]+20,points[0][1]+5):level+=1self.dead=Trueifself.tomber()andself.chute==0:self.chute=1deftomber(self):self.gx=self.x+int(self.width/2)self.gy=self.y+self.heightforiinplateforms:ifself.gy<=i[1]<=self.gy+self.chute:ifi[0]<=self.gx<=i[0]+i[2]:returnFalsereturnTruedefget_plateform(self):ifnotself.tomber():foriinplateforms:ifself.gy<=i[1]<=self.gy+self.chute:ifi[0]<=self.gx<=i[0]+i[2]:returnplateforms.index(i)defdraw(self):ifself.speed<=0:foriinself.drawing:fill_rect(self.x+i[0],self.y+i[1],i[2],i[3],i[4])else:foriinself.drawing_inverse:fill_rect(self.x+i[0],self.y+i[1],i[2],i[3],i[4])#Plateforme
defdraw_all_plateforms(color):foriinplateforms:fill_rect(i[0],i[1],i[2],i[3],color)#Entites
defdraw_all_entities():foriinentities:i.move()i.draw()#Shoot
is_shooting=Noneshooting_direction=1shoot=[]shooting_list=[]foriinrange(20):shooting_list+=[[int((15**2-(i-10)**2)**0.5),i-10],]defget_shoot(e,shooting):return[e.gx,e.y+8+10,shooting_list[shooting][0]*((e.speed>0)*2-1),shooting_list[shooting][1],0]defdraw_shoot(color):c=get_shoot(avatar,is_shooting)fill_rect(c[0]+c[2]*2-5,c[1]+c[3]*2-2,10,10,color)#Dead animation
defdeath_animation():foryinrange(11):forxinrange(16):fill_rect(x*20,y*20,20,24,death_color)sleep(0.003)#points
points=[]defdraw_all_points():fill_rect(points[0][0],points[0][1]-5,20,5,(255,150,100))fill_rect(points[1][0],points[1][1]-5,20,5,(100,100,255))#Spawn
maps=[#[spaw/end,monsters,plateforms(,txt)]
[[[10,200],[290,200]],[],[[10,200,300,10],],"utilisez les fleches\n pour vous deplacer"],[[[10,200],[10,100]],[],[[10,200,100,10],[140,200,100,10],[170,150,100,10],[10,100,100,10],],"utilisez la fleche\n du haut pour sauter"],[[[10,160],[280,80]],[[100,100,20,30,5]],[[10,160,50,10],[100,130,100,10],[200,80,100,10]],"appuyez sur OK pour tirer"],[[[0,120],[280,80]],[[130,100,20,30,5],[160,100,20,30,5],[190,100,20,30,5]],[[0,120,50,10],[100,130,140,10],[200,80,100,10]],"restez appuye pour viser"],[[[10,190],[270,90]],[[180,100,20,30,5]],[[10,190,130,10],[140,140,100,10],[240,90,50,10]]],[[[10,170],[270,170]],[[90,140,20,30,5]],[[10,170,100,10],[170,170,120,10]]],[[[20,40],[270,200]],[[270,100,20,30,5],[100,80,20,30,5],[180,130,20,30,5],[160,10,20,30,5],[50,50,20,30,5],[230,170,20,30,5]],[[220,200,70,10],[220,130,70,10],[160,160,60,10],[90,110,40,10],[140,40,60,10],[40,80,40,10],[20,40,50,10]]],[[[120,200],[290,50]],[[190,120,20,30,5],[110,120,20,30,5],[100,70,20,30,5],[200,70,20,30,5],[150,70,20,30,5],[80,20,20,30,5],[120,20,20,30,5],[180,20,20,30,5],[220,20,20,30,5]],[[100,150,120,10],[90,100,140,10],[70,50,180,10],[120,200,80,10],[280,50,30,10]]],[[[40,130],[240,130]],[[70,0,20,30,5],[90,10,20,30,5],[110,20,20,30,5],[130,30,20,30,5],[150,40,20,30,5],[170,50,20,30,5],[190,60,20,30,5],[210,70,20,30,5],[230,80,20,30,5]],[[40,130,220,10],]],[[[10,200],[280,40]],[[250,10,20,30,5],[190,150,20,30,5],[260,100,20,30,5],[120,70,20,30,5],[30,20,20,30,5],[140,-10,20,30,5]],[[240,40,60,10],[10,200,80,10],[180,180,50,10],[240,130,70,10],[100,100,70,10],[2990,210,20,10],[10,50,60,10],[110,20,90,10]]],[[[20,190],[280,70]],[[160,110,20,30,5],[70,70,20,30,5],[150,20,20,30,5],[110,160,20,30,5]],[[20,190,270,10],[140,140,70,10],[50,100,60,10],[130,50,60,10],[230,70,70,10]]],[[[80,190],[280,190]],[[220,160,20,30,5]],[[80,190,220,10]]],[[[10,30],[210,130]],[[380,100,20,30,5],[60,100,20,30,5],[200,100,20,30,5],[180,100,20,30,5],[160,100,20,30,5],[80,80,20,30,5],[140,90,20,30,5],[120,100,20,30,5],[100,100,20,30,5],[60,50,20,30,5],[40,60,20,30,5],[20,80,20,30,5]],[[-10,130,220,10],[200,130,20,10],[210,130,20,10],[10,30,20,10]]],[[[20,40],[270,210]],[[270,180,20,30,5]],[[0,120,320,10],[20,40,20,10],[-20,210,340,10]]],[[[40,130],[60,130]],[[120,100,20,30,5]],[[40,130,40,10]]],[[[40,60],[40,180]],[[120,150,20,30,5]],[[40,180,220,10]]],[[[10,200],[290,200]],[],[[10,200,300,10],],"Vous avez gagne !"]]defspawn(level):globalavatar,entities,plateforms,shoot,points,txt,runfill_rect(0,0,320,222,backColor)shoot=[]iflevel==len(maps):run=Falsereturnmap=maps[level]points=map[0]plateforms=map[2]avatar=Entity(points[0][0],points[0][1]-30,20,30,10,False)avatar.drawing=[(3,0,17,30,(255,0,0)),(0,3,12,10,(200,200,200)),]avatar.set_drawing_inverse()entities=[avatar,]foriinmap[1]:entities+=[Entity(i[0],i[1],i[2],i[3],i[4]),]entities[-1].drawing=[(3,0,17,30,(0,255,0)),(0,3,12,10,(200,200,200)),]entities[-1].set_drawing_inverse()iflen(map)==4:draw_string(map[3],20,20,(150,)*3,backColor)avatar.draw()spawn(level)time_start=monotonic()run=Truewhilerun:ifavatar.dead:death_animation()spawn(level)foriinrange(len(entities)-1,0,-1):forjinrange(len(shoot)-1,-1,-1):ifentities[i].contact(shoot[j][0]-5,shoot[j][1]-5,shoot[j][0]+5,shoot[j][1]+5):fill_rect(entities[i].x,entities[i].y,20,30,backColor)fill_rect(shoot[j][0]-5,shoot[j][1]-5,10,10,backColor)delentities[i]delshoot[j]breakifkeydown(KEY_OK)oris_shooting!=None:ifkeydown(KEY_OK):ifis_shooting==None:is_shooting=1draw_shoot(backColor)is_shooting+=shooting_directionifis_shooting==len(shooting_list)-1oris_shooting==0:shooting_direction*=-1elifis_shooting!=None:shoot+=[get_shoot(avatar,is_shooting),]shoot[-1][0]+=shoot[-1][2]shoot[-1][1]+=shoot[-1][3]draw_shoot(backColor)is_shooting=Noneforiinentities:i.step()ifnottrainee:foriinshoot:fill_rect(i[0]-5,i[1]-5,10,10,backColor)foriinrange(len(shoot)-1,-1,-1):shoot[i][0]+=shoot[i][2]shoot[i][1]+=shoot[i][3]shoot[i][3]+=1ifshoot[i][1]>222:delshoot[i]continuefill_rect(shoot[i][0]-5,shoot[i][1]-5,10,10,shoot_color)foriinentities[1:]:ifi.contact(avatar.x,avatar.y,avatar.x+avatar.width,avatar.y+avatar.height):avatar.dead=Truedraw_all_points()draw_all_plateforms(plateforms_color)sleep(0.05)print("Gagne !")print("Temps:")print(round(monotonic()-time_start,3)," s")#Everyone !
#You can change all features (go to top)
#You can also create levels with
#level_maker.py (the same creator) and put
#it at line 225
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.