Skip to content

Instantly share code, notes, and snippets.

@jeffersonsouza
Last active November 15, 2020 14:26
Show Gist options
  • Save jeffersonsouza/b5d5bafadb785b58aa1c8c7ce8a1de77 to your computer and use it in GitHub Desktop.
Save jeffersonsouza/b5d5bafadb785b58aa1c8c7ce8a1de77 to your computer and use it in GitHub Desktop.
{
// Copie daqui
"Init PyGame": {
"prefix": "pygame.init",
"body": [
"import pygame",
"from collections import namedtuple",
"",
"# Game init",
"pygame.init()",
"",
"# Coordinates",
"Coordinate = namedtuple('Coordinate', ['x', 'y'])",
"",
"screenSize = Coordinate(x=800, y=600)",
"screen = pygame.display.set_mode(screenSize)"
],
"description": "Initialize PyGame and set main scrseen"
},
"PyGame Title": {
"prefix": "pygame.title",
"body": [
"# Change title and logo",
"icon = pygame.image.load('$1')",
"pygame.display.set_caption('$2')",
"pygame.display.set_icon(icon)"
],
"description": "Set title and Icon for the application"
},
"PyGame Text": {
"prefix": "pygame.text",
"body": [
"font = pygame.font.SysFont('${1:arial}', 32)",
"text = font.render(f\"${2:title}\", 1, (0, 0, 0))",
"position = text.get_rect(center=(screen.get_width()//2, screen.get_height()//2))",
"screen.blit(text, position)"
],
"description": "Set title and Icon for the application"
},
"PyGame While": {
"prefix": "pygame.loop",
"body": [
"# Game loop",
"running = True",
"clock = pygame.time.Clock()",
"while running:",
" # events",
" for event in pygame.event.get():",
" if event.type == pygame.QUIT:",
" running = False",
"",
" # paint the screen",
" screen.fill((255, 255, 255))",
"",
" # Update the display",
" pygame.display.update()",
"",
" # Update the display",
" clock.tick()",
"",
"pygame.display.quit()",
],
"description": "Create main while loop to keep the game running"
},
"PyGame KeyEvents": {
"prefix": "pygame.keyEvents",
"body": [
"if event.type == pygame.KEYDOWN:",
" if event.key == pygame.K_LEFT:",
" continue",
"",
" if event.key == pygame.K_RIGHT:",
" continue",
"",
" if event.key == pygame.K_UP:",
" continue",
"",
" if event.key == pygame.K_DOWN:",
" continue",
"",
"if event.type == pygame.KEYUP:",
" if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:",
" continue",
"",
" if event.key == pygame.K_UP or event.key == pygame.K_DOWN:",
" continue"
],
"description": "Create default keu Up/right/left/down events watch"
}
// Copie até aqui
}
## VSCode Snippets
Criei esta coleção para tornar mais rápido o meu desenvolvimento durante os estudos.
### Como adicionar ao seu VSCode
Para adicionar ao VSCode, basta copiar o conteúdo do arquivo correspondente a linguagem (python.json, por exemplo)
e colar no seu arquivo de snippets.
Para acessar a sua coleção de snippets, você pode navegar até o menu `Preferences > User Snippets` no mac
e logo depois selecionar a linguagem que você deseja adicionar os snippets (neste caso, python).
Caso você já tenha algum snippet no seu arquivo, sugiro apenas copiar o conteúdo entre os comentários "copie daqui"
até "Copie até aqui".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment