Advertisement
albertohilal

Clase 10 Ejemplo 3.2.b

Oct 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import pygame
  2. import sys
  3. BLANCO = (255, 255, 255)
  4. ROJO = (255, 0, 0)
  5. X = 0
  6. Y = 1
  7. ABAJO = 1
  8. ARRIBA = -1
  9. MEDIDA_PANTALLA = (640, 480)
  10. def Pelota(pantalla, posicion):
  11. pygame.draw.circle(pantalla, ROJO, posicion, 50)
  12.  
  13. def DibujarPantalla(pantalla, estado):
  14. Pelota(pantalla, estado["posicion"])
  15.  
  16. def actualizarEstado(estado):
  17. if estado["posicion"][Y] >= 480 - 50:
  18. # Si llega al Borde de pantalla
  19. dir = ARRIBA
  20. elif estado["posicion"][Y] <= 240:
  21. # Si alcanza la posicion inicial
  22. dir = ABAJO
  23. else:
  24. # De lo contrario, continuamos en la misma direccion
  25. dir = estado["direccion"]
  26.  
  27. pos = (estado["posicion"][X], estado["posicion"][Y] + dir)
  28.  
  29. # Retorno el nuevo estado
  30. return {
  31. "posicion" : pos,
  32. "direccion" : dir
  33. }
  34. def EjecutarCiclo():
  35. estado = {
  36. "posicion": (320, 240),
  37. "direccion": ABAJO
  38. }
  39. pygame.init()
  40. pantalla = pygame.display.set_mode( MEDIDA_PANTALLA )
  41. reloj = pygame.time.Clock()
  42. while True:
  43. estado = actualizarEstado(estado)
  44. pantalla.fill(BLANCO)
  45. DibujarPantalla(pantalla, estado)
  46. pygame.display.flip()
  47. tick = reloj.tick(60)
  48.  
  49. if __name__ == "__main__":
  50. EjecutarCiclo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement