Advertisement
chete

Snake game

Nov 12th, 2014
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. white = (255,255,255)
  6. black = (0,0,0)
  7. red = (255,0,0)
  8.  
  9.  
  10.  
  11. gameDisplay = pygame.display.set_mode((800,600))
  12. pygame.display.set_caption('Slither')
  13.  
  14.  
  15. gameExit = False
  16.  
  17. lead_x = 300
  18. lead_y = 300
  19. lead_x_change = 0
  20. lead_y_change = 0
  21.  
  22. clock = pygame.time.Clock()##clock
  23.  
  24. while not gameExit:
  25.     for event in pygame.event.get():
  26.         if event.type == pygame.QUIT:  
  27.             gameExit = True
  28.         if event.type == pygame.KEYDOWN:
  29.             if event.key == pygame.K_LEFT:
  30.                 lead_x_change = -10
  31.             if event.key == pygame.K_RIGHT:
  32.                 lead_x_change = 10
  33.             if event.key == pygame.K_UP:
  34.                 lead_y_change = -10
  35.             if event.key == pygame.K_DOWN:
  36.                 lead_y_change = 10
  37.         if event.type == pygame.KEYUP:
  38.             if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  39.                 lead_x_change = 0
  40.             if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
  41.                 lead_y_change = 0
  42.  
  43.                
  44.     lead_x += lead_x_change
  45.     lead_y += lead_y_change
  46.    
  47.     gameDisplay.fill(white) ## color de el fondo de pantalla
  48.     pygame.draw.rect(gameDisplay, black, [lead_x,lead_y,10,10]) ##dibujar un rectangulo
  49.     pygame.display.update()## despues de tener todos los ajustes graficos renderizamos
  50.  
  51.     clock.tick(15)##clock
  52.  
  53.  
  54. pygame.quit()
  55. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement