fenrie

pygame code

Nov 2nd, 2020
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. import pygame, sys
  2.  
  3. # Setup pygame/window ---------------------------------------- #
  4. mainClock = pygame.time.Clock()
  5. from pygame.locals import *
  6.  
  7.  
  8. SCREEN_WIDTH = 1143
  9. SCREEN_HEIGHT = 650
  10.  
  11. pygame.image.load(r"C:\Users\ga-sa\Downloads\iniciar.png")
  12. class Circuito(pygame.sprite.Sprite):
  13.  
  14. def __init__(self):
  15. pygame.sprite.Sprite.__init__(self)
  16.  
  17. self.images = [pygame.image.load(r'C:\Users\ga-sa\Downloads\00.png').convert_alpha(),
  18. pygame.image.load(r'C:\Users\ga-sa\Downloads\01.png').convert_alpha(),
  19. pygame.image.load(r"C:\Users\ga-sa\Downloads\02.png").convert_alpha(),
  20. pygame.image.load(r'C:\Users\ga-sa\Downloads\03.png').convert_alpha()]
  21.  
  22. self.current_image = 0
  23.  
  24. self.image = pygame.image.load(r'C:\Users\ga-sa\Downloads\00.png').convert_alpha()
  25. self.rect = self.image.get_rect()
  26. self.rect[0] = 500
  27. self.rect[1] = 10
  28.  
  29. def update(self):
  30. self.current_image = (self.current_image + 1) % 4
  31. self.image = self.images[ self.current_image ]
  32.  
  33. pygame.init()
  34. pygame.display.set_caption('game base')
  35. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  36. iniciar = pygame.image.load(r"C:\Users\ga-sa\Downloads\iniciar.png")
  37. config = pygame.image.load(r"C:\Users\ga-sa\Downloads\config.png")
  38. nivel = pygame.image.load(r"C:\Users\ga-sa\Downloads\nivel.png")
  39. sair = pygame.image.load(r"C:\Users\ga-sa\Downloads\sair.png")
  40.  
  41. BACKGROUND = pygame.image.load(r'C:\Users\ga-sa\Downloads\honeycomb.png')
  42. BACKGROUND = pygame.transform.scale(BACKGROUND, (SCREEN_WIDTH, SCREEN_HEIGHT))
  43.  
  44. BACKGROUND_FASE = pygame.image.load(r"C:\Users\ga-sa\Downloads\FaseSemX_1.png")
  45. BACKGROUND_FASE = pygame.transform.scale(BACKGROUND_FASE, (SCREEN_WIDTH, SCREEN_HEIGHT))
  46.  
  47.  
  48.  
  49. font = pygame.font.SysFont(None, 20)
  50.  
  51.  
  52. def draw_text(text, font, color, surface, x, y):
  53. textobj = font.render(text, 1, color)
  54. textrect = textobj.get_rect()
  55. textrect.topleft = (x, y)
  56. surface.blit(textobj, textrect)
  57.  
  58.  
  59. click = False
  60.  
  61.  
  62. def main_menu():
  63. while True:
  64.  
  65. screen.fill((0, 0, 0))
  66. draw_text('main menu', font, (255, 255, 255), screen, 20, 20)
  67.  
  68. mx, my = pygame.mouse.get_pos()
  69.  
  70.  
  71. button_1 = pygame.Rect(400, 50, 800, 200)
  72. button_2 = pygame.Rect(450, 500, 720, 180)
  73. if button_1.collidepoint((mx, my)):
  74. if click:
  75. game()
  76. if button_2.collidepoint((mx, my)):
  77. if click:
  78. options()
  79.  
  80.  
  81.  
  82.  
  83. pygame.draw.rect(screen, (255, 0, 0), button_1)
  84. pygame.draw.rect(screen, (255, 0, 0), button_2)
  85.  
  86.  
  87. click = False
  88. for event in pygame.event.get():
  89. if event.type == QUIT:
  90. pygame.quit()
  91. sys.exit()
  92. if event.type == KEYDOWN:
  93. if event.key == K_ESCAPE:
  94. pygame.quit()
  95. sys.exit()
  96. if event.type == MOUSEBUTTONDOWN:
  97. if event.button == 1:
  98. click = True
  99.  
  100. screen.blit(BACKGROUND, (0,0))
  101. screen.blit(iniciar, (400, 50))
  102. screen.blit(config, (450, 500))
  103. screen.blit(nivel, (400, 280))
  104. screen.blit(sair, (400, 700))
  105. pygame.display.update()
  106. mainClock.tick(60)
  107.  
  108.  
  109.  
  110. def game():
  111. running = True
  112. while running:
  113. screen.fill((0, 0, 0))
  114. mx, my = pygame.mouse.get_pos()
  115. button_3 = pygame.Rect(300, 100, 1300, 700)
  116. if button_3.collidepoint((mx, my)):
  117. if click:
  118. begin()
  119.  
  120. draw_text('game', font, (255, 255, 255), screen, 20, 20)
  121. for event in pygame.event.get():
  122. if event.type == QUIT:
  123. pygame.quit()
  124. sys.exit()
  125. if event.type == KEYDOWN:
  126. if event.key == K_ESCAPE:
  127. running = False
  128.  
  129.  
  130. # set the pygame window name
  131.  
  132. img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png")
  133. img2 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsXOR.png")
  134. img3 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsNOT.png")
  135. img4 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsAND.png")
  136.  
  137. images = [img1, img2, img3, img4]
  138.  
  139. current_image = -1
  140. img_rects = [images[i].get_rect(topleft=(20 + 40 * i, 20)) for i in range(len(images))]
  141.  
  142. LeftButton = 0
  143. while 1:
  144. for e in pygame.event.get():
  145. if e.type == QUIT:
  146. pygame.quit()
  147. exit(0)
  148.  
  149. if e.type == pygame.MOUSEBUTTONDOWN:
  150. mouse_rect = pygame.Rect(e.pos, (1, 1))
  151. current_image = mouse_rect.collidelist(img_rects)
  152.  
  153. if e.type == MOUSEMOTION:
  154. if e.buttons[LeftButton]:
  155. rel = e.rel
  156. if 0 <= current_image < len(images):
  157. img_rects[current_image].x += rel[0]
  158. img_rects[current_image].y += rel[1]
  159.  
  160. screen.fill(0)
  161. for i in range(len(images)):
  162. screen.blit(images[i], img_rects[i])
  163. pygame.display.flip()
  164. pygame.time.delay(30)
  165.  
  166. screen.blit(BACKGROUND_FASE, (0, 0))
  167. pygame.display.update()
  168. mainClock.tick(60)
  169.  
  170.  
  171. def begin():
  172. running = True
  173. while running:
  174. screen.fill((0, 0, 0))
  175.  
  176. draw_text('begin', font, (255, 255, 255), screen, 20, 20)
  177. for event in pygame.event.get():
  178. if event.type == QUIT:
  179. pygame.quit()
  180. sys.exit()
  181. if event.type == KEYDOWN:
  182. if event.type == KEYDOWN:
  183. running = False
  184.  
  185.  
  186.  
  187. pygame.display.update()
  188. mainClock.tick(60)
  189.  
  190. def options():
  191. running = True
  192. while running:
  193. screen.fill((0, 0, 0))
  194.  
  195. draw_text('options', font, (255, 255, 255), screen, 20, 20)
  196. for event in pygame.event.get():
  197. if event.type == QUIT:
  198. pygame.quit()
  199. sys.exit()
  200. if event.type == KEYDOWN:
  201. if event.key == K_ESCAPE:
  202. running = False
  203.  
  204. pygame.display.update()
  205. mainClock.tick(60)
  206.  
  207.  
  208. main_menu()
Advertisement
Add Comment
Please, Sign In to add comment