Browse Source

report d'un bloque de code qui gère la gravité dans le mouvement du player

Cloud37 6 months ago
parent
commit
0c4877961b
3 changed files with 27 additions and 23 deletions
  1. BIN
      saves/save.data
  2. 0 22
      src/engine/utils/animations.py
  3. 27 1
      src/objects/entities/player/player.py

BIN
saves/save.data


+ 0 - 22
src/engine/utils/animations.py

@@ -106,28 +106,6 @@ class PlayerAnimation(Animation):
                     elif rope_vector.x < 0 and rope_vector.y >0:
                         sprite = pygame.transform.rotate(sprite, 270)
                 return sprite
-
-        # On change les axes si la gravité n'est pas vers la bas
-        if self.player.gravity_orientation == Gravity.LEFT:
-            if self.player.velocity.y != 0:
-                self.x_velocity = self.player.velocity.y
-            if self.player.velocity.x != 0:
-                self.y_velocity = -self.player.velocity.x
-        elif self.player.gravity_orientation == Gravity.UP:
-            if self.player.velocity.x != 0:
-                self.x_velocity = -self.player.velocity.x
-            if self.player.velocity.y != 0:
-                self.y_velocity = -self.player.velocity.y
-        elif self.player.gravity_orientation == Gravity.RIGHT:
-            if self.player.velocity.y != 0:
-                self.x_velocity = -self.player.velocity.y
-            if self.player.velocity.x != 0:
-                self.y_velocity = self.player.velocity.x
-        else:
-            if self.player.velocity.x != 0:
-                self.x_velocity = self.player.velocity.x
-            if self.player.velocity.y != 0:
-                self.y_velocity = self.player.velocity.y
                 
         # saut et chutes
         if self.player.air_time>0.2 or self.player.is_jumping:

+ 27 - 1
src/objects/entities/player/player.py

@@ -296,6 +296,31 @@ class Player(HandlerPlayerEvent, PlayerDisplay):
         """
         fonction qui déplace le player et applique donc la physique et les collisions avec les inputs
         """
+        
+        # On change les axes si la gravité n'est pas vers la bas
+        if self.gravity_orientation == Gravity.LEFT:
+            if self.velocity.y != 0:
+                self.x_velocity = self.velocity.y
+            if self.velocity.x != 0:
+                self.y_velocity = -self.velocity.x
+                
+        elif self.gravity_orientation == Gravity.UP:
+            if self.velocity.x != 0:
+                self.x_velocity = -self.velocity.x
+            if self.velocity.y != 0:
+                self.y_velocity = -self.velocity.y
+    
+        elif self.gravity_orientation == Gravity.RIGHT:
+            if self.velocity.y != 0:
+                self.x_velocity = -self.velocity.y
+            if self.velocity.x != 0:
+                self.y_velocity = self.velocity.x
+        else:
+            if self.velocity.x != 0:
+                self.x_velocity = self.velocity.x
+            if self.velocity.y != 0:
+                self.y_velocity = self.velocity.y
+
         self.air_time += dt # update air time
         # set states on ground
         if self.collide[self.gravity_orientation]:
@@ -321,7 +346,8 @@ class Player(HandlerPlayerEvent, PlayerDisplay):
                 set_swing(self, self.primary_anchor_pos, self.rope_length)
             else:
                 update_swing(self, dt, map_manager)
-                    
+        
+           
     def update(self, dt: float, map_manager: MapManager) -> None:
         """
         Called every frame by the main loop