Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Corentin MIMEAU
PolyDefense
Commits
2eb17af5
Commit
2eb17af5
authored
Dec 14, 2015
by
Corentin MIMEAU
Browse files
Commentaire
parent
b109ba22
Changes
1
Hide whitespace changes
Inline
Side-by-side
unite.py
View file @
2eb17af5
...
...
@@ -11,46 +11,50 @@ from base import *
from
joueur
import
*
from
unite
import
*
# Classe Unite
#
#
class
Unite
:
def
__init__
(
self
,
pos
,
pro
):
self
.
chemin_image_soldat_1
=
""
# Image du soldat
self
.
chemin_image_soldat_3
=
""
self
.
chemin_image_soldat_2
=
""
self
.
chemin_image_soldat_4
=
""
self
.
chemin_image_route
=
""
self
.
numero_image
=
0
self
.
sante
=
50
# Santé du soldat
self
.
sante_totale
=
50
self
.
position
=
pos
self
.
vitesse
=
1
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
self
.
violence
=
1
# Agressivité qu'apporte le soldat
self
.
prix
=
5
# Prix du soldat
self
.
temps
=
0
self
.
liste_case
=
[]
self
.
temps_passe
=
0
self
.
chemin_image_soldat_1
=
""
# Chemin de la première image du soldat
self
.
chemin_image_soldat_3
=
""
# Deuxième image
self
.
chemin_image_soldat_2
=
""
# Troisième
self
.
chemin_image_soldat_4
=
""
# Quatrième
#self.chemin_image_route = "" # Chemin de l'image de la route
self
.
numero_image
=
0
# Image actuelle à utiliser
self
.
sante
=
50
# Santé actuelle du soldat
self
.
sante_totale
=
50
# Santé maximale du soldat
self
.
position
=
pos
# Position actuelle du soldat
self
.
vitesse
=
1
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
self
.
violence
=
1
# Agressivité qu'apporte le soldat
self
.
prix
=
5
# Prix du soldat
self
.
temps
=
0
# Temps actuel
self
.
liste_case
=
[]
# Liste des cases déjà parcourues par le soldat
self
.
temps_passe
=
0
# Temps écoulé depuis la dernière mise à jour
# Modifie la vitesse du soldat
def
modifier_vitesse
(
self
,
vit
):
self
.
vitesse
=
vit
# Calcule le temps écoulé depuis la dernière fois
def
chrono
(
self
):
return
self
.
temps_passe
-
self
.
temps
# Affiche l'unité à l'écran
def
afficher
(
self
,
ecran
):
if
self
.
affichage
==
1
:
if
self
.
numero_image
==
1
:
image_soldat_in
iti
ale
=
image
.
load
(
self
.
chemin_image_soldat
)
image_soldat_
f
inale
=
transform
.
scale
(
self
.
image_soldat
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
)
)
elif
self
.
numero_image
==
2
:
image_soldat_in
iti
ale
=
image
.
load
(
self
.
chemin_image_soldat_2
)
image_soldat_
f
inale
=
transform
.
scale
(
self
.
image_soldat_2
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
)
)
elif
self
.
numero_image
==
3
:
image_soldat_in
iti
ale
=
image
.
load
(
self
.
chemin_image_soldat_3
)
image_soldat_
f
inale
=
transform
.
scale
(
self
.
image_soldat_3
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
)
)
elif
self
.
numero_image
==
4
:
image_soldat_initiale
=
image
.
load
(
self
.
chemin_image_soldat_4
)
image_soldat_finale
=
transform
.
scale
(
self
.
image_soldat_4
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
image_soldat_finale
=
transform
.
scale
(
image_soldat_initiale
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
ecran
.
blit
(
image_soldat_finale
,
self
.
position
)
draw
.
rect
(
ecran
,
(
255
,
0
,
0
),
(
self
.
position
[
0
],
self
.
position
[
1
],(
Constante
.
taille_rel
*
self
.
sante
/
self
.
sante_totale
),
Constante
.
taille_rel
/
10
))
...
...
@@ -59,40 +63,49 @@ class Unite:
return
#
##
Retire de la sante à l'unité (si elle se fait attaquer par exemple)
# Retire de la sante à l'unité (si elle se fait attaquer par exemple)
def
retirerSante
(
self
,
quantite
):
if
quantite
<
self
.
sante
:
self
.
sante
=
self
.
sante
-
quantite
else
:
self
.
sante
=
0
# Fait avancer le soldat
def
avancer
(
self
,
carte
,
base
,
base_ennemie
,
ecran
):
# Test du temps écoulé (doit-on avancer le soldat ?)
if
self
.
chrono
()
>
self
.
vitesse
:
self
.
temps
=
time
.
time
()
# Récupère la position en case de l'unité
(
u
,
v
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
# On marque la case comme visitée si elle ne l'est pas déjà
if
(
u
,
v
)
not
in
self
.
liste_case
:
if
(
self
.
position
[
0
]
%
Constante
.
taille_rel
==
0
and
self
.
position
[
1
]
%
Constante
.
taille_rel
==
0
):
self
.
liste_case
.
append
((
u
,
v
))
# On cherche la prochaine case (pour pouvoir déterminer la direction)
prochaineCase
=
self
.
chercherProchaineCase
(
carte
)
if
prochaineCase
!=
"erreur"
:
a
=
(
prochaineCase
[
0
]
*
Constante
.
taille_rel
-
self
.
position
[
0
])
b
=
(
prochaineCase
[
1
]
*
Constante
.
taille_rel
-
self
.
position
[
1
])
# Gauche ou droite
if
a
!=
0
:
dx
=
(
-
(
Constante
.
taille_rel
/
4
)
if
a
<
0
else
Constante
.
taille_rel
/
4
)
else
:
dx
=
0
# Haut ou bas
if
b
!=
0
:
dy
=
(
-
(
Constante
.
taille_rel
/
4
)
if
b
<
0
else
Constante
.
taille_rel
/
4
)
else
:
dy
=
0
# Détermine le sprite de l'unité en fonction de la direction
if
dx
==
-
(
Constante
.
taille_rel
/
4
)
:
self
.
numero_image
=
1
elif
dx
==
Constante
.
taille_rel
/
4
:
...
...
@@ -102,9 +115,11 @@ class Unite:
elif
dy
==
Constante
.
taille_rel
/
4
:
self
.
numero_image
=
4
# Modifie la position du joueur
nPos
=
(
self
.
position
[
0
]
+
dx
,
self
.
position
[
1
]
+
dy
)
self
.
position
=
nPos
# En fonction du propriétaire, enlève de la vie à la base si l'unité l'atteint
if
self
.
proprietaire
==
2
:
if
nPos
[
0
]
==
2
*
Constante
.
taille_rel
and
nPos
[
1
]
==
4
*
Constante
.
taille_rel
:
base_ennemie
.
perte_sante
()
...
...
@@ -119,13 +134,16 @@ class Unite:
return
else
:
# Met à jour le temps
self
.
temps_passe
=
time
.
time
()
return
# Retourne la prochaine case à visiter par le soldat
def
chercherProchaineCase
(
self
,
carte
):
(
u
,
v
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
(
u
,
v
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
# Position du soldat
(
a
,
b
)
=
((
self
.
position
[
0
]
-
1
)
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
(
a
,
b
)
=
((
self
.
position
[
0
]
-
1
)
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
# les 4 cases autours
(
c
,
d
)
=
((
self
.
position
[
0
]
+
Constante
.
taille_rel
)
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
(
e
,
f
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
(
self
.
position
[
1
]
-
1
)
/
Constante
.
taille_rel
)
(
g
,
h
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
(
self
.
position
[
1
]
+
Constante
.
taille_rel
)
/
Constante
.
taille_rel
)
...
...
@@ -143,20 +161,23 @@ class Unite:
else
:
return
"erreur"
### Spécialisation ###
class
Elfe
(
Unite
):
def
__init__
(
self
,
pos
,
pro
):
self
.
chemin_
image_soldat
=
"elfe.png"
# Image du soldat
self
.
chemin_
image_soldat_2
=
"elfe_2.png"
self
.
chemin_
image_soldat_3
=
"elfe_3.png"
self
.
chemin_
image_soldat_4
=
"elfe_4.png"
self
.
image_soldat
=
image
.
load
(
"elfe.png"
)
# Image du soldat
self
.
image_soldat_2
=
image
.
load
(
"elfe_2.png"
)
self
.
image_soldat_3
=
image
.
load
(
"elfe_3.png"
)
self
.
image_soldat_4
=
image
.
load
(
"elfe_4.png"
)
self
.
numero_image
=
1
self
.
chemin_image_route
=
"route.png"
self
.
sante
=
2
00
# Santé du soldat
self
.
sante_totale
=
2
00
self
.
sante
=
4
00
# Santé du soldat
self
.
sante_totale
=
4
00
self
.
position
=
pos
# Position du soldat
self
.
vitesse
=
0.1
# Vitesse du soldat
self
.
vitesse
=
0.1
5
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
self
.
type
=
1
# Agressivité qu'apporte le soldat
self
.
prix
=
50
...
...
@@ -168,14 +189,14 @@ class Elfe(Unite):
class
Loup
(
Unite
):
def
__init__
(
self
,
pos
,
pro
):
self
.
chemin_
image_soldat
=
"loup.png"
# Image du soldat
self
.
chemin_
image_soldat_2
=
"loup_2.png"
self
.
chemin_
image_soldat_3
=
"loup_3.png"
self
.
chemin_
image_soldat_4
=
"loup_4.png"
self
.
image_soldat
=
image
.
load
(
"loup.png"
)
# Image du soldat
self
.
image_soldat_2
=
image
.
load
(
"loup_2.png"
)
self
.
image_soldat_3
=
image
.
load
(
"loup_3.png"
)
self
.
image_soldat_4
=
image
.
load
(
"loup_4.png"
)
self
.
numero_image
=
1
self
.
chemin_image_route
=
"route.png"
self
.
sante
=
50
# Santé du soldat
self
.
sante_totale
=
5
0
self
.
sante
=
100
# Santé du soldat
self
.
sante_totale
=
10
0
self
.
position
=
pos
# Position du soldat
self
.
vitesse
=
0.01
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
...
...
@@ -189,16 +210,16 @@ class Loup(Unite):
class
Paladin
(
Unite
):
def
__init__
(
self
,
pos
,
pro
):
self
.
chemin_
image_soldat
=
"paladin.png"
# Image du soldat
self
.
chemin_
image_soldat_2
=
"paladin_2.png"
self
.
chemin_
image_soldat_3
=
"paladin_3.png"
self
.
chemin_
image_soldat_4
=
"paladin_4.png"
self
.
image_soldat
=
image
.
load
(
"paladin.png"
)
# Image du soldat
self
.
image_soldat_2
=
image
.
load
(
"paladin_2.png"
)
self
.
image_soldat_3
=
image
.
load
(
"paladin_3.png"
)
self
.
image_soldat_4
=
image
.
load
(
"paladin_4.png"
)
self
.
numero_image
=
1
self
.
chemin_image_route
=
"route.png"
self
.
sante
=
500
# Santé du soldat
self
.
sante_totale
=
500
self
.
sante
=
1
500
# Santé du soldat
self
.
sante_totale
=
1
500
self
.
position
=
pos
# Position du soldat
self
.
vitesse
=
0.
3
# Vitesse du soldat
self
.
vitesse
=
0.
2
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
self
.
type
=
3
# Agressivité qu'apporte le soldat
self
.
prix
=
200
...
...
@@ -210,16 +231,16 @@ class Paladin(Unite):
class
Soldat
(
Unite
):
def
__init__
(
self
,
pos
,
pro
):
self
.
chemin_
image_soldat
=
"soldat.png"
# Image du soldat
self
.
chemin_
image_soldat_2
=
"soldat_2.png"
self
.
chemin_
image_soldat_3
=
"soldat_3.png"
self
.
chemin_
image_soldat_4
=
"soldat_4.png"
self
.
image_soldat
=
image
.
load
(
"soldat.png"
)
# Image du soldat
self
.
image_soldat_2
=
image
.
load
(
"soldat_2.png"
)
self
.
image_soldat_3
=
image
.
load
(
"soldat_3.png"
)
self
.
image_soldat_4
=
image
.
load
(
"soldat_4.png"
)
self
.
numero_image
=
1
self
.
chemin_image_route
=
"route.png"
self
.
sante
=
15
0
# Santé du soldat
self
.
sante_totale
=
15
0
self
.
sante
=
20
0
# Santé du soldat
self
.
sante_totale
=
20
0
self
.
position
=
pos
# Position du soldat
self
.
vitesse
=
0.
2
# Vitesse du soldat
self
.
vitesse
=
0.
1
# Vitesse du soldat
self
.
proprietaire
=
pro
# Propriétaire du soldat
self
.
type
=
4
# Agressivité qu'apporte le soldat
self
.
prix
=
50
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment