|
|
|
@ -26,7 +26,7 @@ class Game():
|
|
|
|
|
# draw the projectiles and remove them if needed
|
|
|
|
|
to_remove = []
|
|
|
|
|
for k,proj in enumerate(self.perso.projectiles):
|
|
|
|
|
if not proj.is_out(surface):
|
|
|
|
|
if not proj.is_out(self.carte):
|
|
|
|
|
proj.move()
|
|
|
|
|
proj.draw(surface, self.perso.get_draw_offset())
|
|
|
|
|
else:
|
|
|
|
@ -108,29 +108,32 @@ class Perso():
|
|
|
|
|
|
|
|
|
|
# Update the position on x axis
|
|
|
|
|
self.posx = self.posx+self.speed[0]
|
|
|
|
|
# If new position cause to enter a wall, rollback to last position (i.e. don't move)
|
|
|
|
|
if carte.mask.overlap(self.mask, (self.posx-self.perso_rect.center[0],self.posy-self.perso_rect.center[1])):
|
|
|
|
|
self.posx = self.posx-self.speed[0]
|
|
|
|
|
self.speed[0] = 0
|
|
|
|
|
|
|
|
|
|
# Update the position on y axis
|
|
|
|
|
self.posy = self.posy+self.speed[1]
|
|
|
|
|
if carte.mask.overlap(self.mask, (self.posx-self.perso_rect.center[0],self.posy-self.perso_rect.center[1])):
|
|
|
|
|
self.posy = self.posy-self.speed[1]
|
|
|
|
|
self.speed[1] = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if keystate[self.key_fire]:
|
|
|
|
|
self.fire('fireball','asset/projectile')
|
|
|
|
|
self.fire('bullet','asset/projectile')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw(self,surface):
|
|
|
|
|
#Calculate player rotation:
|
|
|
|
|
if self.speed != [0,0]:
|
|
|
|
|
if self.speed[0]!=0:
|
|
|
|
|
self.degres_perso = -1*degrees(atan(self.speed[1]/self.speed[0]))
|
|
|
|
|
if self.speed[0] < 0:
|
|
|
|
|
self.degres_perso = 180+self.degres_perso
|
|
|
|
|
else:
|
|
|
|
|
self.degres_perso = ((self.speed[1]>0)*2-1)*-90
|
|
|
|
|
self.perso = pygame.transform.rotate(self.img_perso,self.degres_perso)
|
|
|
|
|
# if self.speed != [0,0]:
|
|
|
|
|
# if self.speed[0]!=0:
|
|
|
|
|
# self.degres_perso = -1*degrees(atan(self.speed[1]/self.speed[0]))
|
|
|
|
|
# if self.speed[0] < 0:
|
|
|
|
|
# self.degres_perso = 180+self.degres_perso
|
|
|
|
|
# else:
|
|
|
|
|
# self.degres_perso = ((self.speed[1]>0)*2-1)*-90
|
|
|
|
|
# self.perso = pygame.transform.rotate(self.img_perso,self.degres_perso)
|
|
|
|
|
|
|
|
|
|
#Calculate canon rotation:
|
|
|
|
|
x_mouse, y_mouse = pygame.mouse.get_pos()
|
|
|
|
@ -172,17 +175,21 @@ class Projectile(pygame.sprite.Sprite):
|
|
|
|
|
self.direction = direction = [cos(radians(angle)),-sin(radians(angle))]
|
|
|
|
|
self.img = pygame.transform.rotate(pygame.image.load(img_path+texture).convert_alpha(),angle)
|
|
|
|
|
self.rect = self.img.get_rect()
|
|
|
|
|
self.mask = pygame.mask.from_surface(self.img)
|
|
|
|
|
|
|
|
|
|
def move(self):
|
|
|
|
|
self.deplacement = (round(self.deplacement[0]+self.speed*self.direction[0]),round(self.deplacement[1]+self.speed*self.direction[1]))
|
|
|
|
|
|
|
|
|
|
def draw(self,surface,offset):
|
|
|
|
|
surface.blit(self.img,(offset[0]+self.pos_init[0]+self.deplacement[0]-self.rect[0],offset[1]+self.pos_init[1]+self.deplacement[1]-self.rect[1]))
|
|
|
|
|
|
|
|
|
|
def is_out(self,surface):
|
|
|
|
|
if (self.deplacement[0]+surface.get_width()/2<0-self.img.get_width() or
|
|
|
|
|
self.deplacement[1]+surface.get_height()/2<0-self.img.get_height() or
|
|
|
|
|
self.deplacement[0]+surface.get_width()/2>surface.get_width()+self.img.get_width() or
|
|
|
|
|
self.deplacement[1]+surface.get_height()/2>surface.get_height()+self.img.get_height()):
|
|
|
|
|
def is_out(self,carte):
|
|
|
|
|
abs_pos = (self.pos_init[0]+self.deplacement[0],self.pos_init[1]+self.deplacement[1])
|
|
|
|
|
if carte.mask.overlap(self.mask, (abs_pos[0]-self.rect.center[0],abs_pos[1]-self.rect.center[1])):
|
|
|
|
|
# if (self.deplacement[0]+surface.get_width()/2<0-self.img.get_width() or
|
|
|
|
|
# self.deplacement[1]+surface.get_height()/2<0-self.img.get_height() or
|
|
|
|
|
# self.deplacement[0]+surface.get_width()/2>surface.get_width()+self.img.get_width() or
|
|
|
|
|
# self.deplacement[1]+surface.get_height()/2>surface.get_height()+self.img.get_height()):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|