All pastes #334336 Raw Edit

Miscellany

public python v1 · immutable
#334336 ·published 2007-01-31 14:52 UTC
rendered paste body
# -*- coding: utf-8 -*-import pygame #import de pygamefrom pygame import *#2eme import -> ca doit marcher sans ... bah dans le doute ...import sys, osimport threadingimport randomimport time #import de timepygame.init() #init de pygame        class Moteur:    """cette classe gère les fonctions vitales concernant l'affichage ..."""    def __init__(self):                self.sizex = 1024        self.sizey = 768 #640, 480 #taille de l'écran           self.screen = pygame.display.set_mode((self.sizex, self.sizey)) #création de la fenêtre graphique                pygame.display.set_caption('Civilis')#titre pour la fenêtre        pygame.key.set_repeat(100, 200)#on active le "set repeat"                return            def generation(self,casesx,casesy):        self.casesx = casesx        self.casesy = casesy        self.listcases = []        listbackground = ['herbe','desert','glace']        listelement = ['ville','rien','foret']        x=0        y=0        self.b = True        while x < casesx*50:            while y < casesy*50:                case = Cases(x,y,listbackground[random.randint(0,2)],listelement[random.randint(0,2)])                self.listcases.append(case)                y+=50                            if self.b == True:                y=25                self.b = False                            else:                y=0                self.b = True                            x+=40        return        def affichage(self):        global xmap        global ymap        black = 0, 0, 0        self.screen.fill(black)                for cas in self.listcases:            if cas.x >= xmap-50 and cas.x <= xmap+self.sizex and cas.y >= ymap-50 and cas.y <= ymap+self.sizey:                self.screen.blit(cas.imageload,(cas.x-xmap,cas.y-ymap))                               self.screen.blit(cas.elementload,(cas.x-xmap,cas.y-ymap))        self.affichemenu()                pygame.display.update()    def printtext(self,text,x,y):                """cette fonction sert à afficher du texte.        Il suffit l'invoquer avec comme argument le message à afficher"""        font = pygame.font.Font("font.ttf", 17 )        font.set_underline(1)        t = font.render(text, 1, (0,0,0))        tpos = t.get_rect()        tpos.center = (x,y)        self.screen.blit(t, tpos)        pygame.display.update()        return                        def affichemenu(self):                """affiche le menu"""        self.screen.blit(pygame.image.load(os.path.join("data","menu.png")).convert(),(self.sizex-140,0))        for cas in self.listcases:            if b.xmouse <= cas.x-xmap+50 and b.xmouse >= cas.x-xmap and b.ymouse <= cas.y-ymap+50 and b.ymouse >= cas.y-ymap:                self.printtext(cas.background,self.sizex-100,self.sizey-240)                self.printtext(cas.element,self.sizex-100,self.sizey-220)                                return        return        class Cases:    def __init__(self,x,y,background,element):        self.x = x        self.y = y        self.background = background        self.element = element        self.imageload = pygame.image.load(os.path.join("decors",self.background+".png")).convert_alpha()        self.elementload = pygame.image.load(os.path.join("elements",self.element+".png")).convert_alpha()        return    def changeback(self,newback):        self.background = newback        return    def changeelement(self,newelement):        self.element = newelement        return    class B:        def __init__(self):        self.xmouse = 0        self.ymouse = 0        return        def evenement(self):        """ici, on gere les entrées de l'utilisateur !"""                global xmap        global ymap        continu = True        while continu == True:            self.xmouse, self.ymouse = pygame.mouse.get_pos()            if self.xmouse <= 10:                xmap -=10            if self.xmouse >= a.sizex-10:                xmap += 10            if self.ymouse <= 10:                ymap -= 10            if self.ymouse >=a.sizey-10:                ymap += 10                            for event in pygame.event.get():                                if event.type == QUIT:                    print"fini"                    continu = False                    exit                    return                elif event.type == KEYDOWN:                    if event.key == K_UP:                                ymap -=10                    if event.key == K_DOWN:                        ymap +=10                    if event.key == K_LEFT:                        xmap -= 10                    if event.key == K_RIGHT:                        xmap += 10            if xmap < 0:                xmap = 0            if ymap < 0:                ymap = 0                        a.affichage()        xmap = 0ymap = 0a = Moteur()a.generation(20000,20000)a.affichage()b = B()t = threading.Thread(target=b.evenement)#,args=())t.start()