|
|
@ -37,6 +37,7 @@ class Joueur : |
|
|
|
self.maitre = maitre |
|
|
|
self.maitre = maitre |
|
|
|
self.poules = poules |
|
|
|
self.poules = poules |
|
|
|
self.nb_poules = len(poules) |
|
|
|
self.nb_poules = len(poules) |
|
|
|
|
|
|
|
self.poules_restantes = self.nb_poules |
|
|
|
|
|
|
|
|
|
|
|
def se_deplacer(self) : |
|
|
|
def se_deplacer(self) : |
|
|
|
if not self.chien.puni : |
|
|
|
if not self.chien.puni : |
|
|
@ -48,19 +49,25 @@ class Joueur : |
|
|
|
self.chien.dep_y(1) |
|
|
|
self.chien.dep_y(1) |
|
|
|
if pyxel.btn(pyxel.KEY_UP): |
|
|
|
if pyxel.btn(pyxel.KEY_UP): |
|
|
|
self.chien.dep_y(-1) |
|
|
|
self.chien.dep_y(-1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def punition(self) -> bool : |
|
|
|
def punition(self) -> bool : |
|
|
|
if self.maitre.x >= self.chien.x and self.maitre.y >= self.chien.y and self.maitre.x <= self.chien.x + 8 and self.maitre.y <= self.chien.y + 8 : |
|
|
|
if self.maitre.x >= self.chien.x and self.maitre.y >= self.chien.y and self.maitre.x <= self.chien.x + 8 and self.maitre.y <= self.chien.y + 8 : |
|
|
|
self.chien.puni = True |
|
|
|
self.chien.puni = True |
|
|
|
|
|
|
|
|
|
|
|
def collecter(self) : |
|
|
|
def collecter(self) : |
|
|
|
if self.nb_poules : |
|
|
|
if self.nb_poules >= 1 : |
|
|
|
print(self.nb_poules) |
|
|
|
print(self.nb_poules) |
|
|
|
for i in range(self.nb_poules) : |
|
|
|
for i in range(self.nb_poules) : |
|
|
|
if self.poules[i].collecte == False and self.poules[i].x >= self.chien.x and self.poules[i].y >= self.chien.y and self.poules[i].x <= self.chien.x + 8 and self.poules[i].y <= self.chien.y + 8 : |
|
|
|
if self.poules[i].collecte == False and self.poules[i].x >= self.chien.x and self.poules[i].y >= self.chien.y and self.poules[i].x <= self.chien.x + 8 and self.poules[i].y <= self.chien.y + 8 : |
|
|
|
print("collision") |
|
|
|
print("collision") |
|
|
|
self.poules[i].collecte = True |
|
|
|
self.poules[i].collecte = True |
|
|
|
|
|
|
|
self.poules_restantes -= 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def croc(self) : |
|
|
|
|
|
|
|
if pyxel.btn(pyxel.KEY_SPACE) : |
|
|
|
|
|
|
|
self.ajouter_croc() |
|
|
|
|
|
|
|
|
|
|
|
class Maitre : |
|
|
|
class Maitre : |
|
|
|
def __init__(self,chien:'Chien') : |
|
|
|
def __init__(self,chien:'Chien') : |
|
|
@ -99,15 +106,32 @@ class Poule : |
|
|
|
if self.collecte : |
|
|
|
if self.collecte : |
|
|
|
self.x = None |
|
|
|
self.x = None |
|
|
|
self.y = None |
|
|
|
self.y = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def deplacement(self) : |
|
|
|
|
|
|
|
rand_dist_x = rd.randint(0,4) |
|
|
|
|
|
|
|
rand_dist_x = rd.choice((-1,0,1))*rand_dist_x |
|
|
|
|
|
|
|
rand_dist_y = rd.randint(0,4) |
|
|
|
|
|
|
|
rand_dist_y = rd.choice((-1,0,1))*rand_dist_y |
|
|
|
|
|
|
|
self.x += rand_dist_x |
|
|
|
|
|
|
|
self.y += rand_dist_y |
|
|
|
|
|
|
|
if self.x > XMAX : |
|
|
|
|
|
|
|
self.x = XMAX |
|
|
|
|
|
|
|
elif self.x < 0 : |
|
|
|
|
|
|
|
self.x = 0 |
|
|
|
|
|
|
|
if self.y > YMAX : |
|
|
|
|
|
|
|
self.y = YMAX |
|
|
|
|
|
|
|
elif self.y < 0 : |
|
|
|
|
|
|
|
self.y = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def afficher(self) : |
|
|
|
def afficher(self) : |
|
|
|
pyxel.blt(self.x,self.y,0,0,8,8,8) |
|
|
|
pyxel.blt(self.x,self.y,0,0,8,8,8) |
|
|
|
|
|
|
|
|
|
|
|
class Map: |
|
|
|
class Map: |
|
|
|
def __init__(self,maitre:"Maitre",chien:"Chien") : |
|
|
|
def __init__(self,maitre:"Maitre",chien:"Chien") : |
|
|
|
self.maitre = maitre |
|
|
|
self.maitre = maitre |
|
|
|
self.chien = chien |
|
|
|
self.chien = chien |
|
|
|
self.map = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
self.map = [ |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
@ -122,12 +146,14 @@ class Map: |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] |
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
|
|
|
|
|
|
|
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
class Jeu: |
|
|
|
class Jeu: |
|
|
|
"""Classe intégrant la gestion du jeu.""" |
|
|
|
"""Classe intégrant la gestion du jeu.""" |
|
|
|
def __init__(self) -> None: |
|
|
|
def __init__(self) -> None: |
|
|
|
|
|
|
|
|
|
|
|
# Création de la fenêtre graphique |
|
|
|
# Création de la fenêtre graphique |
|
|
|
pyxel.init(128, 128, title="Projet chien") |
|
|
|
pyxel.init(128, 128, title="Projet chien") |
|
|
|
pyxel.load("res.pyxres") |
|
|
|
pyxel.load("res.pyxres") |
|
|
@ -140,7 +166,7 @@ class Jeu: |
|
|
|
self.maitre = Maitre(self.chien) |
|
|
|
self.maitre = Maitre(self.chien) |
|
|
|
self.joueur = Joueur(self.chien,self.maitre,self.poules) |
|
|
|
self.joueur = Joueur(self.chien,self.maitre,self.poules) |
|
|
|
pyxel.run(self.controler, self.afficher) |
|
|
|
pyxel.run(self.controler, self.afficher) |
|
|
|
|
|
|
|
|
|
|
|
def controler(self:'Jeu') -> None: |
|
|
|
def controler(self:'Jeu') -> None: |
|
|
|
"""déplacement avec les touches de directions""" |
|
|
|
"""déplacement avec les touches de directions""" |
|
|
|
|
|
|
|
|
|
|
@ -148,7 +174,13 @@ class Jeu: |
|
|
|
self.joueur.se_deplacer() |
|
|
|
self.joueur.se_deplacer() |
|
|
|
self.joueur.punition() |
|
|
|
self.joueur.punition() |
|
|
|
self.joueur.collecter() |
|
|
|
self.joueur.collecter() |
|
|
|
#self.deplacer_ennemis() |
|
|
|
for i in range(len(self.poules)) : |
|
|
|
|
|
|
|
if pyxel.frame_count % 30 == 0 : |
|
|
|
|
|
|
|
self.poules[i].deplacement() |
|
|
|
|
|
|
|
if self.joueur.poules_restantes == 0 : |
|
|
|
|
|
|
|
self.fin() |
|
|
|
|
|
|
|
if self.chien.puni : |
|
|
|
|
|
|
|
pyxel.quit() |
|
|
|
#self.supprimer_ennemis_touches() |
|
|
|
#self.supprimer_ennemis_touches() |
|
|
|
|
|
|
|
|
|
|
|
def se_deplacer(self:'Jeu')->None : |
|
|
|
def se_deplacer(self:'Jeu')->None : |
|
|
@ -170,6 +202,10 @@ class Jeu: |
|
|
|
for i in range(4) : |
|
|
|
for i in range(4) : |
|
|
|
if not self.poules[i].collecte : |
|
|
|
if not self.poules[i].collecte : |
|
|
|
self.poules[i].afficher() |
|
|
|
self.poules[i].afficher() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fin(self:'Jeu') : |
|
|
|
|
|
|
|
pyxel.text(64,64,'Bien joué !',7) |
|
|
|
|
|
|
|
pyxel.quit() |
|
|
|
|
|
|
|
|
|
|
|
# Programme Principal ! |
|
|
|
# Programme Principal ! |
|
|
|
application = Jeu() |
|
|
|
application = Jeu() |