fantasma que se mueve


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ancho =500
  2. alto =500
  3. import random
  4. import pygame
  5. import sys
  6. from pygame.locals import *
  7. ventana = pygame.display.set_mode((ancho, alto))
  8. pygame.display.set_caption("marcos game !")
  9. fantasma= pygame.image.load("rojo.gif")
  10. x=50
  11. y=50
  12. anchoi=56
  13. altoi=56
  14. ventana.blit(fantasma,[x,y])
  15. pygame.display.flip()
  16. while True:
  17. for event in pygame.event.get():
  18. if event.type == QUIT:
  19. pygame.quit()
  20. sys.exit()
  21. if event.type==pygame.KEYDOWN:
  22. #CONTROLES
  23. if event.key==pygame.K_LEFT:
  24. pygame.draw.rect(ventana,(0,0,0),(x,y,anchoi,altoi))
  25. x=x-56
  26. pygame.display.flip()
  27. ventana.blit(fantasma,[x,y])
  28. pygame.display.flip()
  29. if event.key==pygame.K_RIGHT:
  30. pygame.draw.rect(ventana,(0,0,0),(x,y,anchoi,altoi))
  31. x=x+56
  32. pygame.display.flip()
  33. ventana.blit(fantasma,[x,y])
  34. pygame.display.flip()
  35. if event.key==pygame.K_UP:
  36.  
  37. pygame.draw.rect(ventana,(0,0,0),(x,y,anchoi,altoi))
  38. y=y-56
  39. pygame.display.flip()
  40. ventana.blit(fantasma,[x,y])
  41. pygame.display.flip()
  42. if event.key==pygame.K_DOWN:
  43.  
  44. pygame.draw.rect(ventana,(0,0,0),(x,y,anchoi,altoi))
  45. y=y+56
  46. pygame.display.flip()
  47. ventana.blit(fantasma,[x,y])
  48. pygame.display.flip()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.