How to use the pygame.draw.rect function in pygame

To help you get started, we’ve selected a few pygame examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KenT2 / python-games / inkspill.py View on Github external
def drawColorSchemeBoxes(x, y, schemeNum):
    # Draws the color scheme boxes that appear on the "Settings" screen.
    for boxy in range(2):
        for boxx in range(3):
            pygame.draw.rect(DISPLAYSURF, COLORSCHEMES[schemeNum][3 * boxy + boxx + 1], (x + MEDIUMBOXSIZE * boxx, y + MEDIUMBOXSIZE * boxy, MEDIUMBOXSIZE, MEDIUMBOXSIZE))
            if paletteColors == COLORSCHEMES[schemeNum][1:]:
                # put the ink spot next to the selected color scheme
                DISPLAYSURF.blit(SPOTIMAGE, (x - 50, y))
github anzev / mingus / mingus_examples / pygame-drum / pygame-drum.py View on Github external
print "Couldn't load soundfont", SF2
	sys.exit(1)


# Initialize pygame and load 'pad.png'
pygame.init()
screen = pygame.display.set_mode((610,500))
pad, pad_rect = load_img("pad.png")

hit = pygame.Surface(pad_rect.size) # Used to display which pad was hit


# Draw track representation basis - a rectangle divided in 9 horizontal pieces
track=pygame.Surface((610, 45))
track.fill((0,0,0))
pygame.draw.rect(track, (255,0,0), track.get_rect(), 1)
for y in range(1, 9):
	pygame.draw.line(track, (255,0,0), (0, y * 5), (610, y * 5), 1)


pygame.display.set_caption("mingus drum")


def play_note(note):
	"""play_note determines which pad was 'hit' and send the 
	play request to fluidsynth"""

	index = None
	if note == Note("B", 2):
		index = 0
	elif note == Note("A", 2):
		index = 1
github buckyroberts / Source-Code-from-Tutorials / Pygame / 57_PythonGameDevelopment.py View on Github external
def button(text, x, y, width, height, inactive_color, active_color, action = None):
    cur = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    #print(click)
    if x + width > cur[0] > x and y + height > cur[1] > y:
        pygame.draw.rect(gameDisplay, active_color, (x,y,width,height))
        if click[0] == 1 and action != None:
            if action == "quit":
                pygame.quit()
                quit()

            if action == "controls":
                game_controls()

            if action == "play":
                gameLoop()

            if action == "main":
                game_intro()
            
    else:
        pygame.draw.rect(gameDisplay, inactive_color, (x,y,width,height))
github carla-simulator / scenario_runner / manual_control.py View on Github external
pygame.draw.lines(display, (255, 136, 0), False, points, 2)
                    item = None
                    v_offset += 18
                elif isinstance(item, tuple):
                    if isinstance(item[1], bool):
                        rect = pygame.Rect((bar_h_offset, v_offset + 8), (6, 6))
                        pygame.draw.rect(display, (255, 255, 255), rect, 0 if item[1] else 1)
                    else:
                        rect_border = pygame.Rect((bar_h_offset, v_offset + 8), (bar_width, 6))
                        pygame.draw.rect(display, (255, 255, 255), rect_border, 1)
                        f = (item[1] - item[2]) / (item[3] - item[2])
                        if item[2] < 0.0:
                            rect = pygame.Rect((bar_h_offset + f * (bar_width - 6), v_offset + 8), (6, 6))
                        else:
                            rect = pygame.Rect((bar_h_offset, v_offset + 8), (f * bar_width, 6))
                        pygame.draw.rect(display, (255, 255, 255), rect)
                    item = item[0]
                if item: # At this point has to be a str.
                    surface = self._font_mono.render(item, True, (255, 255, 255))
                    display.blit(surface, (8, v_offset))
                v_offset += 18
        self._notifications.render(display)
        self.help.render(display)
github buckyroberts / Source-Code-from-Tutorials / Pygame / 84_PythonGameDevelopment.py View on Github external
y = int(y)


    possibleTurrets = [(x+27, y-2),
                       (x+26, y-5),
                       (x+25, y-8),
                       (x+23, y-12),
                       (x+20, y-14),
                       (x+18, y-15),
                       (x+15, y-17),
                       (x+13, y-19),
                       (x+11, y-21)
                       ]
  
    pygame.draw.circle(gameDisplay, black, (x,y), int(tankHeight/2))
    pygame.draw.rect(gameDisplay, black, (x-tankHeight, y, tankWidth, tankHeight))

    pygame.draw.line(gameDisplay, black, (x,y), possibleTurrets[turPos], turretWidth)

    pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
       

    pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x-5, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x+5, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x+10, y+20), wheelWidth)
    pygame.draw.circle(gameDisplay, black, (x+15, y+20), wheelWidth)

    return possibleTurrets[turPos]
github ktt3ja / kttetris / tetris.py View on Github external
def draw_blocks(self, array2d, color=(0,0,255), dx=0, dy=0):
        for y, row in enumerate(array2d):
            y += dy
            if y >= 2 and y < self.height:
                for x, block in enumerate(row):
                    if block:
                        x += dx
                        x_pix, y_pix = self.pos_to_pixel(x, y)
                        # draw block
                        pygame.draw.rect(self.screen, color,
                                         (  x_pix, y_pix,
                                            self.block_size,
                                            self.block_size))
                        # draw border
                        pygame.draw.rect(self.screen, (0, 0, 0),
                                         (  x_pix, y_pix,
                                            self.block_size,
                                            self.block_size), 1)
github kidscancode / gamedev / tutorials / shmup / shmup-14.py View on Github external
def draw_shield_bar(surf, x, y, pct):
    if pct < 0:
        pct = 0
    BAR_LENGTH = 100
    BAR_HEIGHT = 10
    fill = (pct / 100) * BAR_LENGTH
    outline_rect = pygame.Rect(x, y, BAR_LENGTH, BAR_HEIGHT)
    fill_rect = pygame.Rect(x, y, fill, BAR_HEIGHT)
    pygame.draw.rect(surf, GREEN, fill_rect)
    pygame.draw.rect(surf, WHITE, outline_rect, 2)
github nathanrw / nuklear-cffi / pynk / nkpygame.py View on Github external
c = ffi.cast("struct nk_command_scissor*", nuklear_command)
                rect = pygame.Rect(c.x, c.y, c.w, c.h)
                screen.set_clip(rect)
            elif nuklear_command.type == lib.NK_COMMAND_LINE:
                c = ffi.cast("struct nk_command_line*", nuklear_command)
                pygame.draw.line(screen, 
                                 (c.color.r, c.color.g, c.color.b), 
                                 (c.begin.x, c.begin.y),
                                 (c.end.x, c.end.y),
                                 c.line_thickness)
            elif nuklear_command.type == lib.NK_COMMAND_RECT:
                c = ffi.cast("struct nk_command_rect*", nuklear_command)
                rect = pygame.Rect(c.x, c.y, c.w, c.h)
                colour = (c.color.r, c.color.g, c.color.b)
                # c.rounding - unsupported.
                pygame.draw.rect(screen, colour, rect, c.line_thickness)
            elif nuklear_command.type == lib.NK_COMMAND_RECT_FILLED:
                c = ffi.cast("struct nk_command_rect_filled*", nuklear_command)
                rect = pygame.Rect(c.x, c.y, c.w, c.h)
                colour = (c.color.r, c.color.g, c.color.b)
                # c.rounding - unsupported.
                pygame.draw.rect(screen, colour, rect, 0)
            elif nuklear_command.type == lib.NK_COMMAND_CIRCLE:
                c = ffi.cast("struct nk_command_circle*", nuklear_command)
                rect = pygame.Rect(c.x, c.y, c.w, c.h)
                colour = (c.color.r, c.color.g, c.color.b)
                pygame.draw.ellipse(screen, colour, rect, c.line_thickness)
            elif nuklear_command.type == lib.NK_COMMAND_CIRCLE_FILLED:
                c = ffi.cast("struct nk_command_circle_filled*", nuklear_command)
                rect = pygame.Rect(c.x, c.y, c.w, c.h)
                colour = (c.color.r, c.color.g, c.color.b)
                pygame.draw.ellipse(screen, colour, rect, 0)
github AndrewKLeech / Pip-Boy / Game.py View on Github external
# Player health
           if playerHealth > 50:
               playerColour = lightGreen
           else:
               playerColour = green

           # Enemy health
           if enemyHealth > 50:
               enemyColour = lightGreen
           else:
               enemyColour = green

           # Draw the health bars
           pygame.draw.rect(gameDisplay, playerColour, (pX - 100, display_height * .7, playerHealth, 10))
           pygame.draw.rect(gameDisplay, enemyColour, (eX, display_height * .7, enemyHealth, 10))
github buckyroberts / Source-Code-from-Tutorials / Pygame / 73_PythonGameDevelopment.py View on Github external
def barrier(xlocation,randomHeight, barrier_width):
    
    pygame.draw.rect(gameDisplay, black, [xlocation, display_height-randomHeight, barrier_width,randomHeight])