from random import * from kandinsky import * from ion import * from time import * cx=-2 vie=100 armure=80 ex=(0,0) direction=(0,0) break_mode=( (4,3,0,3,4), (0,0,2,0,0), (3,0,1,0,3), (4,0,2,2,0), (0,3,0,0,4), ) map=[ [0,5,5,5,0,0,0,1,3 ,3 ,3 ,10,3,1 ,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,0,0,0,0,0,1 ,2,3 ,11,3 ,2,1 ,0,0,0,0,0,0,0,0 ,0 ,0 ,0,0,0,0,5,5,5,5,0,0,0,0,1,0,0,0,0,0,15,16,16,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,15], [0,5,4,5,0,0,1,2,3 ,11,3 ,3 ,3,10,1,1,0,1,1,1,0,0,0,0,0,0,5,5,4,5,5,0,0,0,1,2 ,3,3 ,9 ,3 ,3,2 ,1,0,0,0,0,0,1,13,13,13,1,0,0,5,5,4,4,5,5,0,0,1,2,1,0,0,0,0,15,16,0 ,14,0 ,16,16,0 ,0 ,0 ,0 ,0 ,16,16,16,16,16,16,15], [1,0,4,0,0,1,2,3,10,9 ,3 ,11,3,3 ,3,2,1,2,2,2,1,0,0,0,1,0,0,0,4,0,0,0,1,1,2,10,3,12,3 ,10,3,3 ,2,1,0,0,0,1,2,2 ,13,13,2,1,0,0,0,4,4,0,0,0,1,2,3,2,1,0,0,0,15,16,0 ,14,0 ,0 ,0 ,0 ,16,16,16,16,16,16,16,16,16,16,15], [2,1,2,1,1,3,3,3,3 ,3 ,12,3 ,3,11,3,3,2,3,3,2,2,1,1,1,2,1,1,1,1,1,1,1,2,2,3,11,3,11,3 ,3 ,3,10,3,2,1,1,1,2,2,14,15,13,3,2,1,1,1,1,1,1,1,1,2,3,3,3,2,1,1,1,15,16,16,16,16,16,16,16,16,14,14,14,16,16,16,16,16,16,15] ] max_map=len(map[1]) blocks=( ("air",10000,0,1,1,((0,0,50,50,(130,230,255)),)), ("gazon",10,4,0,0,((0,10,50,40,(190,90,0)),(0,0,50,10,(0,220,0)))), ("terre",10,4,0,0,((0,0,50,50,(190,90,0)),)), ("pierre",40,2,0,0,((0,0,50,50,(180,180,180)),)), ("buche",20,3,0,0,(((0,0,50,50,(200,100,10)),(20,0,10,50,(210,110,20))))), ("feuille",2,3,0,0.75,((0,0,50,50,(100,120,0)),)), (),#("table",15,3,0,0,()), ("planche",15,3,0,0,((0,0,50,50,(230,130,40)),(0,20,50,10,(210,110,20)),)), (),#("four",30,2,0,0,()), ("torche",10,3,1,1,((0,0,50,50,(130,230,255)),(20,20,10,30,(200,100,10)),(20,20,10,10,(255,255,0)))), ("minerai_charbon",50,2,0,0,((0,0,50,50,(180,180,180)),(10,30,10,10,(20,20,20)),(30,10,10,10,(20,20,20)))), ("minerai_fer",50,2,0,0,((0,0,50,50,(180,180,180)),(10,30,10,10,(250,100,100)),(30,10,10,10,(250,100,100)))), ("diamant",40,2,0,0,((0,0,50,50,(180,180,180)),(10,30,10,10,(0,255,255)),(30,10,10,10,(0,255,255)))), ("eau",10000,5,0.75,0.5,((0,0,50,50,(0,0,180)),)), ("lave",10000,5,0.25,1,((0,0,50,50,(255,100,0)),)), ("obsidienne",200,2,0,0,((0,0,50,50,(0,0,20)),)), ("pierre_trefond",40,2,0,0,((0,0,50,50,(250,20,0)),)), #("spawner",200,2,0,0,()), #("pierre_ender",80,2,0,0,((0,0,50,50,(235,235,235)),)), #("toile",20,1,0.2,0.9,((0,0,50,50,(130,230,255)),(0,10,40,10,(230,230,230)),(30,0,10,40,(230,230,230)),(10,30,40,10,(230,230,230)),(10,10,10,40,(230,230,230)))) ) inv=[ [0,1,2,3,4,13], [31,41,51,32,42,52], [9,7,61,62,63,64] ] select=0 selectY=0 def casser(outil=0): if not -1<p.y+direction[1]<4: return block=blocks[map[p.y+direction[1]][(p.x+direction[0])%max_map]] outil_destine=block[2] temps=0.2*block[1]/10 if outil!=0: if outil_destine==outil%10: temps/=2 else: temps*=2 temps/=(int(outil/10)-3)+1 if block[1]==10000: return for h in range(1,5): for i in range(0,5): for j in range(0,5): if h==break_mode[i][j]: fill_rect(50*(p.x-cx+direction[0])+10*i,50*(p.y+direction[1])+10*j,10,10,(0,0,0)) sleep(temps) map[p.y+direction[1]][(p.x+direction[0])%max_map]=0 class Perso(): def __init__(self): self.x=0 self.y=0 def move(self,x,y): global direction,cx direction=(x,y) if keydown(KEY_ONOFF) or (self.y+y in (-1,4)): return if blocks[map[(self.y+y)%4][(self.x+x)%max_map]][3]>0: self.x+=x self.y+=y if cx+4<self.x or self.x<cx+1: cx+=x def draw(self): rx=(self.x-cx)*50 ry=self.y*50 fill_rect(rx+15,ry+10,20,40,(255,0,255)) fill_rect(rx+15,ry,20,20,(250,160,130)) fill_rect(rx+18,ry+5,5,5,(255,255,255)) fill_rect(rx+27,ry+5,5,5,(255,255,255)) fill_rect(rx+19+(direction[0]),ry+6+(direction[1]),3,3,(0,0,255)) fill_rect(rx+28+(direction[0]),ry+6+(direction[1]),3,3,(0,0,255)) if 0<inv[0][select%6]<20: block=blocks[inv[0][select]] for k in block[5]: fill_rect(int(30+rx+(k[0]*1/5)),int(30+ry+(k[1]*1/5)),int(k[2]*1/5),int(k[3]*1/5),k[4]) if 30<inv[0][select%6]<70: draw_outil(30+rx,30+ry,1/5,inv[0][select%6]-30) p=Perso() def draw(): if open_inv: draw_inv() bouger_inv() return else: for i in range(0,4): for j in range(0,7): block=blocks[map[i][(j+(cx))%max_map]] for k in block[5]: fill_rect(k[0]+(j*50),k[1]+(i*50),k[2],k[3],k[4]) p.draw() if armure!=ex[0] or vie!=ex[1]: draw_life() def draw_life(): global ex ex=(armure,vie) fill_rect(0,200,320,22,(255,255,255)) fill_rect(0,200,int(armure/100*320),22,(120,120,150)) fill_rect(3,203,int(vie/100*314),16,(255,0,0)) drawed_inv=0 def draw_inv(): global drawed_inv if drawed_inv: return fill_rect(20,20,280,160,(125,225,250)) for i in range(0,6): for j in range(0,3): if i==select and j==selectY: fill_rect(27+i*45-5,10*(j!=0)+30+j*45-5,50,50,(220,200,200)) if 0<=inv[j][i]<20: block=blocks[inv[j][i]] for k in block[5]: fill_rect(int(27+i*45+(k[0]*4/5)),int(10*(j!=0)+30+j*45+(k[1]*4/5)),int(k[2]*4/5),int(k[3]*4/5),k[4]) elif 30<inv[j][i]<70: draw_outil(27+i*45,10*(j!=0)+30+j*45,4/5,inv[j][i]-30) else: fill_rect(27+i*45,10*(j!=0)+30+j*45,40,40,(0,0,0)) drawed_inv=1 open_inv=0 def draw_outil(x,y,scale,id): couleur=((200,100,10),(180,180,180),(235,235,235),(0,255,255))[int(id/10)] if id%10==1: fill_rect(x+int(15*scale),y+int(5*scale),int(20*scale),int(30*scale),couleur) fill_rect(x+int(20*scale),y+int(35*scale),int(10*scale),int(15*scale),(220,120,30)) if id%10==2: fill_rect(x+int(5*scale),y+int(5*scale),int(40*scale),int(10*scale),couleur) fill_rect(x+int(20*scale),y+int(15*scale),int(10*scale),int(30*scale),(220,120,30)) if id%10==3: fill_rect(x+int(20*scale),y,int(25*scale),int(10*scale),couleur) fill_rect(x+int(30*scale),y+int(10*scale),int(15*scale),int(10*scale),couleur) fill_rect(x+int(20*scale),y+int(10*scale),int(10*scale),int(35*scale),(220,120,30)) if id%10==4: fill_rect(x+int(15*scale),y+int(5*scale),int(20*scale),int(20*scale),couleur) fill_rect(x+int(20*scale),y+int(25*scale),int(10*scale),int(25*scale),(220,120,30)) def bouger_inv(): global select,selectY,drawed_inv if not open_inv: return for i in range(18): if keydown(i+12): if keydown(KEY_OK): inv[int(i/6)][i%6],inv[selectY][select]=inv[selectY][select],inv[int(i/6)][i%6] else: selectY=int(i/6) select=i%6 for i in range(4): if keydown(i): select=(select+(-1,0,0,1)[i])%6 selectY=(selectY+(0,-1,1,0)[i])%3 drawed_inv=0 draw_inv() while True: draw() sleep(0.2) if keydown(KEY_HOME): drawed_inv=0 open_inv=1-open_inv if open_inv: continue if p.y<3: if blocks[map[(p.y+1)%4][p.x%max_map]][3]==1 and p.y<3: p.y+=1 if map[p.y][p.x%max_map]==14: vie-=10-(5*(vie<=armure)) for i in range(6): if keydown(12+i): select=i if keydown(KEY_OK): if 0<inv[0][select%6]<20: if map[(p.y+direction[1])%4][(p.x+direction[0])%max_map] in (0,13,14): map[(p.y+direction[1])%4][(p.x+direction[0])%max_map]=inv[0][select] else: casser(inv[0][select%6]) if keydown(KEY_UP) and (map[(p.y+1)%4][p.x%max_map]!=0 or p.y==3): p.move(0,-1) if keydown(KEY_DOWN): p.move(0,1) if keydown(KEY_LEFT): p.move(-1,0) if keydown(KEY_RIGHT): p.move(1,0) #COMMENT JOUER: #1) On se deplace avec les fleches. #2) On peut changer la direction du # regard en appuyant sur le bouton off # et la fleche voulue. #3) On peut ouvrir et fermer l'inventaire # avec la touche "home" #4)On selectionne quelque chose dans l'inventaire avec la touche correspondante parmi les trois premieres lignes du clavier. #5)Pour changer le place d'un outil on selectionne cet outil, on appuie sur "'OK" et en même temps on appuie sur la touche correspondante à la case où vous voulez qu'il arrive. #6)# Type your text here