Projectiles bleu se supprimes

This commit is contained in:
grisel-davy 2020-03-30 23:03:42 -04:00
parent 7062491b66
commit f0f90daee0
6 changed files with 51 additions and 14 deletions

View file

@ -25,9 +25,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="-990.35093"
inkscape:cy="138.68996"
inkscape:zoom="22.4"
inkscape:cx="-1033.5604"
inkscape:cy="234.95109"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
@ -277,5 +277,15 @@
id="rect890"
style="opacity:1;fill:#ff6600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
transform="rotate(90)" />
<path
style="opacity:1;fill:#5555ff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.79649597;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="m -276.48388,232.17708 a 1.3274933,1.3274933 0 0 0 -1.32749,1.32491 l -0.006,-0.006 0.007,0.0493 a 1.3274933,1.3274933 0 0 0 0.041,0.28935 l 0.21729,1.51988 0.26549,-0.2655 0.2655,0.7965 0.2655,-0.2655 0.2655,1.32749 0.2655,-1.32749 0.2655,0.2655 0.2655,-0.7965 0.26549,0.2655 0.20638,-1.44313 a 1.3274933,1.3274933 0 0 0 0.0648,-0.40706 1.3274933,1.3274933 0 0 0 -1.32749,-1.3275 z"
id="path845"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
id="path859"
d="m -276.48958,232.44167 a 1.0329675,1.0329675 0 0 0 -1.03297,1.03096 l -0.005,-0.005 0.005,0.0384 a 1.0329675,1.0329675 0 0 0 0.0319,0.22515 l 0.16908,1.18267 0.20659,-0.20659 0.20659,0.61978 0.2066,-0.20659 0.20659,1.03296 0.2066,-1.03296 0.20659,0.20659 0.2066,-0.61978 0.20658,0.20659 0.1606,-1.12294 a 1.0329675,1.0329675 0 0 0 0.0504,-0.31675 1.0329675,1.0329675 0 0 0 -1.03297,-1.03297 z"
style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.61978054;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
asset/projectile_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

BIN
asset/projectile_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

BIN
asset/projectile_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
asset/projectile_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

View file

@ -54,19 +54,27 @@ class Perso():
self.direction = (0,1)
if keystate[self.key_fire]:
self.fire('asset/missile')
self.fire('fireball','asset/projectile')
def draw(self,surface):
surface.blit(self.img,(self.posx,self.posy))
for proj in self.projectiles:
proj.move()
proj.draw(surface)
to_remove = []
for k,proj in enumerate(self.projectiles):
if not proj.is_out(surface):
proj.move()
proj.draw(surface)
else:
to_remove.append(k)
if to_remove != []:
for k in to_remove[::-1]:
del self.projectiles[k]
def fire(self,name):
print(time())
surface.blit(self.img,(self.posx,self.posy))
print("Projectiles for {}: {}".format(self.name,len(self.projectiles)))
def fire(self,name,texture):
if (time()-self.last_fire> 0.2):
new_proj = Projectile(name,2,(self.posx,self.posy),self.direction)
new_proj = Projectile(name,texture,2,(self.posx+int(self.img.get_height()/2),self.posy+int(self.img.get_width()/2)),self.direction)
self.projectiles.append(new_proj)
self.last_fire = time()
@ -74,15 +82,34 @@ class Perso():
class Projectile():
def __init__(self,name,speed,position,direction):
def __init__(self,name,texture,speed,position,direction):
self.name = name
self.img = pygame.image.load(name+'.png')
self.speed = speed
self.position = position
self.direction = direction
if direction[0]!=0:
if direction[0]>0:
self.img = pygame.image.load(texture+'_right.png')
else:
self.img = pygame.image.load(texture+'_left.png')
else:
if direction[1]>0:
self.img = pygame.image.load(texture+'_down.png')
else:
self.img = pygame.image.load(texture+'_up.png')
def move(self):
self.position = (self.position[0]+self.speed*self.direction[0],self.position[1]+self.speed*self.direction[1])
def draw(self,surface):
surface.blit(self.img,self.position)
surface.blit(self.img,self.position)
def is_out(self,surface):
if (self.position[0]<0-self.img.get_width() or
self.position[1]<0-self.img.get_height() or
self.position[0]>surface.get_width()+self.img.get_width() or
self.position[1]>surface.get_height()+self.img.get_height()):
return True
else:
return False