Another study guide Flashcards

(43 cards)

1
Q

What is the screen variable and what does it represent?

A

The window

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

How do you check if the user wants to close the window?

A

for event in pygame.event.get():
if event.type == pygame.QUIT:
return False

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

What are the three primary tasks that make up the game loop?

A

Process input, update, draw

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

What is the purpose of calling process_input(), update(), and draw() separately in the game loop?

A

To make sure to condense the code/ more readable and that everything happens in the right order

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

What does the statement pygame.display.flip() do? (Comment it out and see what happens.)

A

It draws everything onto the screen

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

What is the purpose of the Clock() and what does the statement clock.tick(FPS) do?

A

If you didn’t have it, each function would move fast, clock.tick(fps) makes it draw the screen how many times per second

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

What is the value for FPS in the my_house.py program? What does FPS represent?

A

FPS = 60. FPS represents how many frames run per second

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

What is the purpose of if __name__ == “__main__”: in this program?

A

It makes it that certain code only runs when the script is executed directly, not when it’s imported as a module into another script

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

Why are assets such as images, fonts, and sounds loaded prior to starting the game loop?

A

It prevents potential performance issues from loading the things into the game loop itself.

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

Describe the coordinate system used in Pygame.

A

It is a typical coordinate plane with (0, 0) located in the top left of the screen

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

Is it possible to draw elements at negative coordinates? Why might you want to do this?

A

It is indeed possible to do that. People might want to do this because it handles shapes with parts off screen.

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

What is the title bar of an application window? Which line of code sets the text you see in the title bar?

A

The title bar is the bar at the top of a window that displays the app’s name. The line of code needed is pygame.display.set_caption(“CAPTION”)

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

How are colors defined in Pygame?

A

RGB

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

Without using a color picker, how could you make a bright red? A dark green? Black? White? Light gray? Dark gray?

A

If you want that color put all of that color (ex. Red (255, 0, 0))
Dark gray (169, 169, 169).
light gray(50, 50, 50)
white(all 0)
Black(all 255)

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

What are the minimum and maximum values that can be used in an RGB tuple? What happens if you try to use a value outside of this range? (Test and see.)

A

Minimum = 0, maximum = 255. If you put 256 or above and/or if you put -1 or below, it will turn black

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

How do you fill the screen with a color?

A

screen.fill

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

What Pygame functions are used to draw shapes (rectangles, ellipses, polygons, and lines)?

A

pygame.draw.SHAPE(screen.COLOR[Coords], [coords] linewidth)

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

Explain how we define the location and size of a rectangle used in a pygame drawing function.

A

Top left coord with height

19
Q

How do you draw a circle using the draw.ellipse function?

A

You make the width and height equal

20
Q

How do you draw filled in shapes? How do you just draw the outline of a shape?

A

To make filled in shapes, don’t fill in the line width or make the line width 0 and to make just the outline, make the line width 1 or more

21
Q

How is the order in which Pygame elements are drawn determined?

A

In the order they are in the code

22
Q

When you blit an image on the screen, what location on the image do the [x, y] values represent?

A

Top left corner

23
Q

Why does the draw_tree function take x and y arguments?

A

For positioning purposes

24
Q

Why do some functions not take any arguments?

A

Not all functions need it

25
Why does the program use multiple draw_ helper functions such as draw_sun, draw_house, and draw_grass instead of just putting all drawing code in the main draw() function?
Organization, easier for debugging/reading
26
Why are the star locations generated before the game loop begins?
So that the stars aren't constantly reset
27
What function is responsible for detecting and processing user input?
The process_input function
28
What is an "event" in Pygame?
anything
29
What events does this program detect? What happens as a result of these events?
Quit, K_t, K_l, K_m
30
Why does the process_input function return either True or False every frame?
You want to be able to close the game loop if using any other variable
31
Why did we decide to handle movement of the cat using pygame.key.get_pressed() rather than from within the event loop?
Instead of spamming the key you can hold it
32
What kind of tasks typically belong in the update() function of a game?
Movement stuff
33
How is the cat's movement restricted?
By the check_cat_location function
34
How is the owl's movement restricted?
It moves (x) 3, if offscreen, goes back to a random point
35
Explain what each line in the move_clouds function does.
Moves from right to left,if cloud is off screen sets a random point for the thing to spawn back in
36
What happens if you forget to call pygame.quit() at the end of a program? (Comment out this line in the game_loop and see what effect it has.)
It will run forever
37
What happens if you misspell a file name for an image in your code? What error message do you get?
The image wont show up, it is a type error
38
Suppose you saw the error message "TypeError: draw_cat() missing 2 required positional arguments: 'x' and 'y'". What does this most likely mean?
That you need the x and y coords
39
What would you change to make the animation larger?
Change the maximum x and y coords that it is higher
40
How could you modify the code so that the clouds are also visible at night? Suppose you wanted to make the grass a darker green at night. How would you modify the RGB value for GREEN that is used in the program?
Remove the clouds from the if part In order to make it a darker green decrease the values of all colors but add more blue
41
Suppose you wanted to modify the distance between fence posts in draw_fence. What could you change to make the posts closer together? How would you make them further apart?
Make the 30 into bigger number farther away and make the 30 into a smaller number closer together
42
The owl currently moves from left to right. How could you make it move from right to left? How could you make the owl fly faster or slower?
Change to a negative number. Faster bigger number slower smaller number
43
How could you make the sun automatically set? Could you make it automatically turn to night when the sun gets below the horizon.
apparently already does that