Pygame --> by myCODEnotein

Installing Pygame

pip install pygame

Basic pygame starting

import pygame
pygame.init()
screen = pygame.display.set_mode((WIDTH,HEIGHT))

Basic required code

running=True
while running:
	for event in pygame.event.get():
		if event.type==pygame.QUIT:
			running=False

Drawing with pygame

Drawing a rectangle

pygame.draw.rect(surface,(r,g,b),(x,y,width,height))

Doing the same thing with pygame.Rect

rect = pygame.rect(x,y,width,height) 
pygame.draw.rect(surface,(r,g,b),rect)

Resizing the rectangle

rect.inflate(width,height)
# -ve values make it smaller and vice-versa
# Note that to see change rect must be draw again on screen , if it is already drawn

Drawing a circle

pygame.draw.circle(surface,(r,g,b),(x,y),radius,thickness)

Mouse Related Functions

mouseX , mouseY = pygame.mouse.get_pos()
# Returns mouse x coordinates and y coordinates

Dealing with images

Loading the image --> First step

myImg = pygame.image.load(pathOfImage)

Converting the image with convert_alpha

myImg = myImg.convert_alpha()

Changing the image size

myImg = pygame.transform.scale(myImg,(width,height))
# Note that myImg used as argument is already loaded

Drawing the image on screen

surface_or_screen.blit(myImg,(x,y))
# Note that here screen is the variable created at the starting of notes