Python Forum
use the print function in pygame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use the print function in pygame
#5
Below is the full code that prints the grid:

# Draw the grid
for row in range(0,3,1):
    for column in range(0,3,1):
        color = WHITE
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

        if x+WIDTH > mouse[0] > x and y+HEIGHT > mouse[1] > y:
            if click[0] == 1:
                print("clicked")
for row in range(0,3,1):
    for column in range(3,6,1):
        color = GREEN
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN

        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

for row in range(0,3,1):
    for column in range(6,9,1):
        color = BLUE
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

for row in range(3,6,1):
    for column in range(0,3,1):
        color = GREEN
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

for row in range(3,6,1):
    for column in range(3,6,1):
        color = BLUE
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN

        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])
for row in range(3,6,1):
    for column in range(6,9,1):
        color = WHITE
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])


for row in range(6,9,1):
    for column in range(0,3,1):
        color = BLUE
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

for row in range(6,9,1):
    for column in range(3,6,1):
        color = WHITE
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])


for row in range(6,9,1):
    for column in range(6,9,1):
        color = GREEN
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        x = (MARGIN + WIDTH) * column + MARGIN
        y = (MARGIN + HEIGHT) * row + MARGIN
        pygame.draw.rect(screen,
                         color,
                         [x,
                          y,
                          WIDTH,
                          HEIGHT])

# Limit to 60 frames per second
clock.tick(60)

# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
OUTPUT:
Grid Output
Reply


Messages In This Thread
use the print function in pygame - by rwahdan - Jul-07-2019, 05:14 AM
RE: use the print function in pygame - by metulburr - Jul-07-2019, 12:13 PM
RE: use the print function in pygame - by rwahdan - Jul-07-2019, 03:58 PM
RE: use the print function in pygame - by metulburr - Jul-07-2019, 04:01 PM
RE: use the print function in pygame - by rwahdan - Jul-07-2019, 04:15 PM
RE: use the print function in pygame - by metulburr - Jul-07-2019, 04:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] pygame, help with making a function to detect collision between player and enemy. Kris1996 3 3,393 Mar-07-2020, 12:32 PM
Last Post: Kris1996
  [PyGame] pygame.draw.rect function stretches across the screen instead of moving BubblesTheGiraffe 2 3,712 Jun-11-2019, 08:32 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020