Advertisement
Midler9

verkefni5 24.september 2017

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