|
|
|
@ -6,7 +6,8 @@ import random as rd
|
|
|
|
|
|
|
|
|
|
# CONSTANTES et variables globales lues directement ========================= |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XMAX = 128 |
|
|
|
|
YMAX = 128 |
|
|
|
|
|
|
|
|
|
# Déclaration des classes |
|
|
|
|
class Chien : |
|
|
|
@ -17,19 +18,63 @@ class Chien :
|
|
|
|
|
|
|
|
|
|
def afficher(self:'Chien') -> None: |
|
|
|
|
"""Affiche le chien""" |
|
|
|
|
pyxel.blt(self.x, self.y, 0, 0, 0, 8, 8) |
|
|
|
|
pyxel.blt(self.x,self.y,0,0,0,8,8) |
|
|
|
|
|
|
|
|
|
def dep_x(self,dist) : |
|
|
|
|
self.x = self.x + dist |
|
|
|
|
if self.x < 0: |
|
|
|
|
self.x = 0 |
|
|
|
|
elif self.x >= XMAX: |
|
|
|
|
self.x = XMAX |
|
|
|
|
|
|
|
|
|
def dep_y(self,dist) : |
|
|
|
|
|
|
|
|
|
self.y = self.y + dist |
|
|
|
|
if self.y < 0: |
|
|
|
|
self.y = 0 |
|
|
|
|
elif self.y >= YMAX: |
|
|
|
|
self.y = YMAX |
|
|
|
|
|
|
|
|
|
class Joueur : |
|
|
|
|
|
|
|
|
|
def __init__(self,chien:'Chien') : |
|
|
|
|
self.chien = chien |
|
|
|
|
|
|
|
|
|
def se_deplacer(self) : |
|
|
|
|
if pyxel.btn(pyxel.KEY_RIGHT): |
|
|
|
|
self.chien.dep_x(1) |
|
|
|
|
if pyxel.btn(pyxel.KEY_LEFT): |
|
|
|
|
self.chien.dep_x(-1) |
|
|
|
|
if pyxel.btn(pyxel.KEY_DOWN): |
|
|
|
|
self.chien.dep_y(1) |
|
|
|
|
if pyxel.btn(pyxel.KEY_UP): |
|
|
|
|
self.chien.dep_y(-1) |
|
|
|
|
|
|
|
|
|
class Maitre : |
|
|
|
|
def __init__(self) : |
|
|
|
|
self.posx = rd.randint(0,XMAX) |
|
|
|
|
self.posy = rd.randint(0,YMAX) |
|
|
|
|
self.ori = |
|
|
|
|
self.poursuite = False |
|
|
|
|
self.blesse = False |
|
|
|
|
self.x = rd.randint(0,XMAX) |
|
|
|
|
self.y = rd.randint(0,YMAX) |
|
|
|
|
|
|
|
|
|
def deplacer(self) : |
|
|
|
|
rand_dist_x = rd.randint(0,XMAX/16) |
|
|
|
|
rand_dist_x = rd.choice((-1,0,1))*rand_dist_x |
|
|
|
|
rand_dist_y = rd.randint(0,YMAX/16) |
|
|
|
|
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) : |
|
|
|
|
pyxel.blt(self.x,self.y,0,8,0,8,8) |
|
|
|
|
|
|
|
|
|
class Poule : |
|
|
|
|
pass |
|
|
|
@ -42,34 +87,37 @@ class Jeu:
|
|
|
|
|
pyxel.init(128, 128, title="Projet chien") |
|
|
|
|
pyxel.load("res.pyxres") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.chien = Chien() |
|
|
|
|
self.joueur = Joueur |
|
|
|
|
self.maitre = Maitre() |
|
|
|
|
self.joueur = Joueur(self.chien) |
|
|
|
|
pyxel.run(self.controler, self.afficher) |
|
|
|
|
|
|
|
|
|
def controler(self:'Jeu') -> None: |
|
|
|
|
"""déplacement avec les touches de directions""" |
|
|
|
|
|
|
|
|
|
self.se_deplacer() |
|
|
|
|
|
|
|
|
|
self.croc() |
|
|
|
|
self.deplacer_ennemis() |
|
|
|
|
self.supprimer_ennemis_touches() |
|
|
|
|
self.maitre.deplacer() |
|
|
|
|
self.joueur.se_deplacer() |
|
|
|
|
#self.croc() |
|
|
|
|
#self.deplacer_ennemis() |
|
|
|
|
#self.supprimer_ennemis_touches() |
|
|
|
|
|
|
|
|
|
def se_deplacer(self:'Jeu')->None : |
|
|
|
|
if pyxel.btn(pyxel.KEY_RIGHT) : |
|
|
|
|
self.chien.set_x(2) |
|
|
|
|
self.chien.dep_x(2) |
|
|
|
|
if pyxel.btn(pyxel.KEY_LEFT) : |
|
|
|
|
self.chien.set_x(-2) |
|
|
|
|
self.chien.dep_x(-2) |
|
|
|
|
if pyxel.btn(pyxel.KEY_DOWN) : |
|
|
|
|
self.chien.set_y(2) |
|
|
|
|
self.chien.dep_y(2) |
|
|
|
|
if pyxel.btn(pyxel.KEY_TOP) : |
|
|
|
|
self.chien.set_y(-2) |
|
|
|
|
self.chien.dep_y(-2) |
|
|
|
|
|
|
|
|
|
def afficher(self:'Jeu') : |
|
|
|
|
|
|
|
|
|
pyxel.cls(0) # efface le contenu de la fenetre |
|
|
|
|
|
|
|
|
|
self.chien.afficher() |
|
|
|
|
self.maitre.afficher() |
|
|
|
|
|
|
|
|
|
# Programme Principal ! |
|
|
|
|
|
|
|
|
|