""" CSCI146 Program Assignment 7 Name: [, ] Section: Creativity: """ import pygame # Constants to determine the size of the screen SCREEN_WIDTH = 500 SCREEN_HEIGHT = 500 # Number of clams to draw at the beginning of the game (or when regenerating) NUM_CLAMS = 10 # Amount the player should move with each key press STEP = 50 # Frames-per-second for the game FPS = 60 class Entity(): """Base class for all game entities You should not ever explicitly create an Entity object, only its child classes should be instantiated. Public instance variables: None Private instance variables: rect: A pygame.Rect that describes the location and size of the entity """ def __init__(self, x, y, width, height): """Initialize an Entity Args: x: Initial x position for entity y: Initial y position for entity width: Width of entity's rectangle height: Height of entity's rectangle """ self.rect = pygame.Rect(x, y, width, height) def get_x(self): """Return the current x-coordinate""" return self.rect.x def set_x(self, value): """Set the x-coordinate to value""" self.rect.x = value def shift_x(self, shift): """Shift the x-coordinate by shift (positively or negatively)""" self.rect.x += shift def get_y(self): """Return the current y-coordinate""" return self.rect.y def set_y(self, value): """Set the y-coordinate to value""" self.rect.y = value def shift_y(self, shift): """Shift the y-coordinate by shift (positively or negatively)""" self.rect.y += shift def play_game(max_time): """Main game function for Piper's adventure Args: max_time: Number of seconds to play for """ # Initialize the pygame engine pygame.init() pygame.font.init() font = pygame.font.SysFont('Arial',14) clock = pygame.time.Clock() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Piper's adventures") # Initialize Player, Wave and Clams time = 0 score = 0 # Main game loop while time < max_time: # Obtain any user inputs event = pygame.event.poll() if event.type == pygame.QUIT: break # Screen origin (0, 0) is the upper-left if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: pass elif event.key == pygame.K_LEFT: pass elif event.key == pygame.K_UP: pass elif event.key == pygame.K_DOWN: pass # Determine if Piper gathered more clams # Update the position of the wave # When the wave has reached its peak create new clams # If the piper touched the wave the game is over... # Draw all of the game elements screen.fill([255,255,255]) # Render the current time and score text = font.render('Time = ' + str(round(max_time-time, 1)), True, (0, 0, 0)) screen.blit(text, (10, 0.95*SCREEN_HEIGHT)) text = font.render('Score = ' + str(score), True, (0, 0, 0)) screen.blit(text, (10, 0.90*SCREEN_HEIGHT)) # Render next frame pygame.display.update() clock.tick(FPS) # Update game time by advancing time for each frame time += 1.0/FPS print('Game over!') print('Score =', score) pygame.display.quit() pygame.quit() if __name__ == "__main__": play_game(30)