SHARE
TWEET

Untitled

a guest Jun 16th, 2019 370 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import pygame
  3. import sys
  4. import random
  5. os.environ['SDL_VIDEO_CENTERED'] = '1'
  6. pygame.init()
  7.  
  8. screen = pygame.display.set_mode((1920,1080))
  9. pygame.display.set_caption("Gra O Zaliczenie")
  10. clock = pygame.time.Clock()
  11.  
  12. #STAŁE
  13. MY_LETTERS="ABCDEFGHJKNOPRSXZ"
  14.  
  15. class Interface:
  16.     def __init__(self):
  17.         pygame.sprite.Sprite.__init__(self)
  18.         self.rect = self.image.get_rect()
  19.  
  20.  
  21. class BG:
  22.     def __init__(self):
  23.         self.bg = pygame.image.load(os.path.join(os.getcwd(), 'obrazki/chest.png'))
  24.         self.rect = self.bg.get_rect()
  25.     def draw(self,surface):
  26.         surface.blit(self.bg, self.rect)
  27.  
  28.  
  29. class Letters:
  30.     def __init__(self, char=""):
  31.         self.letter= pygame.image.load(os.path.join(os.getcwd(), 'obrazki/letter_' + char + ".png"))
  32.         self.rect = self.letter.get_rect()
  33.         self.__char = char
  34.  
  35.     def get_char(self):
  36.         return self.__char
  37.  
  38.     def draw(self, surface):
  39.         surface.blit(self.letter, self.rect)
  40.  
  41.     def set_start_position(self,pos_x,pos_y):
  42.         self.rect.x = pos_x
  43.         self.rect.y = pos_y
  44.     def switch_letter_position(self):
  45.         self.rect.x += 100
  46.  
  47.  
  48. class Frame:
  49.     def __init__(self):
  50.         self.frame= pygame.image.load(os.path.join(os.getcwd(), 'obrazki/frame.png'))
  51.         self.rect = self.frame.get_rect()
  52.  
  53.     def draw(self, surface):
  54.         surface.blit(self.frame, self.rect)
  55.  
  56.     def set_start_position(self,pos_x,pos_y):
  57.         self.rect.x = pos_x
  58.         self.rect.y = pos_y
  59.  
  60.     def update_position(self):
  61.         if (self.rect.x < 1231):
  62.             self.rect.x += 100
  63.         else:
  64.             self.rect.x = 530
  65.  
  66. class ButtonL:
  67.     def __init__(self):
  68.         self.br= pygame.image.load(os.path.join(os.getcwd(), 'obrazki/button_L.png'))
  69.         self.rect = self.br.get_rect()
  70.  
  71.     def draw(self, surface):
  72.         surface.blit(self.br, self.rect)
  73.  
  74.     def set_start_position(self, pos_x, pos_y):
  75.         self.rect.x = pos_x
  76.         self.rect.y = pos_y
  77.  
  78. class ButtonR:
  79.     def __init__(self):
  80.         self.bl= pygame.image.load(os.path.join(os.getcwd(), 'obrazki/button_R.png'))
  81.         self.rect = self.bl.get_rect()
  82.  
  83.     def draw(self, surface):
  84.         surface.blit(self.bl, self.rect)
  85.  
  86.     def set_start_position(self, pos_x, pos_y):
  87.         self.rect.x = pos_x
  88.         self.rect.y = pos_y
  89.  
  90. class ButtonS:
  91.     def __init__(self):
  92.         self.bs= pygame.image.load(os.path.join(os.getcwd(), 'obrazki/button_O.png'))
  93.         self.rect = self.bs.get_rect()
  94.  
  95.     def draw(self, surface):
  96.         surface.blit(self.bs, self.rect)
  97.  
  98.     def set_start_position(self, pos_x, pos_y):
  99.         self.rect.x = pos_x
  100.         self.rect.y = pos_y
  101.  
  102. class Random_Letter_Generator:
  103.     def get_word_unique(length=10):
  104.         selected_letters = []
  105.         for i in range(length):
  106.             letter = MY_LETTERS[random.randrange(len(MY_LETTERS))]
  107.             while letter in selected_letters:
  108.                 letter = MY_LETTERS[random.randrange(len(MY_LETTERS))]
  109.             selected_letters.append(letter)
  110.         return ''.join(selected_letters)
  111.  
  112.  
  113.  
  114. # TWORZENIE OBIEKTÓW
  115. bg=BG()
  116. frame=Frame()
  117. letter=Letters("a")
  118. bl=ButtonL()
  119. br=ButtonR()
  120. bs=ButtonS()
  121. word=Random_Letter_Generator.get_word_unique()
  122.  
  123. letter.set_start_position(535, 185)
  124. frame.set_start_position(530, 180)
  125. bl.set_start_position(500, 400)
  126. br.set_start_position(900, 400)
  127. bs.set_start_position(1300, 400)
  128.  
  129.  
  130.  
  131. def event_handler():
  132.  
  133.     for event in pygame.event.get():
  134.  
  135.         keys = pygame.key.get_pressed()
  136.  
  137.         if event.type == pygame.QUIT:
  138.             sys.exit(0)
  139.         elif event.type == pygame.KEYDOWN:
  140.             if keys[pygame.K_RIGHT]:
  141.                 frame.update_position()
  142.                 frame.draw(screen)
  143.             elif event.key == pygame.K_ESCAPE:
  144.                 sys.exit(0)
  145. # main loop
  146. i=0
  147. while (True):
  148.     clock.tick(30)
  149.     event_handler()
  150.     bg.draw(screen)
  151.     for i in word:
  152.         letter = Letters(word[i])
  153.         letter.draw(screen)
  154.         letter.switch_letter_position()
  155.     frame.draw(screen)
  156.     bl.draw(screen)
  157.     br.draw(screen)
  158.     bs.draw(screen)
  159.     pygame.display.flip()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top