This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pygame | |
| pygame.init() | |
| game_display = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) | |
| pygame.display.set_caption(GAME_CAPTION) | |
| pygame.quit() | |
| quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while is_running: | |
| for event in pygame.event.get(): | |
| # print(event) | |
| if event.type == pygame.QUIT: | |
| is_running = False | |
| elif event.type == pygame.KEYDOWN: | |
| if event.key == pygame.K_q: | |
| is_running = False | |
| elif event.key == pygame.K_RIGHT: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| game_display = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) | |
| BLACK = (0,0,0) | |
| pygame.draw.rect(game_display, BLACK, [x, y, width, height]) | |
| game_display.fill(BLACK, rect=[x, y, width, height]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| clock = pygame.time.Clock() | |
| FPS = 60 | |
| ... | |
| while is_running: | |
| for event in pygame.event.get(): | |
| ... | |
| ... | |
| pygame.display.update() | |
| clock.tick(FPS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, sys | |
| def load_image(name): | |
| fullname = os.path.join('data', name) | |
| try: | |
| image = pygame.image.load(fullname) | |
| except pygame.error, message: | |
| print 'Cannot load image:', name | |
| raise SystemExit, message | |
| image = image.convert() | |
| return image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pygame.mouse.set_visible(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| image = pygame.transform.scale(image, (desired_width,desired_height)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| background = pygame.Surface(game_display.get_size()) # (width,height) | |
| background = background.convert() | |
| background.fill((100, 100, 100)) | |
| game_display.blit(background, (0,0)) | |
| pygame.display.update() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| font_size = 36 | |
| text_color = (10,10,10) | |
| background_text_color = (255, 255, 255) | |
| background = pygame.Surface(game_display.get_size()) | |
| if pygame.font: | |
| font = pygame.font.Font(None, font_size) | |
| text = font.render("Text", 1, text_color, background_text_color) # color and background | |
| textpos = text.get_rect(centerx=background.get_width()/2, centery=background.get_height()/2) | |
| # textpos = (50,50) | |
| background.blit(text, textpos) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while is_running: | |
| for event in pygame.event.get(): | |
| if event.type == MOUSEBUTTONDOWN: | |
| if event.button == 1: | |
| print("Left button") | |
| elif event.button == 3: | |
| print("Right button") | |
| # 4, 5, 6 are scroll events, not sure about the details | |
| elif event.type == MOUSEBUTTONUP: |