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
fe9c13f5
Commit
fe9c13f5
authored
Dec 08, 2015
by
Corentin MIMEAU
Browse files
update
parent
dbacf2f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
tour.py
View file @
fe9c13f5
...
...
@@ -12,9 +12,11 @@ from constante import Constante
from
base
import
*
from
joueur
import
*
from
tour
import
*
from
projectile
import
*
class
Tour
:
def
__init__
(
self
,
pos
,
prop
):
self
.
degatType
=
""
# Type de dégat de la tour
self
.
position
=
pos
# Coordonées de la tour
...
...
@@ -23,32 +25,48 @@ class Tour:
self
.
vitesse
=
0
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
### Attaque
def
attaquerUnite
(
self
,
unite
):
print
"Attaque."
if
self
.
verifierUnite
(
unite
):
unite
.
retirerSante
(
self
.
degat
)
def
attaquer
(
self
,
liste_unite
):
#print "Attaque."
u
=
self
.
chercherUnite
(
liste_unite
)
if
u
!=
0
:
p
=
Projectile
((
self
.
position
[
0
]
*
Constante
.
taille_rel
,
self
.
position
[
1
]
*
Constante
.
taille_rel
),
(
50
,
50
),
self
.
vitesse
,
u
)
self
.
liste_proj
.
append
(
p
)
#u.retirerSante(self.degat)
else
:
print
"Impossible d'attaquer cette unite"
print
"Pas d'unité à attaquer"
def
actualiserProj
(
self
,
ecran
):
for
i
in
self
.
liste_proj
:
i
.
avancer
(
ecran
)
#def calculerPositionProj(self, unite):
### Vérifie si une unité est a portée
def
verifierUnite
(
self
,
unite
):
distance
=
math
.
fabs
(
self
.
position
[
0
]
-
unite
.
position
[
0
])
+
math
.
fabs
(
self
.
position
[
1
]
-
unite
.
position
[
1
])
distance
=
math
.
fabs
(
self
.
position
[
0
]
-
unite
.
position
[
0
]
/
Constante
.
taille_rel
)
+
math
.
fabs
(
self
.
position
[
1
]
-
unite
.
position
[
1
]
/
Constante
.
taille_rel
)
print
"Distance a la tour : "
+
str
(
distance
)
if
(
distance
<=
self
.
portee
):
assert
(
unite
.
proprietaire
==
self
.
proprietaire
)
if
(
unite
.
proprietaire
=
=
self
.
proprietaire
):
#
assert(unite.proprietaire == self.proprietaire)
if
(
unite
.
proprietaire
!
=
self
.
proprietaire
):
return
True
else
:
return
False
return
False
def
chercherUnite
(
self
,
liste_unite
):
for
i
in
liste_unite
:
if
self
.
verifierUnite
(
i
):
return
i
return
0
...
...
@@ -63,6 +81,7 @@ class Tour_feu(Tour):
self
.
vitesse
=
1
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
def
afficher
(
self
,
ecran
):
tour_1_finale
=
transform
.
scale
(
self
.
image
,(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
...
...
@@ -79,6 +98,7 @@ class Tour_glace(Tour):
self
.
vitesse
=
2
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
def
afficher
(
self
,
ecran
):
tour_2_finale
=
transform
.
scale
(
self
.
image
,(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
...
...
@@ -88,4 +108,113 @@ class Tour_glace(Tour):
# -*- coding: utf-8 -*-
# http://pad.univ-nantes.fr/editor/p/g.KMzBqiBBATY1dYss$Ageofdefense
import
math
from
pygame
import
*
import
time
import
os
from
carteStruct
import
*
from
constante
import
Constante
from
base
import
*
from
joueur
import
*
from
tour
import
*
from
projectile
import
*
class
Tour
:
def
__init__
(
self
,
pos
,
prop
):
self
.
degatType
=
""
# Type de dégat de la tour
self
.
position
=
pos
# Coordonées de la tour
self
.
portee
=
0
# Portee de la tour
self
.
degat
=
0
# Dégat de chaque projectile jeté de la tour
self
.
vitesse
=
0
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
### Attaque
def
attaquer
(
self
,
liste_unite
):
#print "Attaque."
u
=
self
.
chercherUnite
(
liste_unite
)
if
u
!=
0
:
p
=
Projectile
((
self
.
position
[
0
]
*
Constante
.
taille_rel
,
self
.
position
[
1
]
*
Constante
.
taille_rel
),
(
50
,
50
),
self
.
vitesse
,
u
)
self
.
liste_proj
.
append
(
p
)
#u.retirerSante(self.degat)
else
:
print
"Pas d'unité à attaquer"
def
actualiserProj
(
self
,
ecran
):
for
i
in
self
.
liste_proj
:
i
.
avancer
(
ecran
)
#def calculerPositionProj(self, unite):
### Vérifie si une unité est a portée
def
verifierUnite
(
self
,
unite
):
distance
=
math
.
fabs
(
self
.
position
[
0
]
-
unite
.
position
[
0
]
/
Constante
.
taille_rel
)
+
math
.
fabs
(
self
.
position
[
1
]
-
unite
.
position
[
1
]
/
Constante
.
taille_rel
)
print
"Distance a la tour : "
+
str
(
distance
)
if
(
distance
<=
self
.
portee
):
#assert(unite.proprietaire == self.proprietaire)
if
(
unite
.
proprietaire
!=
self
.
proprietaire
):
return
True
return
False
def
chercherUnite
(
self
,
liste_unite
):
for
i
in
liste_unite
:
if
self
.
verifierUnite
(
i
):
return
i
return
0
class
Tour_feu
(
Tour
):
def
__init__
(
self
,
pos
,
prop
):
self
.
image
=
image
.
load
(
"tour_1_avec_fond.png"
)
self
.
degatType
=
"fire"
# Type de dégat de la tour
self
.
position
=
pos
# Coordonées de la tour
self
.
portee
=
5
# Portee de la tour
self
.
degat
=
10
# Dégat de chaque projectile jeté de la tour
self
.
vitesse
=
1
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
def
afficher
(
self
,
ecran
):
tour_1_finale
=
transform
.
scale
(
self
.
image
,(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
ecran
.
blit
(
tour_1_finale
,
(
self
.
position
[
0
]
*
Constante
.
taille_rel
,
self
.
position
[
1
]
*
Constante
.
taille_rel
))
class
Tour_glace
(
Tour
):
def
__init__
(
self
,
pos
,
prop
):
self
.
image
=
image
.
load
(
"tour_2_avec_fond.png"
)
self
.
degatType
=
"ice"
# Type de dégat de la tour
self
.
position
=
pos
# Coordonées de la tour
self
.
portee
=
5
# Portee de la tour
self
.
degat
=
100
# Dégat de chaque projectile jeté de la tour
self
.
vitesse
=
2
# Nombre de projectile lancé par seconde
self
.
niveau
=
0
# Niveau de la tour
self
.
proprietaire
=
prop
# Propriétaire de la tour
self
.
liste_proj
=
[]
def
afficher
(
self
,
ecran
):
tour_2_finale
=
transform
.
scale
(
self
.
image
,(
Constante
.
taille_rel
,
Constante
.
taille_rel
))
ecran
.
blit
(
tour_2_finale
,
(
self
.
position
[
0
]
*
Constante
.
taille_rel
,
self
.
position
[
1
]
*
Constante
.
taille_rel
))
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