Exemple #1
0
	def draw(self,screen):
		#gfxdraw.pixel(screen, self.x, self.y, planetfillcolors[self.team])
		coords=[int(element) for tupl in self.graphic for element in tupl]
		coords=map(int,map(sum,zip(coords,(self.x,self.y)*3)))

		coords.append(planetfillcolors[self.team])
		gfxdraw.aatrigon(screen,*coords)
Exemple #2
0
def draw_aa(screen, p, color):
    try:
        gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0],
                          p[2][1], color)
    except:
        print("points", p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1])
        print(color)
    gfx.aatrigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1],
                 color)
Exemple #3
0
 def __createImage__(self):
     self.imageO.fill((0, 0, 0, 0))
     x1, y1 = map(lambda x: int(round(x)),
                  carte_plus_polar(Ship.RADIUS, Ship.RADIUS,
                                   Ship.RADIUS, Ship.BACK_ANGLE))
     x2, y2 = map(lambda x: int(round(x)),
                  carte_plus_polar(Ship.RADIUS, Ship.RADIUS,
                                   Ship.RADIUS, - Ship.BACK_ANGLE))
     x3, y3 = 2 * Ship.RADIUS, Ship.RADIUS
     gfx.aatrigon(self.imageO, x1, y1, x2, y2, x3, y3, self.color)
Exemple #4
0
 def draw(self):
     gfxdraw.filled_trigon(screen,
                      self.trigonPointLeftX,self.trigonPointLeftY,
                      self.trigonPointRightX,self.trigonPointRightY,
                      self.x,self.y,
                      (0,0,0))
     gfxdraw.aatrigon(screen,
                      self.trigonPointLeftX,self.trigonPointLeftY,
                      self.trigonPointRightX,self.trigonPointRightY,
                      self.x,self.y,
                      (240,240,240))#clean this line
Exemple #5
0
def func(event):
    global light_pos
    objs.sort(key=lambda x:x.from_center.length(), reverse=True)
    screen.fill((255,255,255))
    DS = 0.2
    DA = 10
    print(pygame.event.event_name(event.type))
    if event.key == pygame.K_LEFT:
        active_obj.move(V3(-DS,0,0))
    elif event.key == pygame.K_RIGHT:
        active_obj.move(V3(DS,0,0))
    elif event.key == pygame.K_DOWN:
        active_obj.move(V3(0,-DS,0))
    elif event.key == pygame.K_UP:
        active_obj.move(V3(0,DS,0))
    elif event.key == pygame.K_m:
        active_obj.move(V3(0,0,DS))
    elif event.key == pygame.K_l:
        active_obj.move(V3(0,0,-DS))
    elif event.key == pygame.K_z:
        active_obj.rotate_around_center_z(DA)
    elif event.key == pygame.K_u:
        active_obj.rotate_around_center_z(-DA)
    elif event.key == pygame.K_x:
        active_obj.rotate_around_center_x(DA)
    elif event.key == pygame.K_c:
        active_obj.rotate_around_center_x(-DA)
    elif event.key == pygame.K_y:
        active_obj.rotate_around_center_y(DA)
    elif event.key == pygame.K_a:
        active_obj.rotate_around_center_y(-DA)
    elif event.key == pygame.K_SPACE:
##        cam.move(V3(1,0,1), objs)
        cam.rotate("y",1,objs)
    for obj in objs: #pas boucler sur objs mais sur tous les triangles de la scen!!! ==> objet scene, le concept de obj est la que pour user transfos ?
        obj.refresh()
        i = 0
        for t in obj.triangles:
            if t.c.z > 0: #c denotes the center coordinate
                p = []
                for v in t.vertices():
                    x,y = cam.project(v)
                    p.append((int(x),int(y)))
                if USE_LIGHT:
                    color = light.get_color(t)
                else:
                    color = t.color
##                print(color)
##                color = t.color
##                print(p)
                gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
                gfx.aatrigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
            i+=1
    pygame.display.flip()
Exemple #6
0
 def __createImage__(self):
     color = Team.teams[self.teamNo].color
     self.imageO.fill((0, 0, 0, 0))
     x1, y1 = map(
         lambda x: int(round(x)),
         cartePlusPolar(Ship.RADIUS, Ship.RADIUS, Ship.RADIUS,
                        Ship.BACKANGLE))
     x2, y2 = map(
         lambda x: int(round(x)),
         cartePlusPolar(Ship.RADIUS, Ship.RADIUS, Ship.RADIUS,
                        -Ship.BACKANGLE))
     x3, y3 = 2 * Ship.RADIUS, Ship.RADIUS
     gfx.aatrigon(self.imageO, x1, y1, x2, y2, x3, y3, color)
Exemple #7
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))
    def aatrigon(self, x1, y1, x2, y2, x3, y3, color):
        """アンチエイリアス処理のなされた三角形を描画します.

        Parameters
        ----------
        x1 : int
            三角形の1つめの頂点のx座標.
        y1 : int
            三角形の1つめの頂点のy座標.
        x2 : int
            三角形の2つめの頂点のx座標.
        y2 : int
            三角形の2つめの頂点のy座標.
        x3 : int
            三角形の3つめの頂点のx座標.
        y3 : int
            三角形の3つめの頂点のy座標.
        color : tuple of int
            描画に使用される色を指定します.

        """

        return gfx.aatrigon(self.pg.screen, x1, y1, x2, y2, x3, y3, color)
def create_body(color):
    original_image = Surface((16, 16), pygame.SRCALPHA)
    gfxdraw.aatrigon(original_image, 8, 0, 2, 16, 14, 16, color)
    gfxdraw.filled_trigon(original_image, 8, 0, 2, 16, 14, 16, color)
    return original_image
Exemple #10
0
def drawCat(topx, topy, width, position, surf, cat_color):
    BLACK = (0, 0, 0)
    if position == 'middle':
        ## front
        gfxdraw.aatrigon(surf, int(topx + 3 * width / 32),
                         int(topy + width / 2), int(topx + 5 * width / 32),
                         int(topy + width / 2), int(topx + 4 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32),
                              int(topy + width / 2),
                              int(topx + 5 * width / 32),
                              int(topy + width / 2),
                              int(topx + 4 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 5 * width / 32),
                         int(topy + width / 2), int(topx + 7 * width / 32),
                         int(topy + width / 2), int(topx + 6 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32),
                              int(topy + width / 2),
                              int(topx + 7 * width / 32),
                              int(topy + width / 2),
                              int(topx + 6 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        ## back
        gfxdraw.aatrigon(surf, int(topx + 25 * width / 32),
                         int(topy + width / 2), int(topx + 23 * width / 32),
                         int(topy + width / 2), int(topx + 24 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32),
                              int(topy + width / 2),
                              int(topx + 23 * width / 32),
                              int(topy + width / 2),
                              int(topx + 24 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 23 * width / 32),
                         int(topy + width / 2), int(topx + 21 * width / 32),
                         int(topy + width / 2), int(topx + 22 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32),
                              int(topy + width / 2),
                              int(topx + 21 * width / 32),
                              int(topy + width / 2),
                              int(topx + 22 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
    elif position == 'out':
        ## front
        gfxdraw.aatrigon(surf, int(topx + 3 * width / 32),
                         int(topy + width / 2), int(topx + 5 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 1 * width / 32), int(topy + 7 * width / 8),
                         cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32),
                              int(topy + width / 2),
                              int(topx + 5 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 1 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 5 * width / 32),
                         int(topy + width / 2), int(topx + 7 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 3 * width / 32), int(topy + 7 * width / 8),
                         cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32),
                              int(topy + width / 2),
                              int(topx + 7 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 3 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        ## back
        gfxdraw.aatrigon(surf, int(topx + 25 * width / 32),
                         int(topy + width / 2), int(topx + 23 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 27 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32),
                              int(topy + width / 2),
                              int(topx + 23 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 27 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 23 * width / 32),
                         int(topy + width / 2), int(topx + 21 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 25 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32),
                              int(topy + width / 2),
                              int(topx + 21 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 25 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
    elif position == "in":
        ## front
        gfxdraw.aatrigon(surf, int(topx + 3 * width / 32),
                         int(topy + width / 2), int(topx + 5 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 7 * width / 32), int(topy + 7 * width / 8),
                         cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 3 * width / 32),
                              int(topy + width / 2),
                              int(topx + 5 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 7 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 5 * width / 32),
                         int(topy + width / 2), int(topx + 7 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 9 * width / 32), int(topy + 7 * width / 8),
                         cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 5 * width / 32),
                              int(topy + width / 2),
                              int(topx + 7 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 9 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        ## back
        gfxdraw.aatrigon(surf, int(topx + 25 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 23 * width / 32), int(topy + width / 2),
                         int(topx + 21 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 25 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 23 * width / 32),
                              int(topy + width / 2),
                              int(topx + 21 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
        gfxdraw.aatrigon(surf, int(topx + 23 * width / 32),
                         int(topy + 7 * width / 16),
                         int(topx + 21 * width / 32), int(topy + width / 2),
                         int(topx + 19 * width / 32),
                         int(topy + 7 * width / 8), cat_color)
        gfxdraw.filled_trigon(surf, int(topx + 23 * width / 32),
                              int(topy + 7 * width / 16),
                              int(topx + 21 * width / 32),
                              int(topy + width / 2),
                              int(topx + 19 * width / 32),
                              int(topy + 7 * width / 8), cat_color)
    # draw the body of the cat
    pygame.draw.ellipse(surf, cat_color,
                        (int(topx + width / 16), int(topy + width / 4),
                         int(3 * width / 4), int(width / 2)))
    # pygame.draw.ellipse(surf, BLACK,
    #                     (int(topx + width/16), int(topy + width/4),
    #                      int(3*width/4), int(width/2)), 5)
    # draw the ears of the cat
    pygame.draw.aalines(surf, cat_color, False,
                        ((int(topx + 7 * width / 12), int(topy + width / 4)),
                         (int(topx + 8 * width / 12), int(topy)),
                         (int(topx + 9 * width / 12), int(topy + width / 4))))
    pygame.draw.aalines(surf, cat_color, False,
                        ((int(topx + 9 * width / 12), int(topy + width / 4)),
                         (int(topx + 10 * width / 12), int(topy)),
                         (int(topx + 11 * width / 12), int(topy + width / 4))))
    # draw the head of the cat
    gfxdraw.filled_circle(surf, int(topx + 3 * width / 4),
                          int(topy + width / 4), int(width / 6), cat_color)
    gfxdraw.aacircle(surf, int(topx + 3 * width / 4), int(topy + width / 4),
                     int(width / 6), cat_color)
    # draw the eyes of the cat
    pygame.draw.ellipse(surf, BLACK,
                        (int(topx + 5.2 * width / 8), int(topy + width / 8),
                         int(width / 10), int(width / 12)))
    pygame.draw.ellipse(surf, BLACK,
                        (int(topx + 6.2 * width / 8), int(topy + width / 8),
                         int(width / 10), int(width / 12)))
Exemple #11
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))
Exemple #12
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))