albertohilal

Clase 10 ejercicio-03

Oct 29th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import pygame
  2. import sys
  3.  
  4. BLANCO = (255, 255, 255)
  5. ROJO = (255, 0, 0)
  6.  
  7. MEDIDA_PANTALLA = (640, 480)
  8.  
  9. X = 0
  10. Y = 1
  11.  
  12. def Pelota(pantalla, posicion,dimension):
  13. pygame.draw.ellipse(pantalla, ROJO, (posicion,dimension), 5)
  14.  
  15. def DibujarPantalla(pantalla,estado):
  16. posicion=(80, 0)
  17. dimension=(240, 240)
  18. Pelota(pantalla, estado["posicion"], estado ["dimension"])
  19.  
  20. def actualizarEstado(estado):
  21.  
  22. pos = estado["posicion"]
  23. dim = estado ["dimension"]
  24.  
  25. for evento in pygame.event.get():
  26. if evento.type == pygame.KEYDOWN:
  27.  
  28.  
  29. if evento.key == pygame.K_LEFT:
  30. pos = (estado["posicion"][X]-10, estado["posicion"][Y])
  31. if evento.key == pygame.K_RIGHT:
  32. pos = (estado["posicion"][X]+10, estado["posicion"][Y])
  33. if evento.key == pygame.K_UP:
  34. pos = (estado["posicion"][X], estado["posicion"][Y]-10)
  35. if evento.key == pygame.K_DOWN:
  36. pos = (estado["posicion"][X], estado["posicion"][Y]+10)
  37.  
  38. if evento.key == pygame.K_KP8:
  39. dim = (estado ["dimension"][X], estado ["dimension"][Y]-5)
  40. if evento.key == pygame.K_KP2:
  41. dim = (estado ["dimension"][X], estado ["dimension"][Y]+5)
  42. if evento.key == pygame.K_KP6:
  43. dim = (estado ["dimension"][X]+5, estado ["dimension"][Y])
  44. if evento.key == pygame.K_KP4:
  45. dim = (estado ["dimension"][X]-5, estado ["dimension"][Y])
  46.  
  47. if evento.type == pygame.QUIT:
  48. pygame.quit()
  49.  
  50.  
  51.  
  52.  
  53. return{
  54. "posicion": pos,
  55. "dimension": dim
  56. }
  57.  
  58.  
  59.  
  60.  
  61. def Ejecutar():
  62. estado = {
  63. "posicion" : (80,0),
  64. "dimension" : (480,480)
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. pygame.init()
  73. pantalla = pygame.display.set_mode(MEDIDA_PANTALLA)
  74. reloj = pygame.time.Clock()
  75. while True:
  76. pantalla.fill(BLANCO)
  77. DibujarPantalla(pantalla, estado)
  78.  
  79. estado = actualizarEstado(estado)
  80. pygame.display.flip()
  81. tick = reloj.tick(60)
  82.  
  83. if __name__ == "__main__":
  84. Ejecutar()
Advertisement
Add Comment
Please, Sign In to add comment