Un petit jeu où il faut attraper des diamants avant qu’un méchant ne nous rejoigne.
from math import * from kandinsky import * from ion import * from random import * def eff(): fill_rect(0,0,320,225,(93,235,109)) def des(pers,p): for i in range(0,19): for j in range(0,19): col=False if p[i][j]==1: c=(0,0,0) col=True if p[i][j]==2: c=(153,102,51) col=True if p[i][j]==3: c=(178,155,100) col=True if p[i][j]==4: c=(255,255,255) col=True if p[i][j]==5: c=(111,94,200) col=True if p[i][j]==6: c=(142,120,255) col=True if p[i][j]==7: c=(255,50,50) col=True if p[i][j]==8: c=(135,206,250) col=True if p[i][j]==9: c=(100,149,237) col=True if col: set_pixel(pers.x+j,pers.y+i,c) class Perso: def __init__(self,x,y,vit): self.x = x self.y = y self.vit = vit def mr(self): if self.x<300: self.x=self.x+self.vit def ml(self): if self.x>0: self.x=self.x-self.vit def md(self): if self.y<200: self.y=self.y+self.vit def mu(self): if self.y>0: self.y=self.y-self.vit def affiche(self): p=[ [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], [0,0,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,0,0], [0,0,1,1,2,1,1,1,1,3,3,1,1,1,1,2,1,1,0,0], [0,0,1,2,3,1,4,4,1,3,3,1,4,4,1,3,2,1,0,0], [0,0,1,3,3,1,1,1,1,3,3,1,1,1,1,3,3,1,0,0], [0,0,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,0,0], [0,0,1,3,3,3,3,3,3,2,2,3,3,3,3,3,3,1,0,0], [0,0,1,2,3,3,3,3,1,1,1,1,3,3,3,3,2,1,0,0], [0,0,0,1,2,3,3,3,3,3,3,3,3,3,3,2,1,0,0,0], [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], [0,0,0,0,0,0,0,1,3,3,3,3,1,0,0,0,0,0,0,0], [0,0,1,1,1,1,1,1,1,3,3,1,1,1,1,1,1,1,0,0], [1,1,1,5,5,5,1,1,1,1,1,1,1,1,5,5,5,1,1,1], [1,2,1,6,6,5,5,5,5,1,1,5,5,5,5,6,6,1,2,1], [1,3,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,3,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [0,0,0,0,1,5,5,5,1,0,0,1,5,5,5,1,0,0,0,0], [0,0,0,0,1,5,5,5,1,0,0,1,5,5,5,1,0,0,0,0], [0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0] ] des(self,p) class Mech: def __init__(self,x,y,vit): self.x = x self.y = y self.vit = vit def mr(self): if self.x<300: self.x=self.x+self.vit def ml(self): if self.x>0: self.x=self.x-sel def md(self): if self.y<200: self.y=self.y+self.vit def mu(self): if self.y>0: self.y=self.y-self.vit def affiche(self): p=[ [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], [0,0,1,1,1,2,2,4,4,4,4,4,4,2,2,1,1,1,0,0], [0,0,1,1,2,1,1,1,1,4,4,1,1,1,1,2,1,1,0,0], [0,0,1,2,4,1,4,4,1,4,4,1,4,4,1,4,2,1,0,0], [0,0,1,4,4,1,1,1,1,4,4,1,1,1,1,4,4,1,0,0], [0,0,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,0,0], [0,0,1,4,4,4,4,4,4,2,2,4,4,4,4,4,4,1,0,0], [0,0,1,2,4,4,4,4,1,1,1,1,4,4,4,4,2,1,0,0], [0,0,0,1,2,4,4,4,4,4,4,4,4,4,4,2,1,0,0,0], [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], [0,0,0,0,0,0,0,1,4,4,4,4,1,0,0,0,0,0,0,0], [0,0,1,1,1,1,1,1,1,4,4,1,1,1,1,1,1,1,0,0], [1,1,1,7,7,7,1,1,1,1,1,1,1,1,7,7,7,1,1,1], [1,2,1,1,1,7,7,7,7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0,0,1,1,1,1,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0] ] des(self,p) def ctc(p,q): c = False if p.x>q.x-20 and p.x<q.x+20: if p.y>q.y-20 and p.y<q.y+20: c = True return c eff() perso = Perso(100,100,8) mech = Mech(300,200,16) dia = Dia(50,200) score = 0 ga = False while True: eff() draw_string(str(score),2,2) perso.affiche() mech.affiche() dia.affiche() if ctc(perso,mech): ga = True draw_string("Game over",100,80) draw_string("Score : "+str(score),100,110) while ga: if keydown(KEY_OK): ga = False perso = Perso(100,100,8) mech = Mech(300,200,16) dia = Dia(50,200) score = 0 if ctc(perso,dia): score=score+1 dia.x=randint(0,300) dia.y=randint(0,200) mech.x=randint(0,300) mech.y=randint(0,200) mech.vit += 0.1 if keydown(KEY_LEFT): perso.ml() if keydown(KEY_UP): perso.mu() if keydown(KEY_DOWN): perso.md() if keydown(KEY_RIGHT): perso.mr() u = [perso.x-mech.x,perso.y-mech.y] nu = sqrt(u[0]**2+u[1]**2) mech.x = mech.x+int(0.5*u[0]/nu*mech.vit) mech.y = mech.y+int(0.5*u[1]/nu*mech.vit)