My Pygame Notes

Importing PyGame:
To use PyGame in your Python program, you need to import the library with the statement import pygame.

Setting Display Mode:
To create a window for your game, use pygame.display.set_mode((width, height)), where width and height represent the screen dimensions. Example: pygame.display.set_mode((800, 600)) will create an 800x600 window.

Using For Loops:
In PyGame, a for loop can be used for tasks like iterating over multiple objects or handling events. Example: for event in pygame.event.get(): checks for each event in the event queue.

Using While Loops:
The while loop is commonly used for the game loop, which runs continuously to check for events, update the screen, and render graphics. Example: while running: keeps the game running until the condition changes.

Drawing a Rectangle:
To draw a rectangle on the screen, use the function pygame.draw.rect(screen, color, pygame.Rect(x, y, width, height)). Example: pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(100, 100, 200, 150)) draws a red rectangle at position (100, 100) with size 200x150.

Drawing a Circle:
To draw a circle, use the function pygame.draw.circle(screen, color, (x, y), radius). Example: pygame.draw.circle(screen, (0, 255, 0), (300, 300), 50) draws a green circle with a radius of 50 at position (300, 300).

Drawing a Polygon:
To draw a polygon, use pygame.draw.polygon(screen, color, points), where points is a list of (x, y) coordinates. Example: pygame.draw.polygon(screen, (0, 0, 255), [(400, 100), (500, 200), (400, 300)]) draws a blue triangle.

Flipping the Screen:
After drawing everything on the screen, you need to update the display using pygame.display.flip(). This will make all the changes visible. Example: pygame.display.flip() refreshes the entire window.

Quitting:
Code: for event in pygame.event.get(): if event.type == pygame.QUIT: drawing = False

Starter Code:
import pygame as pg pg.init() window = pg.display.set_mode([400, 400]) window.fill((255, 255, 255))