Commits

SkRt committed ace2c82

Agregando un par de cambios a Pong

Comments (0)

Files changed (1)

 class Ball(pygame.sprite.Sprite):
     def __init__(self):
         pygame.sprite.Sprite.__init__(self)
-        self.image = load_image("images/ball.png", True)
-        self.rect = self.image.get_rect()
-        self.rect.centerx = WIDTH / 2
-        self.rect.centery = HEIGHT / 2
-        self.speed = [0.5, -0.5]
+        self.image = load_image("images/ball.png", True)  # Esto carga la imagen y la hace transparente.
+        self.rect = self.image.get_rect() # Esto obtiene el rectángulo del sprite, y la pasa a una variable.
+        self.rect.centerx = WIDTH / 2    # Estas dos lineas
+        self.rect.centery = HEIGHT / 2   # ponen la bola en el centro de la pantalla.
+        self.speed = [0.5, -0.5]         # Esto hace una lista con dos valores que servirán para definir la velocidad de la bola.
 
     def refresh(self, time_play, brick_player, brick_cpu, points):
-        self.rect.centerx += self.speed[0] * time_play
-        self.rect.centery += self.speed[1] * time_play
+        self.rect.centerx += self.speed[0] * time_play              # Esto hace que la bola se mueva, distancia = velocidad * tiempo (tomando el primer valor de la lista, para el eje x)
+        self.rect.centery += self.speed[1] * time_play              # Y esto para el eje y
 
-        if self.rect.left <=0:
-            points[1] += 1
-            self.rect.centerx = WIDTH / 2
-            self.rect.centery = HEIGHT / 2
-
-        if self.rect.right >= WIDTH:
-            points[0] += 1
-            self.rect.centerx = WIDTH / 2
-            self.rect.centery = HEIGHT / 2
-
-
-
-        if self.rect.left <= 0 or self.rect.right >= WIDTH:
-            self.speed[0] = -self.speed[0]
-            self.rect.centerx += self.speed[0] * time_play
+        if self.rect.left <=0:                                     # Esto gestiona el sistema de puntuaciones
+            points[1] += 1                                          #
+                                                                    #
+        if self.rect.right >= WIDTH:                               #
+            points[0] += 1                                          #
+            
+        if self.rect.left <= 0 or self.rect.right >= WIDTH:       # Esto hace que la bola rebote de la pared
+            self.speed[0] = -self.speed[0]                        # Esto hace que vaya al lado contrario
+            self.rect.centerx += self.speed[0] * time_play        
+            
         if self.rect.top <= 0 or self.rect.bottom >= HEIGHT:
             self.speed[1] = -self.speed[1]
             self.rect.centery += self.speed[1] * time_play
 
     background_image = load_image('images/fondo_pong.png')
     ball = Ball()
-    brick_player = Brick(30)
-    brick_cpu = Brick(WIDTH - 30)
+    brick_player = Brick(5)
+    brick_cpu = Brick(WIDTH - 5)
 
     clock = pygame.time.Clock()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.