Beispiel #1
0
 def on_draw(self, screen):
     # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new
     # frame
     self.director.screen.fill((0, 0, 0))
     # Calls the draw_grid function
     self.draw_grid(screen)
     # Calls the apple Entity's draw function
     self.apple.draw(screen)
     # Calls the head Entity's draw function
     self.head.draw(screen)
     # Calls the print_tail function
     self.print_tail(screen)
     # This conditional statement is executed if the gameOver boolean has been set to true
     if self.gameOver:
         # The text "Game Over" is printed to the middle of the screen
         screen.blit(self.text,
                     self.text.get_rect(center=self.screen_rect.center))
         # draws a round rectangle to the top left corner of the screen
         rrect(
             screen, (255, 255, 255),
             pygame.Rect(0 * self.director.scale, 0 * self.director.scale,
                         63 * self.director.scale,
                         30 * self.director.scale), 9 * self.director.scale,
             3 * self.director.scale)
         # Prints the text to the screen at the specified coordinates
         screen.blit(self.txt,
                     (25 * self.director.scale, 7 * self.director.scale))
         #Draws a filled triangle to the screen with the points being at the specified coordinates
         gfxdraw.filled_trigon(screen, 5 * self.director.scale,
                               15 * self.director.scale,
                               20 * self.director.scale,
                               22 * self.director.scale,
                               20 * self.director.scale,
                               8 * self.director.scale, (255, 150, 44))
         #Draws an anti-aliased triangle outline with the points being at the specified coordinates
         gfxdraw.aatrigon(screen, 5 * self.director.scale,
                          15 * self.director.scale,
                          20 * self.director.scale,
                          22 * self.director.scale,
                          20 * self.director.scale, 8 * self.director.scale,
                          (255, 150, 44))
Beispiel #2
0
    def on_draw(self, screen):
        # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new
        # frame
        screen.fill((0, 0, 0))

        # Player One Config
        # A surface is created with the text "Player One Controls" printed on it
        self.txt = self.plyr.render("Player One Controls", True,
                                    (255, 255, 255))
        # Prints the text to the game window at the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=self.screen_rect.centerx,
                              centery=19 * self.director.scale))
        # A surface is created with the text "Player Two Controls" printed on it
        self.txt = self.plyr.render("Player Two Controls", True,
                                    (255, 255, 255))
        # Prints the text to the game window at the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=self.screen_rect.centerx,
                              centery=149 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(47 * self.director.scale, 34 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Creates a surface with the letter W printed on it
        self.txt = self.ctrl.render("W", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=47 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 25 * self.director.scale))
        # Creates a surface with the word "up" on it
        self.txt = self.plyr.render("up", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=47 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(133 * self.director.scale, 34 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Creates a surface with the letter A printed on it
        self.txt = self.ctrl.render("A", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=133 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 25 * self.director.scale))
        # Creates a surface with the word "left" on it
        self.txt = self.plyr.render("left", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=133 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(219 * self.director.scale, 34 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Creates a surface with the letter S printed on it
        self.txt = self.ctrl.render("S", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=219 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 25 * self.director.scale))
        # Creates a surface with the word "down" on it
        self.txt = self.plyr.render("down", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=219 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(305 * self.director.scale, 34 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Creates a surface with the letter D printed on it
        self.txt = self.ctrl.render("D", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=305 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 25 * self.director.scale))
        # Creates a surface with the word "right" on it
        self.txt = self.plyr.render("right", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=305 * self.director.scale + 25 * self.director.scale,
                centery=34 * self.director.scale + 65 * self.director.scale))

        # Player Two Config
        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(47 * self.director.scale, 164 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Draws a filled triangle to the screen using the specified points
        gfxdraw.filled_trigon(screen, 72 * self.director.scale,
                              176 * self.director.scale,
                              86 * self.director.scale,
                              204 * self.director.scale,
                              58 * self.director.scale,
                              204 * self.director.scale, (255, 255, 255))
        # Draws an outline of an anti-aliased triangle using the specified points
        gfxdraw.aatrigon(screen, 72 * self.director.scale,
                         176 * self.director.scale, 86 * self.director.scale,
                         204 * self.director.scale, 58 * self.director.scale,
                         204 * self.director.scale, (255, 255, 255))
        # Creates a surface with the word "up" printed on it
        self.txt = self.plyr.render("up", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=47 * self.director.scale + 25 * self.director.scale,
                centery=164 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(133 * self.director.scale, 164 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Draws a filled triangle to the screen using the specified points
        gfxdraw.filled_trigon(screen, 144 * self.director.scale,
                              189 * self.director.scale,
                              172 * self.director.scale,
                              175 * self.director.scale,
                              172 * self.director.scale,
                              203 * self.director.scale, (255, 255, 255))
        # Draws an outline of an anti-aliased triangle using the specified points
        gfxdraw.aatrigon(screen, 144 * self.director.scale,
                         189 * self.director.scale, 172 * self.director.scale,
                         175 * self.director.scale, 172 * self.director.scale,
                         203 * self.director.scale, (255, 255, 255))
        # Creates a surface with the word "left" printed on it
        self.txt = self.plyr.render("left", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=133 * self.director.scale + 25 * self.director.scale,
                centery=164 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(219 * self.director.scale, 164 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Draws a filled triangle to the screen using the specified points
        gfxdraw.filled_trigon(screen, 244 * self.director.scale,
                              204 * self.director.scale,
                              258 * self.director.scale,
                              176 * self.director.scale,
                              230 * self.director.scale,
                              176 * self.director.scale, (255, 255, 255))
        # Draws an outline of an anti-aliased triangle using the specified points
        gfxdraw.aatrigon(screen, 244 * self.director.scale,
                         204 * self.director.scale, 258 * self.director.scale,
                         176 * self.director.scale, 230 * self.director.scale,
                         176 * self.director.scale, (255, 255, 255))
        # Creates a surface with the word "left" printed on it
        self.txt = self.plyr.render("down", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=219 * self.director.scale + 25 * self.director.scale,
                centery=164 * self.director.scale + 65 * self.director.scale))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(305 * self.director.scale, 164 * self.director.scale,
                        51 * self.director.scale, 51 * self.director.scale),
            12 * self.director.scale, 3 * self.director.scale)
        # Draws a filled triangle to the screen using the specified points
        gfxdraw.filled_trigon(screen, 344 * self.director.scale,
                              189 * self.director.scale,
                              316 * self.director.scale,
                              175 * self.director.scale,
                              316 * self.director.scale,
                              203 * self.director.scale, (255, 255, 255))
        # Draws an outline of an anti-aliased triangle using the specified points
        gfxdraw.aatrigon(screen, 344 * self.director.scale,
                         189 * self.director.scale, 316 * self.director.scale,
                         175 * self.director.scale, 316 * self.director.scale,
                         203 * self.director.scale, (255, 255, 255))
        # Creates a surface with the word "right" printed on it
        self.txt = self.plyr.render("right", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(
                centerx=305 * self.director.scale + 25 * self.director.scale,
                centery=164 * self.director.scale + 65 * self.director.scale))

        # Creates a surface with the word "p1" printed on it
        self.txt = self.p.render("p1", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=self.screen_rect.right / 3,
                              centery=self.screen_rect.bottom -
                              116 * self.director.scale))

        # Creates a surface with the word "p2" printed on it
        self.txt = self.p.render("p2", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=self.screen_rect.right * (2 / 3),
                              centery=self.screen_rect.bottom -
                              116 * self.director.scale))

        # Draws anti-aliased lines to the screen using the coordinates given by drawpnts_one
        pygame.draw.aalines(screen, (255, 255, 255), False, self.drawpnts_one)
        # Draws anti-aliased lines to the screen using the coordinates given by drawpnts_two
        pygame.draw.aalines(screen, (255, 255, 255), False, self.drawpnts_two)
        # Draws the particle system
        self.particle_system.draw(screen)

        # Creates a surface with the name of the color printed on it using the color associated with that name
        self.txt = self.colortxt.render(
            self.color_name[self.director.index_one], True,
            self.color_rgb[self.director.index_one])
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=133 * self.director.scale,
                              centery=373 * self.director.scale))

        # Creates a surface with the name of the color printed on it using the color associated with that name
        self.txt = self.colortxt.render(
            self.color_name[self.director.index_two], True,
            self.color_rgb[self.director.index_two])
        # Prints the text to the game window a the specified coordinates
        screen.blit(
            self.txt,
            self.txt.get_rect(centerx=267 * self.director.scale,
                              centery=373 * self.director.scale))

        # This conditional statement says that if p1_hili_l_arrow is set to true then draw the enlarged version of the
        # triangle. Otherwise, draw the regular version
        if self.p1_hili_l_arrow:
            gfxdraw.filled_trigon(screen, 94 * self.director.scale,
                                  363 * self.director.scale,
                                  94 * self.director.scale,
                                  383 * self.director.scale,
                                  74 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 94 * self.director.scale,
                             363 * self.director.scale,
                             94 * self.director.scale,
                             383 * self.director.scale,
                             74 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))
        else:
            gfxdraw.filled_trigon(screen, 91 * self.director.scale,
                                  366 * self.director.scale,
                                  91 * self.director.scale,
                                  380 * self.director.scale,
                                  77 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 91 * self.director.scale,
                             366 * self.director.scale,
                             91 * self.director.scale,
                             380 * self.director.scale,
                             77 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))

        # This conditional statement says that if p1_hili_l_arrow is set to true then draw the enlarged version of the
        # triangle. Otherwise, draw the regular version
        if self.p1_hili_r_arrow:
            gfxdraw.filled_trigon(screen, 172 * self.director.scale,
                                  363 * self.director.scale,
                                  172 * self.director.scale,
                                  383 * self.director.scale,
                                  192 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 172 * self.director.scale,
                             363 * self.director.scale,
                             172 * self.director.scale,
                             383 * self.director.scale,
                             192 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))
        else:
            gfxdraw.filled_trigon(screen, 175 * self.director.scale,
                                  366 * self.director.scale,
                                  175 * self.director.scale,
                                  380 * self.director.scale,
                                  189 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 175 * self.director.scale,
                             366 * self.director.scale,
                             175 * self.director.scale,
                             380 * self.director.scale,
                             189 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))

        # This conditional statement says that if p2_hili_l_arrow is set to true then draw the enlarged version of the
        # triangle. Otherwise, draw the regular version
        if self.p2_hili_l_arrow:
            gfxdraw.filled_trigon(screen, 228 * self.director.scale,
                                  363 * self.director.scale,
                                  228 * self.director.scale,
                                  383 * self.director.scale,
                                  209 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 228 * self.director.scale,
                             363 * self.director.scale,
                             228 * self.director.scale,
                             383 * self.director.scale,
                             209 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))
        else:
            gfxdraw.filled_trigon(screen, 225 * self.director.scale,
                                  366 * self.director.scale,
                                  225 * self.director.scale,
                                  380 * self.director.scale,
                                  211 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 225 * self.director.scale,
                             366 * self.director.scale,
                             225 * self.director.scale,
                             380 * self.director.scale,
                             211 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))

        # This conditional statement says that if p2_hili_r_arrow is set to true then draw the enlarged version of the
        # triangle. Otherwise, draw the regular version
        if self.p2_hili_r_arrow:
            gfxdraw.filled_trigon(screen, 306 * self.director.scale,
                                  363 * self.director.scale,
                                  306 * self.director.scale,
                                  383 * self.director.scale,
                                  326 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 306 * self.director.scale,
                             363 * self.director.scale,
                             306 * self.director.scale,
                             383 * self.director.scale,
                             326 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))
        else:
            gfxdraw.filled_trigon(screen, 309 * self.director.scale,
                                  366 * self.director.scale,
                                  309 * self.director.scale,
                                  380 * self.director.scale,
                                  323 * self.director.scale,
                                  373 * self.director.scale, (255, 255, 255))
            gfxdraw.aatrigon(screen, 309 * self.director.scale,
                             366 * self.director.scale,
                             309 * self.director.scale,
                             380 * self.director.scale,
                             323 * self.director.scale,
                             373 * self.director.scale, (255, 255, 255))

        # Creates a rounded rectangle with an rgb color of white at the specified coordinates
        rrect(
            screen, (255, 255, 255),
            pygame.Rect(0 * self.director.scale, 0 * self.director.scale,
                        63 * self.director.scale, 30 * self.director.scale),
            9 * self.director.scale, 3 * self.director.scale)
        # Creates a surface with the word "ctrl" printed on it
        self.txt = self.plyr.render("ctrl", True, (255, 255, 255))
        # Prints the text to the game window a the specified coordinates
        screen.blit(self.txt,
                    (25 * self.director.scale, 7 * self.director.scale))
        # Draws a filled triangle to the screen using the specified points
        gfxdraw.filled_trigon(screen, 5 * self.director.scale,
                              15 * self.director.scale,
                              20 * self.director.scale,
                              22 * self.director.scale,
                              20 * self.director.scale,
                              8 * self.director.scale, (255, 150, 44))
        # Draws an outline of an anti-aliased triangle using the specified points
        gfxdraw.aatrigon(screen, 5 * self.director.scale,
                         15 * self.director.scale, 20 * self.director.scale,
                         22 * self.director.scale, 20 * self.director.scale,
                         8 * self.director.scale, (255, 150, 44))
Beispiel #3
0
 def on_draw(self, screen):
     # Changes every pixel in the window to black. This is done to wipe the screen and set it up for drawing a new
     # frame
     self.director.screen.fill((0, 0, 0))
     # Calls the draw_grid function
     self.draw_grid(screen)
     # Calls the apple Entity's draw function
     self.apple.draw(screen)
     # Calls the head Entity's draw function
     self.head_1.draw(screen)
     # Calls the head Entity's draw function
     self.head_2.draw(screen)
     # Calls the print_tail function
     self.print_tails(screen)
     # This conditional statement executes if player one has won
     if self.plyronewins:
         # The text "Player One Wins" is printed to the middle of the screen
         screen.blit(
             self.plyronewins_txt,
             self.plyronewins_txt.get_rect(center=self.screen_rect.center))
         # Creates a surface with the text "ctrl" print on it using the plyr font
         self.txt = self.plyr.render("ctrl", True, (255, 255, 255))
         # draws a round rectangle to the top left corner of the screen
         rrect(
             screen, (255, 255, 255),
             pygame.Rect(0 * self.director.scale, 0 * self.director.scale,
                         63 * self.director.scale,
                         30 * self.director.scale), 9 * self.director.scale,
             3 * self.director.scale)
         # The text ctrl is printed in the top left corner of the screen
         screen.blit(self.txt,
                     (25 * self.director.scale, 7 * self.director.scale))
         #Draws a filled triangle to the screen with the points being at the specified coordinates
         gfxdraw.filled_trigon(screen, 5 * self.director.scale,
                               15 * self.director.scale,
                               20 * self.director.scale,
                               22 * self.director.scale,
                               20 * self.director.scale,
                               8 * self.director.scale, (255, 150, 44))
         #Draws an anti-aliased triangle outline with the points being at the specified coordinates
         gfxdraw.aatrigon(screen, 5 * self.director.scale,
                          15 * self.director.scale,
                          20 * self.director.scale,
                          22 * self.director.scale,
                          20 * self.director.scale, 8 * self.director.scale,
                          (255, 150, 44))
     #pygame.mixer.music.stop()
     # This conditional statement executes if player two has won
     if self.plyrtwowins:
         # The text "Player Two Wins" is printed to the middle of the screen
         screen.blit(
             self.plyrtwowins_txt,
             self.plyronewins_txt.get_rect(center=self.screen_rect.center))
         # Creates a surface with the text "ctrl" print on it using the plyr font
         self.txt = self.plyr.render("ctrl", True, (255, 255, 255))
         # draws a round rectangle to the top left corner of the screen
         rrect(
             screen, (255, 255, 255),
             pygame.Rect(0 * self.director.scale, 0 * self.director.scale,
                         63 * self.director.scale,
                         30 * self.director.scale), 9 * self.director.scale,
             3 * self.director.scale)
         # The text ctrl is printed in the top left corner of the screen
         screen.blit(self.txt,
                     (25 * self.director.scale, 7 * self.director.scale))
         #Draws a filled triangle to the screen with the points being at the specified coordinates
         gfxdraw.filled_trigon(screen, 5 * self.director.scale,
                               15 * self.director.scale,
                               20 * self.director.scale,
                               22 * self.director.scale,
                               20 * self.director.scale,
                               8 * self.director.scale, (255, 150, 44))
         #Draws an anti-aliased triangle outline with the points being at the specified coordinates
         gfxdraw.aatrigon(screen, 5 * self.director.scale,
                          15 * self.director.scale,
                          20 * self.director.scale,
                          22 * self.director.scale,
                          20 * self.director.scale, 8 * self.director.scale,
                          (255, 150, 44))
         #pygame.mixer.music.stop()
     #  This conditional statement executes if there has been a draw
     if self.plyrdraw:
         # Creates a surface with the text "ctrl" print on it using the plyr font
         self.txt = self.plyr.render("ctrl", True, (255, 255, 255))
         # The text "draw" is printed to the middle of the screen
         screen.blit(
             self.plyrdraw_txt,
             self.plyrdraw_txt.get_rect(center=self.screen_rect.center))
         # draws a round rectangle to the top left corner of the screen
         rrect(
             screen, (255, 255, 255),
             pygame.Rect(0 * self.director.scale, 0 * self.director.scale,
                         63 * self.director.scale,
                         30 * self.director.scale), 9 * self.director.scale,
             3 * self.director.scale)
         # The text ctrl is printed in the top left corner of the screen
         screen.blit(self.txt,
                     (25 * self.director.scale, 7 * self.director.scale))
         #Draws a filled triangle to the screen with the points being at the specified coordinates
         gfxdraw.filled_trigon(screen, 5 * self.director.scale,
                               15 * self.director.scale,
                               20 * self.director.scale,
                               22 * self.director.scale,
                               20 * self.director.scale,
                               8 * self.director.scale, (255, 150, 44))
         #Draws an anti-aliased triangle outline with the points being at the specified coordinates
         gfxdraw.aatrigon(screen, 5 * self.director.scale,
                          15 * self.director.scale,
                          20 * self.director.scale,
                          22 * self.director.scale,
                          20 * self.director.scale, 8 * self.director.scale,
                          (255, 150, 44))