Advertisement
Midler9

verkefni5 22.september 2017

Sep 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. """
  2. Simple graphics demo
  3.  
  4. Sample Python/Pygame Programs
  5. Simpson College Computer Science
  6. http://programarcadegames.com/
  7. http://simpson.edu/computer-science/
  8.  
  9. """
  10.  
  11. # Import a library of functions called 'pygame'
  12. import pygame
  13. from pygame.locals import *
  14. # Initialize the game engine
  15. pygame.init()
  16.  
  17. # Define some colors
  18. BLACK = (0, 0, 0)
  19. WHITE = (255, 255, 255)
  20. BLUE = (0, 0, 255)
  21. GREEN = (0, 255, 0)
  22. RED = (255, 0, 0)
  23.  
  24.  
  25. # Set the height and width of the screen
  26. size = (400, 500)
  27. screen = pygame.display.set_mode(size)
  28. pygame.display.set_caption("Verkefni 5")
  29. # Loop until the user clicks the close button.
  30. done = False
  31. clock = pygame.time.Clock()
  32. snua1 = 0
  33. snua2 = 0
  34. x_hnit = 350
  35. y_hnit = 450
  36. x = 0
  37. y = 0
  38. size = 25
  39. att="haegri"
  40. staekka=True
  41. nytt=True
  42. text_rotate_degrees = 0
  43.  
  44. # Loop as long as done == False
  45. while not done:
  46.  
  47. for event in pygame.event.get(): # User did something
  48. if event.type == pygame.QUIT: # If user clicked close
  49. done = True # Flag that we are done so we exit this loop
  50.  
  51. # All drawing code happens after the for loop and but
  52. # inside the main while not done loop.
  53.  
  54. # Clear the screen and set the screen background
  55. screen.fill(RED)
  56.  
  57. font = pygame.font.SysFont('Calibri', 25, True, False)
  58. font2 = pygame.font.SysFont('Comic Sans MS', size, True, False)
  59.  
  60. snua1 = 0
  61. snua2 = 0
  62. # Flipped text
  63. text2 = font2.render("GAME OVER", True, GREEN)
  64. #text2 = pygame.transform.rotate(text2, text_rotate_degrees)
  65. #text_rotate_degrees -=1
  66. text_rect = text2.get_rect()
  67. text_x = screen.get_width() / 2 - text_rect.width / 2
  68. screen.blit(text2, [text_x, 230])
  69.  
  70.  
  71. # Flipped text
  72. text3 = font2.render(":)", True, GREEN)
  73. text3 = pygame.transform.rotate(text3, snua1)
  74. snua1 -=1
  75. text_rect = text3.get_rect()
  76. text_x = screen.get_width() / 2 - text_rect.width / 2
  77. screen.blit(text3, [text_x, 130])
  78.  
  79. text4 = font2.render(":)", True, GREEN)
  80. text4 = pygame.transform.rotate(text4, snua2)
  81. snua1 +=1
  82. text_rect = text4.get_rect()
  83. text_x = screen.get_width() / 2 - text_rect.width / 2
  84. screen.blit(text4, [text_x, 330])
  85.  
  86. if staekka:
  87. size+=1
  88. if size>80:
  89. staekka=False
  90. elif not staekka:
  91. size-=1
  92. if size<10:
  93. staekka=True
  94.  
  95. # Sideways text
  96. text = font.render("Bjarni", True, BLACK)
  97. #text = pygame.transform.rotate(text, 90)
  98.  
  99. if att=="haegri":
  100. x+=1
  101. text = pygame.transform.rotate(text, 0)
  102. elif att=="nidur":
  103. y+=1
  104. text = pygame.transform.rotate(text, 270)
  105. elif x==10 and att=="vinstri":
  106. att="upp"
  107. x=0
  108. y=430
  109. elif y==10 and att=="upp":
  110. att="haegri"
  111. y=0
  112.  
  113. screen.blit(text, [x, y])
  114.  
  115. # Go ahead and update the screen with what we've drawn.
  116. # This MUST happen after all the other drawing commands.
  117. pygame.display.flip()
  118.  
  119. # This limits the while loop to a max of 60 times per second.
  120. # Leave this out and we will use all CPU we can.
  121. clock.tick(60)
  122.  
  123. # Be IDLE friendly
  124. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement