Advertisement
albertohilal

Clase 10 ejercicio-02

Oct 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. '''Programa los procedimientos y funciones necesarios para manipular la posicion de la figura
  2. con las flechas del teclado.
  3. Tendras que manipular los eventos pertinentes y mantener un
  4. estado de la figura que contenga la posicioon (x,y) donde dibujar la figura.
  5. Sugerencia: cada vez que accione una tecla de flecha,
  6. modifica las coordenadas agregando o restando un
  7. valor constante (ejemplo, si toca derecha suma 10 a la coordenada x).'''
  8.  
  9. import pygame
  10. import sys
  11. BLANCO = (255, 255, 255)
  12. ROJO = (255, 0, 0)
  13. MEDIDA_PANTALLA = (640, 480)
  14.  
  15.  
  16.  
  17.  
  18. def Pelota(pantalla, posicion):
  19. pygame.draw.circle(pantalla, ROJO, posicion, 239, 2)
  20.  
  21. def Ejecutar():
  22. pygame.init()
  23. coordenadaX = 320
  24. coordenadaY = 240
  25. posicion = [coordenadaX , coordenadaY]
  26. pantalla = pygame.display.set_mode( MEDIDA_PANTALLA )
  27. reloj = pygame.time.Clock()
  28. while True:
  29. for event in pygame.event.get():
  30. if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  31. pygame.quit()
  32. sys.exit()
  33. if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
  34. coordenadaX=coordenadaX+10
  35. posicion = [coordenadaX, coordenadaY]
  36. print posicion[0]
  37. if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
  38. coordenadaX=coordenadaX-10
  39. posicion = [coordenadaX, coordenadaY]
  40. print posicion[0]
  41.  
  42. pantalla.fill(BLANCO)
  43. Pelota(pantalla, posicion)
  44. pygame.display.flip()
  45. tick = reloj.tick(60)
  46.  
  47. if __name__ == "__main__":
  48. Ejecutar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement