diff --git a/asset/asset.svg b/asset/asset.svg
index d3b414f..6b764c7 100644
--- a/asset/asset.svg
+++ b/asset/asset.svg
@@ -14,7 +14,7 @@
viewBox="0 0 210 297"
version="1.1"
id="svg8"
- inkscape:version="0.92.4 5da689c313, 2019-01-14"
+ inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
sodipodi:docname="asset.svg">
@@ -25,9 +25,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="0.24748737"
- inkscape:cx="-3244.5066"
- inkscape:cy="371.0213"
+ inkscape:zoom="20.055905"
+ inkscape:cx="-1045.8998"
+ inkscape:cy="197.95561"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
@@ -73,24 +73,6 @@
y="238.79167"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
-
-
+
+
+
+
+
+
+
+
+
diff --git a/asset/perso.png b/asset/perso.png
new file mode 100644
index 0000000..19c8aec
Binary files /dev/null and b/asset/perso.png differ
diff --git a/asset/perso1_right.png b/asset/perso1_right.png
index cca4d30..ea122db 100644
Binary files a/asset/perso1_right.png and b/asset/perso1_right.png differ
diff --git a/main.py b/main.py
index 78a601b..a925ea2 100644
--- a/main.py
+++ b/main.py
@@ -23,7 +23,7 @@ BLUE=(0,0,255)
RED=(255,0,0)
carte = Carte('map_1.png')
-perso = Perso('Alice',660,1570,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,'perso1_right.png','canon.png','projectile1_right.png')
+perso = Perso('Alice',660,1570,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,'perso.png','canon.png','projectile1_right.png')
game = Game(carte,perso)
clock = pygame.time.Clock()
diff --git a/models.py b/models.py
index 43254ca..c1a8579 100644
--- a/models.py
+++ b/models.py
@@ -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
\ No newline at end of file