Repository: alecwatersmusic/Peanut-Piper-Game
Pull request #2: more settings and piper image
Author: login: alecwatersmusic
Created: 2025-05-15T17:24:52Z | Merged: 2025-05-18T18:36:36Z



Diff:
diff --git a/src/PeanutPiper.bmp b/src/PeanutPiper.bmp
new file mode 100644
index 0000000..1ef3ede
Binary files /dev/null and b/src/PeanutPiper.bmp differ
diff --git a/src/__pycache__/piper.cpython-39.pyc b/src/__pycache__/piper.cpython-39.pyc
new file mode 100644
index 0000000..8798f2e
Binary files /dev/null and b/src/__pycache__/piper.cpython-39.pyc differ
diff --git a/src/__pycache__/settings.cpython-39.pyc b/src/__pycache__/settings.cpython-39.pyc
new file mode 100644
index 0000000..38cd631
Binary files /dev/null and b/src/__pycache__/settings.cpython-39.pyc differ
diff --git a/src/peanut_piper.py b/src/peanut_piper.py
index 962f9e0..72b8e58 100644
--- a/src/peanut_piper.py
+++ b/src/peanut_piper.py
@@ -3,6 +3,7 @@
 import pygame
 
 from settings import Settings
+from piper import Piper
 
 class PeanutPiper: 
     """Overall class to manage game assets and behavior."""
@@ -14,10 +15,14 @@ def __init__(self):
         self.clock = pygame.time.Clock()
         self.settings = Settings()
 
-        self.screen = pygame.display.set_mode(
-            (self.settings.screen_width, self.settings.screen_height))
+        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
+        self.settings.screen_width = self.screen.get_rect().width
+        self.settings.screen_height = self.screen.get_rect().height
+
         pygame.display.set_caption("Peanut Piper")
 
+        self.piper = Piper(self)
+
         # Set the background color.
         self.bg_color = (50,230,50)
 
@@ -25,16 +30,43 @@ def run_game(self):
         """Start the main loop for the game."""
         while True:
             # Watch for keyboard and mouse events.
-            for event in pygame.event.get():
+            self._check_events()
+            self.piper.update()
+            self._update_screen()
+            self.clock.tick(60)
+
+    def _check_events(self):
+        """Respond to keypresses and mouse events."""
+        for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     sys.exit()
+                elif event.type == pygame.KEYDOWN:
+                    self._check_keydown_events(event)
+                elif event.type == pygame.KEYUP:
+                    self._check_keyup_events(event)
 
-            # Redraw the screen during each pass through the loop.
-            self.screen.fill(self.bg_color)
+    def _check_keydown_events(self, event):
+        """Respond to keypresses."""
+        if event.key == pygame.K_RIGHT:
+            self.piper.moving_right = True
+        elif event.key == pygame.K_LEFT:
+            self.piper.moving_left = True
+        elif event.key == pygame.K_q:
+            sys.exit()
 
-            # Make the most recently drawn screen visible.
-            pygame.display.flip()
-            self.clock.tick(60)
+    def _check_keyup_events(self, event):
+        """Respond to key releases."""
+        if event.key == pygame.K_RIGHT:
+            self.piper.moving_right = False
+        elif event.key == pygame.K_LEFT:
+            self.piper.moving_left = False
+
+    def _update_screen(self):
+        """Update images on the screen, and flip to the new screen."""
+        self.screen.fill(self.bg_color)
+        self.piper.blitme()
+
+        pygame.display.flip()
 
 if __name__ == '__main__':
     # Make a game instance, and run the game.
diff --git a/src/piper.py b/src/piper.py
new file mode 100644
index 0000000..db7733e
--- /dev/null
+++ b/src/piper.py
@@ -0,0 +1,39 @@
+import pygame
+
+class Piper:
+    """A class to manage the piper."""
+
+    def __init__(self, ai_game):
+        """Initialize the piper and set its starting position."""
+        self.screen = ai_game.screen
+        self.settings = ai_game.settings
+        self.screen_rect = ai_game.screen.get_rect()
+
+        # Load the piper image and get its rect.
+        self.image = pygame.image.load('src/PeanutPiper.bmp')
+        self.rect = self.image.get_rect()
+
+        # Start each new piper at the bottom center of the screen.
+        self.rect.midbottom = self.screen_rect.midbottom
+
+        # Store a float for the ship's exact horizontal position.
+        self.x = float (self.rect.x)
+
+        # Movement flags; start with a piper that's not moving.
+        self.moving_right = False
+        self.moving_left = False
+
+    def update(self):
+        """Update the piper's position based on the movement flags."""
+        # Update the ship's x value, not the rect.
+        if self.moving_right and self.rect.right < self.screen_rect.right:
+            self.x += self.settings.piper_speed
+        if self.moving_left and self.rect.left > 0:
+            self.x -= self.settings.piper_speed
+
+        # Update rect object from self.x.
+        self.rect.x = self.x
+
+    def blitme(self):
+        """Draw the piper at its current location."""
+        self.screen.blit(self.image, self.rect)
\ No newline at end of file
diff --git a/resources/settings.py b/src/settings.py
similarity index 72%
rename from resources/settings.py
rename to src/settings.py
index 36aa7a9..4773db5 100644
--- a/resources/settings.py
+++ b/src/settings.py
@@ -6,4 +6,7 @@ def __init__(self):
         # Screen Settings
         self.screen_width = 1200
         self.screen_height = 800
-        self.bg_color = (50,230,50)
\ No newline at end of file
+        self.bg_color = (50,230,50)
+
+        # Piper Settings
+        self.piper_speed = 1.5
\ No newline at end of file


Reviews:
user: login: dontworrybhappy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-16T02:04:18Z
user: login: alecwatersmusic
state: COMMENTED
author_association: OWNER
submitted_at: 2025-05-18T02:54:21Z

Review comments:
diff_hunk: @@ -0,0 +1,20 @@
+import pygame
+
+class Piper:
+    """A class to manage the piper."""
+
+    def __init__(self, ai_game):
+        """Initialize the ship and set its starting position."""
path: src/piper.py
user: login: dontworrybhappy
body: Please check your comments - they appear to be inaccurate (what ship?). 
created_at: 2025-05-16T02:04:18Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,20 @@
+import pygame
+
+class Piper:
+    """A class to manage the piper."""
+
+    def __init__(self, ai_game):
+        """Initialize the ship and set its starting position."""
path: src/piper.py
user: login: alecwatersmusic
body: Fixed it! Good catch :)
created_at: 2025-05-18T02:54:21Z
author_association: OWNER

PR comments:
user: login: alecwatersmusic
created_at: 2025-05-15T21:58:57Z
body: ![peanutpiper-bmp-err](https://github.com/user-attachments/assets/ee0ce5fb-efb9-4853-9e0a-85caea85da5a)
Currently failing with this error
author_association: OWNER
user: login: dontworrybhappy
created_at: 2025-05-16T02:02:23Z
body: > ![peanutpiper-bmp-err](https://private-user-images.githubusercontent.com/44412046/444307798-ee0ce5fb-efb9-4853-9e0a-85caea85da5a.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDczNjEwNjksIm5iZiI6MTc0NzM2MDc2OSwicGF0aCI6Ii80NDQxMjA0Ni80NDQzMDc3OTgtZWUwY2U1ZmItZWZiOS00ODUzLTllMGEtODVjYWVhODVkYTVhLkpQRz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTE2VDAxNTkyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI3NGNmMWMyZTcxNmEyODYzNDExOWMwNThhYThhODEzNzBlZTdmYjE1YzM2YzYxOGU2MjgyZDEwYzk0N2M5MmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.O9rgbtHo6PUbN4X8sa9z_ODLjkh1QungmVkNyLkkiME) Currently failing with this error

Try removing “Peanut-Piper-Game/“ from the file path string. I suspect it’s because you are currently already in that directory so the path needs to only be “src/PeanutPiper.bmp”
author_association: COLLABORATOR
user: login: alecwatersmusic
created_at: 2025-05-18T02:54:37Z
body: > > ![peanutpiper-bmp-err](https://private-user-images.githubusercontent.com/44412046/444307798-ee0ce5fb-efb9-4853-9e0a-85caea85da5a.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDczNjEwNjksIm5iZiI6MTc0NzM2MDc2OSwicGF0aCI6Ii80NDQxMjA0Ni80NDQzMDc3OTgtZWUwY2U1ZmItZWZiOS00ODUzLTllMGEtODVjYWVhODVkYTVhLkpQRz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTE2VDAxNTkyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI3NGNmMWMyZTcxNmEyODYzNDExOWMwNThhYThhODEzNzBlZTdmYjE1YzM2YzYxOGU2MjgyZDEwYzk0N2M5MmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.O9rgbtHo6PUbN4X8sa9z_ODLjkh1QungmVkNyLkkiME) Currently failing with this error
> 
> Try removing “Peanut-Piper-Game/“ from the file path string. I suspect it’s because you are currently already in that directory so the path needs to only be “src/PeanutPiper.bmp”

That resolved it! Thank you 👍 
author_association: OWNER