Term 3 Study Guide Flashcards

0
Q

black =( 0, 0, 0)
white =(255,255,255)
red =(255,0,0)

A

Defined some colors

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

Import pygame

Import random

A

Imports needed modules

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

class Block(pygame.sprite.Sprite):

A

Creates the block class - it derives from the Sprite class in Pygame

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

def __init__(self, color, width, height):

A

Constructs the color of the block and the width and height

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

pygame.sprite.Sprite.__init__(self)

A

Calls the parent class constructor

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

self. image = pygame.Surface([width, height])

self. image.fill(color)

A

Creates and image and fills it with color

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

self.rect = self.image.get_rect()

A

Fetches the rectangle object that has the dimensions of the image

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

pygame.init()

A

Initializes pygame

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

screen_width=700
screen_height=400
screen=pygame.display.set_mode([sceen_width,screen_height])

A

Sets the width and height of the screen

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

block_list = pygame.sprite.Group()

A

This is a list of ‘spites’. Each block in the program is added to this list. The list is managed by a class called ‘Group’.

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

all_sprites_list = pygame.sprite.Group()

A

This is a list of every sprite, including all blocks as well as the player block.

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

for i in range(50):

block = Block(black,20,15)

A

Uses a loop to produce 50 blocks

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

block. rect.x = random.randrange(screen_width)

block. rect.y = random.randrange(screen_height)

A

Sets a random location for the block

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

block_list.add(block)

all_sprites_list.add(block)

A

Add the block to the list of objects

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

player = Block(red, 20, 15)

all_sprites_list.add(player)

A

Creates a red player block

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

done = False

A

Loops until the user click the close button

16
Q

clock = pygame.time.Clock()

A

Manages how fast the screen updates

17
Q

while done==False:
for event in pygame.event.get():
if event.type==pygame.QUIT:
done = true

A

This is the main program loop

18
Q

screen.fill(white)

A

Fills the screen with white

19
Q

pos = pygame.mouse.get_pos()

A

Gets the current mouse position and returns the positions as a list of two numbers

20
Q

player. rect.x = pos[0]

player. rect.x = pos[1]

A

Fetches the x and y out of the list and sets the player object to the mouse location.

21
Q

blocks_hit_list = pygame.sprite.spritecollide(player, block_list, True)

A

checks if the player is colliding with anything if so erases the block.

22
Q

for block in blocks_hit_list:
score +=1
print( score )

A

Checks the list of collisions and increases the score

23
Q

all_sprites_list.draw(screen)

A

Draws all of the sprites

24
Q

clock.tick(20)

A

Sets the clock to 20 frames per second

25
Q

pygame.display.flip()

A

Updates the screen with what is drawn

26
Q

pygame.quit()

A

Used to avoid glitches in idle