rendered paste body# -*- coding: utf-8 -*-
import pygame
import sys, os
import threading
import random
import time #import de time
pygame.init() #init de pygame
class Moteur:
"""cette classe gère les fonctions vitales concernant l'affichage ..."""
def __init__(self):
self.sizex = 800
self.sizey = 700 #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('Combat')#titre pour la fenêtre
pygame.key.set_repeat(100, 200)#on active le "set repeat"
return
def affichage(self):
black = 0, 0, 0
self.screen.fill(black)
self.screen.blit(champ.background,(0,0))
for cas in champ.listcases :
self.screen.blit(cas.imageload,(cas.x,cas.y))
for i in hero.creature:
self.screen.blit(i.image,(i.x,i.y-60))
pygame.display.update()
class Cases:
def __init__(self,ident,x,y,terrain,element,passe,creature):
self.ident = ident
self.x = x
self.y = y
self.terrain = terrain
self.element = element
self.imageload = pygame.image.load(os.path.join("decors",self.terrain+".png")).convert_alpha()
self.creature = None
self.img = 0
#self.elementload = pygame.image.load(os.path.join("elements",self.element+".png")).convert_alpha()
return
class Creature:
def __init__(self,caseid,typec,nombre,capacite,immunite,hero,caracteristiques):
for i in champ.listcases:
if i.ident == caseid:
self.x = i.x
self.y = i.y
i.creature = self
self.nbimg = 0
self.joue = False
self.caseid = caseid
self.typec = typec
self.images = {}
self.actimg = ['marche','reste','combat']
for i in self.actimg:
self.images[i] = {}
abc=0
for k in xrange(0,4):
try:
self.images[i][k] = pygame.image.load(os.path.join('images','creature',self.typec,str(i)+'-'+str(abc)+'.png'))
except:
print"Le fichier est introuvable : à l'interieur de ", self.typec," : ",str(i)+'-'+str(abc)+'.png'
abc+=1
self.actimg = 'reste'
self.image = self.images['reste'][0]
self.capacite = capacite
#self.immunite = immunite
self.hero = hero
self.mouvement = 2
#self.caracteristiques = caracteristiques
def change_image(self,change=None):
if change != None:
self.nbimg = 0
self.actimg = change
else:
self.nbimg+=1
if self.nbimg>4:
self.nbimg = 0
return
def tour(self):
self.image = self.images['reste'][1]
self.deppos= []
self.deppos2=[]
self.xx= self.x
self.yy= self.y#verification des cases disponibles
print self.yy
for i in xrange(1,self.mouvement+1):
for j in champ.listcases:
if self.xx+(50*i) == j.x and self.yy == j.y:#marche
self.deppos.append(j.ident)
if self.xx-(50*i) == j.x and self.yy == j.y: #marche
self.deppos.append(j.ident)
if self.xx+(25*i) == j.x and self.yy+(36*i) >= j.y:#marche ?
self.deppos.append(j.ident)
if self.xx-(25*i) == j.x and self.yy-(37*i) == j.y:
self.deppos.append(j.ident)
if self.xx+(25*i) == j.x and self.yy-(37*i) == j.y:
self.deppos.append(j.ident)
if self.xx-(25*i) == j.x and self.yy+(37*i) == j.y:
self.deppos.append(j.ident)
if self.xx-(25*i) == j.x and self.yy+(73) == j.y:
self.deppos.append(j.ident)
if self.xx == j.x and self.yy+(73*(i/3)) == j.y : #marche
self.deppos.append(j.ident)
if self.xx == j.x and self.yy-(73*(i/3)) == j.y : #marche
self.deppos.append(j.ident)
if self.xx+((50*i)-25) == j.x and self.yy+36 == j.y:#marche
self.deppos.append(j.ident)
if self.xx-((50*i)-25) == j.x and self.yy+36 == j.y:#marche
self.deppos.append(j.ident)
if self.xx+((50*i)-25) == j.x and self.yy-37 == j.y:#marche
self.deppos.append(j.ident)
if self.xx-((50*i)-25) == j.x and self.yy-37 == j.y:#marche
self.deppos.append(j.ident)
#verification des cases non prises
for i in self.deppos:
for j in champ.listcases:
if i == j.ident and j.creature == None:
self.deppos2.append(i)
j.imageload = pygame.image.load(os.path.join("decors",j.terrain+"-1.png")).convert_alpha()
j.img = 1
a.affichage()
continu2 = True
self.dep = 0
while continu2 == True:
if pygame.mouse.get_pressed() == (1,0,0):
self.xmouse, self.ymouse = pygame.mouse.get_pos()
for i in champ.listcases:
if self.xmouse > i.x and self.xmouse <i.x+50 and self.ymouse > i.y and self.ymouse < i.y+50 and i.ident in self.deppos2 and self.dep == 0:
self.caseid = i.ident
self.nvcase = {}
self.nvcase['x'],self.nvcase['y'] = i.x,i.y
continu2 = False
self.joue = True
self.deplacement()
for event in pygame.event.get():
if event.type == pygame.QUIT:
print"fini"
continu = False
pygame.quit()
sys.exit()
return
return
def deplacement(self):
self.nbimg = 0
self.actimg = "marche"
self.image = self.images['marche'][0]
if self.x < self.nvcase['x']:
while self.x < self.nvcase['x']:
self.x+=10
self.nbimg+=1
self.image = self.images['marche'][int(self.nbimg)]
pygame.time.wait(100)
if self.nbimg == 3:
self.nbimg=0
a.affichage()
self.nbimg = 0
if self.x > self.nvcase['x']:
while self.x > self.nvcase['x']:
self.x-=10
self.nbimg+=1
self.image = self.images['marche'][int(self.nbimg)]
pygame.time.wait(100)
if self.nbimg == 3:
self.nbimg=0
a.affichage()
self.nbimg = 0
if self.y+10 < self.nvcase['y']:
while self.y+10 < self.nvcase['y']:
self.y+=10
self.nbimg+=1
self.image = self.images['marche'][int(self.nbimg)]
pygame.time.wait(100)
if self.nbimg == 3:
self.nbimg=0
a.affichage()
self.nbimg = 0
if self.y+10 > self.nvcase['y']:
while self.y+10 > self.nvcase['y']:
self.y-=10
self.nbimg+=1
self.image = self.images['marche'][int(self.nbimg)]
pygame.time.wait(100)
if self.nbimg == 3:
self.nbimg=0
a.affichage()
self.nbimg = 0
self.image = self.images['reste'][0]
for i in champ.listcases:
if i.img == 1:
i.imageload = pygame.image.load(os.path.join("decors",i.terrain+".png")).convert_alpha()
i.img = 0
return
class Heros:
def __init__(self,cote,image_,mods):
self.cote = cote
self.image = pygame.image.load(os.path.join('images','heros',image_+'.png')).convert_alpha()
self.mods = mods
self.creature = []
self.creat = Creature(1,'ab',3,{},{},self,{})
self.creature.append(self.creat)
self.creat = Creature(34,'ab',3,{},{},self,{})
self.creature.append(self.creat)
class Champs:
def __init__(self,background):
self.listcases = []
self.generation(14,8)
self.background = pygame.image.load(os.path.join('images','background',background+'.png'))
def generation(self,casesx,casesy):
self.casesx = casesx
self.casesy = casesy
self.listcases = []
listbackground = ['herbe','desert','glace']
#listelement = ['ville','rien','foret']
z=0
x=0
y=100
self.b = True
while x < casesx*50:
while y <= (casesy+1)*73:
z+=1
case = Cases(z,x,y,'herbe','',True,None)
self.max = z
self.listcases.append(case)
y+=73
if self.b == True:
y=136
self.b = False
else:
y=100
self.b = True
x+=25
return
class Gest:
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()
for event in pygame.event.get():
if event.type == pygame.QUIT:
print"fini"
continu = False
pygame.quit()
sys.exit()
return
self.tour()
a.affichage()
def tour(self):
for i in hero.creature:
if i.joue == False:
i.tour()
rect_list = []
a=Moteur()
champ = Champs('background')
hero = Heros("gauche","hero",{})
g = Gest()
g.evenement()