Another study guide Flashcards
(43 cards)
What is the screen variable and what does it represent?
The window
How do you check if the user wants to close the window?
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
What are the three primary tasks that make up the game loop?
Process input, update, draw
What is the purpose of calling process_input(), update(), and draw() separately in the game loop?
To make sure to condense the code/ more readable and that everything happens in the right order
What does the statement pygame.display.flip() do? (Comment it out and see what happens.)
It draws everything onto the screen
What is the purpose of the Clock() and what does the statement clock.tick(FPS) do?
If you didn’t have it, each function would move fast, clock.tick(fps) makes it draw the screen how many times per second
What is the value for FPS in the my_house.py program? What does FPS represent?
FPS = 60. FPS represents how many frames run per second
What is the purpose of if __name__ == “__main__”: in this program?
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
Why are assets such as images, fonts, and sounds loaded prior to starting the game loop?
It prevents potential performance issues from loading the things into the game loop itself.
Describe the coordinate system used in Pygame.
It is a typical coordinate plane with (0, 0) located in the top left of the screen
Is it possible to draw elements at negative coordinates? Why might you want to do this?
It is indeed possible to do that. People might want to do this because it handles shapes with parts off screen.
What is the title bar of an application window? Which line of code sets the text you see in the title bar?
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 are colors defined in Pygame?
RGB
Without using a color picker, how could you make a bright red? A dark green? Black? White? Light gray? Dark gray?
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)
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.)
Minimum = 0, maximum = 255. If you put 256 or above and/or if you put -1 or below, it will turn black
How do you fill the screen with a color?
screen.fill
What Pygame functions are used to draw shapes (rectangles, ellipses, polygons, and lines)?
pygame.draw.SHAPE(screen.COLOR[Coords], [coords] linewidth)
Explain how we define the location and size of a rectangle used in a pygame drawing function.
Top left coord with height
How do you draw a circle using the draw.ellipse function?
You make the width and height equal
How do you draw filled in shapes? How do you just draw the outline of a shape?
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
How is the order in which Pygame elements are drawn determined?
In the order they are in the code
When you blit an image on the screen, what location on the image do the [x, y] values represent?
Top left corner
Why does the draw_tree function take x and y arguments?
For positioning purposes
Why do some functions not take any arguments?
Not all functions need it