Classwork:
Discussions on concepts you should know:
- pygame is so advanced that even the pygame module has its own modules
- pygame.locals module contains many constant variables QUIT, K_ESCAPE and many more.
- pygame.init() must always be included in your pygame programs
- pygame.display.set_mode((500, 400), 0, 32) creates a pop up window of width 500 pixels and height 400 pixels. 0 is used for more options and color 32 for depth. If you want to know more about this syntax, here is the link
- Surface object represents pop up windows.
- Differences between values and reference values: a list variable name is actually a reference, the contents of the list are the values.
- RGB referes to Red, Green and Blue
- This method: basicFont.render(‘Hello world!’, True, WHITE, BLUE) creates a Surface object with the text drawn on it
- Anti-aliasing can make your text and lines look blurry but smoother
- A pygame rectangle is an object: Rect((left, top), (width, height)).
pygame.Rect(left, top, width, height) - pygame.Rect objects have attributes, variables that are associated with an object
- pygame.Rect objects have behaviors, methods that are associated with an object
- But you can draw a rectangle with this syntax:pygame.draw.rect(windowSurface, color,( x , y , width, heigth))
where x is the x coordinate and y is the y-coordinate of the upper left corner of the rectangle. - If you are including text in your pygmae window,
text = basicFont.render(‘Hello world!’, True, WHITE, BLUE)
textRect = text.get_rect()
The next step then is to render the text by using the blit method:
windowSurface.blit(text, textRect) - Important: before blit-ting and before drawing: windowSurface.fill(WHITE)
- In Pygame, nothing is drawn to the screen until the pygame.display.update() function is called.
- Finally, no pygame should miss the next lines:
while True:
….for event in pygame.event.get():
……..if event.type == QUIT:
…………pygame.quit()
…………sys.exit() - The End
Homework:
Read chapter 17 topics we covered in class.