13. Pygame Flashcards

1
Q

infinity loop

A
while run:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
        pygame.quit()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

get keyboard (constantly)

A

keys_pressed = pygame.key.get_pressed()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

get keyboard (one time press)

A

if event.type == pygame.KEYDOWN:

if event.key == pygame.K_LCTRL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

clock to set FPS

A

clock = pygame.time.Clock()

clock.tick(FPS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Rectangle

A

1) create object:
yellow = pygame.Rect(pos.x, pox.y, width, height)
x = to right
y = to down

2)
pygame. draw.rect(surface, BLACK, yellow (object))

or

pygame.draw.rect(WIN, BLACK, (WIDTH//2, 0, 10, WIDTH))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

blit

A

surface method

WIN.blit(RED_SPACESHIP, (pos.x, pos.y))

WIN.blit(yellow_health_text,(10,10))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

image

A

pygame. image.load

pygame. transform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Text

A

initialize -> set font -> render
pygame.font.init()
HEALTH_FONT = pygame.font.SysFont(‘comicsans’, 40)
draw_text = WINNER_FONT.render(text, 1, WHITE)
WIN.blit(yellow_health_text,(10,10))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Surface

A

WIN = pygame.display.set_mode((WIDTH, HEIGHT))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

User event

A
YELLOW_HIT = pygame.USEREVENT + 1
RED_HIT = pygame.USEREVENT + 2

pygame.event.post(pygame.event.Event(RED_HIT))

if event.type == RED_HIT:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

update display

A

pygame.display.update()

WIN.fill(WHITE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

pygame.?

A
.display.set_mode
.image.load
.font.SysFont
.transform
.time
.event
.Rect
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

pygame direction

A

(x,y) x to the right, y to down

always x then y, and start at left upper corner which is 0,0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly