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
74cd3921
Commit
74cd3921
authored
Dec 01, 2015
by
Mimeau Corentin
Browse files
Ajout de l'avancelent de l'unite
parent
a5cdc14d
Changes
1
Hide whitespace changes
Inline
Side-by-side
unite.py
View file @
74cd3921
# -*- coding: utf-8 -*-
from
pygame
import
*
import
time
from
carteStruct
import
*
from
constante
import
Constante
from
base
import
*
from
joueur
import
*
from
unite
import
*
class
Unite
:
def
__init__
(
self
):
self
.
image
=
"
img/unite
.png"
# Image du soldat
def
__init__
(
self
,
pos
):
self
.
chemin_
image
=
"
milieu_soldat
.png"
# Image du soldat
self
.
sante
=
50
# Santé du soldat
self
.
position
=
(
0
,
0
)
# Position du soldat
self
.
position
=
pos
# Position du soldat
self
.
vitesse
=
1
# Vitesse du soldat
self
.
proprietaire
=
0
# Propriétaire du soldat
self
.
violence
=
1
# Agressivité qu'apporte le soldat
self
.
prix
=
5
# Prix du soldat
self
.
liste_case
=
[]
def
afficher
(
self
,
ecran
):
res
=
image
.
load
(
self
.
chemin_image
)
im
=
transform
.
scale
(
res
,
(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
ecran
.
blit
(
im
,
self
.
position
)
return
### Retire de la sante à l'unité (si elle se fait attaquer par exemple)
def
retirerSante
(
self
,
quantite
):
...
...
@@ -20,8 +39,64 @@ class Unite:
else
:
self
.
sante
=
0
def
avancer
(
self
):
print
"test"
def
avancer
(
self
,
carte
):
(
u
,
v
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
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
))
prochaineCase
=
self
.
chercherProchaineCase
(
carte
)
print
prochaineCase
if
prochaineCase
!=
"erreur"
:
a
=
(
prochaineCase
[
0
]
*
Constante
.
taille_rel
-
self
.
position
[
0
])
b
=
(
prochaineCase
[
1
]
*
Constante
.
taille_rel
-
self
.
position
[
1
])
print
a
,
b
if
a
!=
0
:
dx
=
(
-
1
if
a
<
0
else
1
)
else
:
dx
=
0
if
b
!=
0
:
dy
=
(
-
1
if
b
<
0
else
1
)
else
:
dy
=
0
print
dx
,
dy
nPos
=
(
self
.
position
[
0
]
+
dx
,
self
.
position
[
1
]
+
dy
)
self
.
position
=
nPos
return
def
chercherProchaineCase
(
self
,
carte
):
(
u
,
v
)
=
(
self
.
position
[
0
]
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
(
a
,
b
)
=
((
self
.
position
[
0
]
-
1
)
/
Constante
.
taille_rel
,
self
.
position
[
1
]
/
Constante
.
taille_rel
)
(
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
)
if
(
a
,
b
)
in
carte
.
liste_route
and
(
a
,
b
)
not
in
self
.
liste_case
:
return
(
a
,
b
)
if
(
c
,
d
)
in
carte
.
liste_route
and
(
c
,
d
)
not
in
self
.
liste_case
:
return
(
c
,
d
)
if
(
e
,
f
)
in
carte
.
liste_route
and
(
e
,
f
)
not
in
self
.
liste_case
:
return
(
e
,
f
)
if
(
g
,
h
)
in
carte
.
liste_route
and
(
g
,
h
)
not
in
self
.
liste_case
:
return
(
g
,
h
)
else
:
return
"erreur"
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