Skip to content

Commit

Permalink
Version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Roger committed Feb 4, 2016
1 parent 89d92f3 commit ecb3a14
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 99 deletions.
48 changes: 43 additions & 5 deletions HUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pygame
import grille_classe
import batiment_classe
import unite_classe

class UserInterface:
""" Classe pour l'interface utilisateur """
Expand Down Expand Up @@ -136,18 +138,54 @@ def draw(self):
for i in range(0,6):
x_pos = (i*50)+225+(i*50)
y_off = 5 if i == self.selected else 0
"""
if i == self.selected:
pygame.draw.rect(self.screen,(25,59,128),(x_pos,screenRect[3]-(50+y_off),50,50),1)
if (self.turn/15)%2==0:
pygame.draw.rect(self.screen,(25,59,128),pygame.Rect(x_pos,screenRect[3]-(50+y_off),taille-1,taille-1),2)
pygame.draw.rect(self.screen,(25,59,128),(x_pos,screenRect[3]-(y_off),60,5),0)
else:
pygame.draw.rect(self.screen,(25,59,128),pygame.Rect(i*taille,j*taille,taille,taille),1)
"""
pygame.draw.rect(self.screen,(45,106,229),(x_pos,screenRect[3]-(y_off),60,5),0)
self.screen.blit(self.images[self.mode][i],(x_pos,screenRect[3]-(50+y_off)))
h_val = self.selectT[self.mode][i]/2
pygame.draw.rect(self.screen,(45,106,229),(x_pos+55,screenRect[3]-y_off,5,-h_val),0)

# Infos sur la séléction
if self.mode=='towers':
name = batiment_classe.Batiment.stats[self.selected]['name']
prix = batiment_classe.Batiment.stats[self.selected]['prix']
attPhy = batiment_classe.Batiment.stats[self.selected]['attPhy']
attMag = batiment_classe.Batiment.stats[self.selected]['attMag']
attAbs = batiment_classe.Batiment.stats[self.selected]['attAbs']
nbCibles = batiment_classe.Batiment.stats[self.selected]['nbCibles']
distanceAtt = batiment_classe.Batiment.stats[self.selected]['distanceAtt']
details=''
if attPhy>0:
details += ( " / " if len(details)>0 else "" )
details += "Phy "+str(attPhy)
if attMag>0:
details += ( " / " if len(details)>0 else "" )
details += "Mag "+str(attMag)
if attAbs>0:
details += ( " / " if len(details)>0 else "" )
details += "Abs "+str(attAbs)
details+= " / Rad "+str(distanceAtt)
details+= " / Nb "+str(nbCibles)
else:
name = unite_classe.Unite.stats[self.selected]['name']
prix = unite_classe.Unite.stats[self.selected]['prix']
attPhy = unite_classe.Unite.stats[self.selected]['attPhy']
attMag = unite_classe.Unite.stats[self.selected]['attMag']
distanceAtt = unite_classe.Unite.stats[self.selected]['distanceAtt']
details=''
if attPhy>0:
details += ( " / " if len(details)>0 else "" )
details += "Phy "+str(attPhy)
if attMag>0:
details += ( " / " if len(details)>0 else "" )
details += "Mag "+str(attMag)
details+= " / Rad "+str(distanceAtt)
self.screen.blit(self.font.render(name,True,(25,25,25)),(875,855))
self.screen.blit(self.fontSmall.render("Cout : "+str(prix),True,(50,50,50)),(875,880))
self.screen.blit(self.fontSmall.render(details,True,(50,50,50)),(875,895))

def tick(self):
for i in range(6):
if (self.selectT['towers'][i]>0):
Expand Down
Binary file added Musique/build.ogg
Binary file not shown.
Binary file removed Musique/build.wav
Binary file not shown.
12 changes: 6 additions & 6 deletions batiment_classe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

class Batiment:
stats = [
{'attPhy': 5, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 1, 'prix': 5},
{'attPhy': 0, 'attMag': 7, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 1, 'prix': 10},
{'attPhy': 10, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 3, 'prix': 20},
{'attPhy': 0, 'attMag': 15, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 3, 'prix': 50},
{'attPhy': 3, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 2, 'nbCibles': 5, 'prix': 75},
{'attPhy': 0, 'attMag': 2, 'attAbs': 1, 'distanceAtt': 2, 'nbCibles': 5, 'prix': 100}
{'name': "Tour de garde", 'attPhy': 5, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 1, 'prix': 5},
{'name': "Tour de mages", 'attPhy': 0, 'attMag': 7, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 1, 'prix': 10},
{'name': "Garnison d archers", 'attPhy': 10, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 3, 'prix': 20},
{'name': "Monolithe d invocation", 'attPhy': 0, 'attMag': 15, 'attAbs': 0, 'distanceAtt': 1, 'nbCibles': 3, 'prix': 50},
{'name': "Cannon longue distance", 'attPhy': 3, 'attMag': 0, 'attAbs': 0, 'distanceAtt': 2, 'nbCibles': 5, 'prix': 75},
{'name': "Vigie avancee", 'attPhy': 0, 'attMag': 2, 'attAbs': 1, 'distanceAtt': 2, 'nbCibles': 5, 'prix': 100}
]

def __init__(self, id_tour, equipe, nom, grille, pos):
Expand Down
10 changes: 2 additions & 8 deletions credits_classe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

class Credits:
def __init__(self,screenP):
print('B-1')
self.screen = screenP
self.background_image = pygame.image.load("images/back.jpg")
self.reset()
print('B-2')

self.text_nom = pygame.font.Font("alagard.ttf",50, bold=True)
self.text_fonction = pygame.font.Font("alagard.ttf",70, bold=True)
self.text_ressource = pygame.font.Font("alagard.ttf",30, bold=True)
Expand All @@ -20,17 +19,14 @@ def __init__(self,screenP):
self.hugo = self.text_nom.render("Hugo VERONESE",True,(255,255,255))
self.son = self.text_fonction.render("Bruitages et Musiques",True,(255,255,255))

print('B-3')
self.son_1 = self.text_ressource.render("Theme en jeu : \"Evenstar\" de boopbeepbeepboop ",True,(255,255,255))
self.sprite_1 = self.text_ressource.render("Certains sprites de Heroes of Might and Magic 2",True,(255,255,255))
self.trailer_1 = self.text_ressource.render("Utilisation des images de la trilogie",True,(255,255,255))
self.image_1 = self.text_ressource.render("Image de fond : Wallhaven",True,(255,255,255))

print('B-4')
self.graphique = self.text_fonction.render("Graphique",True,(255,255,255))
self.code = self.text_fonction.render("Code",True,(255,255,255))
self.ressources = self.text_fonction.render("Ressources",True,(255,255,255))
print('B-5')

def draw(self):
#Position de centre
Expand Down Expand Up @@ -67,7 +63,7 @@ def draw(self):
image_1pos.centerx = self.screen.get_rect().centerx

#Position de hauteur
self.fini = (self.pos<-2000)
self.fini = (self.pos<-1700)

self.pos-=1
sonpos[1]+=self.pos
Expand Down Expand Up @@ -108,7 +104,5 @@ def draw(self):
return self.fini

def reset(self):
print('B-1.5')
self.pos = 500
self.fini = False
print('B-1.6')
12 changes: 3 additions & 9 deletions fin_jeu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ def __init__(self,screen):
self.vict = False

def start(self,victoire):
print('................')
self.vict = victoire
if victoire:
print('victoire')
self.music_victoire = pygame.mixer.music.load('Musique/theme_principal.mp3')
pygame.mixer.music.load('Musique/theme_principal.mp3')
else:
print('defaite')
self.music_defaite = pygame.mixer.music.load('Musique/defaite.mp3')
print('!!!!!!!!!!!')
pygame.mixer.music.load('Musique/defaite.mp3')
pygame.mixer.music.play()
pygame.mixer.music.set_volume(1.0)
print('................')


def stop(self):
pygame.mixer.music.stop()
pygame.mixer.music.set_volume(1.0)

def draw(self):
# Fond de l'interface du haut
Expand Down
83 changes: 40 additions & 43 deletions game_classe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@
class Game:
def __init__(self):
self.paused=False
self.show_gameOver=False

# Set the width and height of the screen [width, height]
self.screen_width = 1410
self.screen_height = 910
os.environ['SDL_VIDEO_CENTERED'] = '1'

def launch(self):
def launch(self,diff):
print('Launching game ...')

pygame.init()
self.screen = pygame.display.set_mode([self.screen_width, self.screen_height])
pygame.display.set_caption("Road to Mordor")
self.clock = pygame.time.Clock()

self.joueur = joueur_classe.Joueur("Player 1","humain",1)
self.joueurIA = joueur_classe.Joueur("Computer","orc",0)
self.hud = HUD.UserInterface(self.screen,self.joueur,self.joueurIA)
self.grille = grille_classe.Grille(16,20,3,self.screen.subsurface((205,50,1000,800)),self.hud,self.joueurIA,self.joueur)
self.grille = grille_classe.Grille(16,20,diff,self.screen.subsurface((205,50,1000,800)),self.hud,self.joueurIA,self.joueur)
self.IA = IA.IA(self.grille,self.joueurIA)
self.ig_menu = ig_menu_classe.InGameMenu(self.screen)
self.rules = regles_classe.Regles(self.screen)
self.game_over = fin_jeu.Fin(self.screen)

pygame.mixer.music.load('Musique/Musiquedefond.mp3')
pygame.mixer.music.play()
pygame.mixer.music.play(-1)

turn=0
done = False
show_regles = False
show_gameOver=False
# -------- Main Program Loop -----------
keys_pressed = dict()
pygame.event.Event(pygame.USEREVENT,{'key':0,'unicode':''})
Expand All @@ -56,39 +55,37 @@ def launch(self):
print('Ending game ... and QUIT !')
return False
elif event.type == pygame.KEYDOWN:
# Create KEYPRESS events
keys_pressed[event.key] = {'key': event.key, 'unicode': event.unicode}
#keys_pressed[event.key] = {'key': event.key, 'unicode': event.unicode} # Create KEYPRESS events
if len(keys_pressed)>0:
pygame.time.set_timer(pygame.USEREVENT,150)
if self.paused:
if event.key == pygame.K_RETURN:
res_m = self.ig_menu.getSelected()
if res_m == 0:
pygame.mixer.music.unpause()
self.paused=False
elif res_m == 1:
show_regles=True
elif res_m == 2:
self.paused=False
print('Ending game ...')
return True
elif event.key == pygame.K_ESCAPE:
if show_regles:
show_regles=False
else:
if show_regles:
show_regles=False
else:
if event.key == pygame.K_RETURN:
res_m = self.ig_menu.getSelected()
if res_m == 0:
pygame.mixer.music.unpause()
self.paused=False
elif res_m == 1:
show_regles=True
elif res_m == 2:
self.paused=False
print('Ending game ...')
return True
elif event.key == pygame.K_ESCAPE:
self.paused=False
pygame.mixer.music.unpause()
else:
self.ig_menu.switchSelected()
elif self.show_gameOver:
if event.key == pygame.K_ESCAPE:
print('Ending game ...')
self.rules.stop()
self.game_over.stop()
return True
elif event.key == pygame.K_LEFT:
self.ig_menu.selectPrev()
else:
self.ig_menu.switchSelected()
elif show_gameOver:
print('Ending game ...')
self.game_over.stop()
return True
else:
# Handle KEYDOWN
#print('keydown',event.unicode)
if event.unicode == 'd':
self.hud.selectNext()
elif event.unicode == 'q': # Q sur un Azerty
Expand All @@ -97,11 +94,11 @@ def launch(self):
self.hud.switchMode()
elif event.unicode == '-':
print('- HEY !')
elif event.unicode == '.':
self.joueurIA.setVieChateau(0)
elif event.key == pygame.K_ESCAPE:
self.paused = True
pygame.mixer.music.pause()
# Effet temporaire, a terme cela ouvre
# le menu ingame qui permet ensuite de quitter
elif event.key == pygame.K_UP:
self.grille.selectUp()
elif event.key == pygame.K_DOWN:
Expand Down Expand Up @@ -139,11 +136,11 @@ def launch(self):
else:
self.hud.showMessage("Cooldown en cours.",70)
print('Cooldown en cours')
"""
elif event.type == pygame.KEYUP:
# Create KEYPRESS events
keys_pressed.pop(event.key)
keys_pressed.pop(event.key) # Create KEYPRESS events
if len(keys_pressed)<=0:
pygame.time.set_timer(pygame.USEREVENT,0)
pygame.time.set_timer(pygame.USEREVENT,0) # Remove timer
elif event.type == pygame.USEREVENT:
for key,item in keys_pressed.iteritems():
if key == pygame.K_UP:
Expand All @@ -154,6 +151,7 @@ def launch(self):
self.grille.selectLeft()
elif key == pygame.K_RIGHT:
self.grille.selectRight()
"""
# --- Game logic should go here
#pygame.display.update()
self.screen.fill((75,75,75))
Expand All @@ -162,7 +160,7 @@ def launch(self):
self.rules.draw()
else:
self.ig_menu.draw()
elif self.show_gameOver:
elif show_gameOver:
self.game_over.draw()
else:
self.grille.draw()
Expand All @@ -175,14 +173,14 @@ def launch(self):
if turn%10==0:
self.grille.play()
# --- Check if the game is over
if self.joueur.getVieChateau()==0 and not self.show_gameOver:
if self.joueur.getVieChateau()==0 and not show_gameOver:
show_gameOver = True
pygame.mixer.music.stop()
self.game_over.start(False)
self.show_gameOver = True
elif self.joueurIA.getVieChateau()==0 and not show_gameOver:
show_gameOver = True
pygame.mixer.music.stop()
elif self.joueurIA.getVieChateau()==0 and not self.show_gameOver:
self.game_over.start(True)
self.show_gameOver = True
pygame.mixer.music.stop()

# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
Expand All @@ -191,7 +189,6 @@ def launch(self):
self.clock.tick(60)

# Close the window and quit.
pygame.quit()

print('Ending game ...')

Expand Down
2 changes: 2 additions & 0 deletions grille_classe.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self,rows,cols,count,screen,hud,joueur1,joueur2):
self.screen = screen
self.generer_nb_grille(count)
self.turn=0
self.buildSound = pygame.mixer.Sound('Musique/build.ogg')
self.images = {}
self.images['test'] = pygame.image.load("images/test.png")
self.images['sprites'] = pygame.image.load("images/sprites.png")
Expand Down Expand Up @@ -279,6 +280,7 @@ def place(self,item):
self.grille[item.getPos()['x']][item.getPos()['y']]['front'] = CONST_FRONT_BAT
self.grille[item.getPos()['x']][item.getPos()['y']]['item'] = item
self.batiments.append(item)
self.buildSound.play()
return True
else:
return False
Expand Down
11 changes: 8 additions & 3 deletions ig_menu_classe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def draw(self):
#Creation des texte
j = self.font.render("Reprendre",True,(255,255,255))
r = self.font.render("Regles",True,(255,255,255))
q = self.font.render("Quitter",True,(255,255,255))
q = self.font.render("Abandonner",True,(255,255,255))

#Position de hauteur
j_y_off=0
Expand All @@ -33,9 +33,9 @@ def draw(self):
text = self.font.render("Road to Mordor",True,(75,75,75))
self.screen.blit(text, [(self.screen.get_rect().width/2)-(text.get_rect().width/2), 0])

self.screen.blit(j,(self.screen.get_rect().centerx-(j.get_rect().centerx)-250,500-j_y_off))
self.screen.blit(j,(self.screen.get_rect().centerx-(j.get_rect().centerx)-300,500-j_y_off))
self.screen.blit(r,(self.screen.get_rect().centerx-(r.get_rect().centerx),500-r_y_off))
self.screen.blit(q,(self.screen.get_rect().centerx-(q.get_rect().centerx)+250,500-q_y_off))
self.screen.blit(q,(self.screen.get_rect().centerx-(q.get_rect().centerx)+300,500-q_y_off))

def getSelected(self):
return self.selected
Expand All @@ -44,3 +44,8 @@ def switchSelected(self):
self.selected+=1
if self.selected>=3:
self.selected=0

def selectPrev(self):
self.selected-=1
if self.selected<0:
self.selected=2
Binary file removed images/guignol.png
Binary file not shown.
Binary file added images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ecb3a14

Please sign in to comment.