PYTHON PYGAME NOTES
-----> FOR YOU


Click for newer version of pygame notes (better)
BASIC PYGAME STARTING :-
import pygame
pygame.init()
screen = pygame.display.set_mode( (WIDTH,HEIGHT) )
BASIC REQUIRED CODE :-
There must be following code to get a screen
running = True while running : for event in pygame.event.get(): if event.type == QUIT: running = False pygame.display.update()
DRAWING WITH PYGAME
pygame.draw.rect(surface,(r,g,b),(x-coordinate,y-coordinate,width,height))
# Doing the same thing with pygame.Rect
rect = pygame.rect(x-coordinate,y-coordinate,width,height)
pygame.draw.rect(surface,(r,g,b),rect)
# RESIZING A RECTANGLE rect.inflate(width , height) # if you give -ve width or height the rectangle # rectangle will become smaller and vice-versa
# ALSO NOTE THAT IF THE RECTANGLE IS ALREADY DRAWN # TO SEE THE CHANGE YOU NEED TO DRAW IT AGAIN
pygame.draw.circle(surface,(r,g,b),(x,y),radius,thickness)
MOUSE-RELATED STUFF :-
The following mouse functions can are there in pygamemouse_x , mouse_y = pygame.mouse.get_pos()
# GIVES MOUSE POSITION
DEALING WITH IMAGES :-
To add an image to your program :-# LOADING THE IMAGE -- 1st step without which # nothing else will work image = pygame.image.load(path_of_image) # AN ADDITIONAL PARAMETER image = pygame.image.load(path_of_image).convert_alpha() # CHANGING IMAGE SIZE image = pygame.transform.scale(image,(width,height)) # DRAWING THE IMAGE ON SCREEN surface_or_screen.blit(image,(x,y))
Comments
Post a Comment