python 2c pygame

Solutions on MaxInterview for python 2c pygame by the best coders in the world

showing results for - "python 2c pygame"
Soraya
25 Aug 2018
1import sys
2import pygame
3
4pygame.init()
5    
6screen = pygame.display.set_mode((800, 400))
7pygame.display.set_caption('Amogus Adventures')
8clock = pygame.time.Clock()
9
10test_font = pygame.font.Font('Graphics/Pixeltype.ttf', 50)
11StartButton = pygame.image.load('Graphics/STARTAS.png')
12GameStart = pygame.image.load('Graphics/gamestart.png')
13text_surface = test_font.render('Press enter to play!', True, 'Green')
14StartButton2 = pygame.image.load('Graphics/STARTAS2.png')
15class Game:
16    def __init__(self):
17        self.screen = pygame.display.set_mode((800, 400))
18        self.position = (100, 70)
19        self.size = (325,125)
20        self.rect = pygame.Rect(self.position, self.size)
21        self.color = pygame.Color("red")
22        pygame.display.set_caption('Amogus Adventures')
23
24    def run(self):
25        FPS = 60
26        clock = pygame.time.Clock()
27    
28        while True:
29            for event in pygame.event.get():
30                if event.type == pygame.QUIT:
31                    pygame.quit()
32                    sys.exit()
33 
34            mouse_position = pygame.mouse.get_pos()
35            left_button,_,_ = pygame.mouse.get_pressed()
36            if self.rect.collidepoint(mouse_position) and left_button:
37                # Clicked, do your code, start your game
38                print('clicked')
39                
40                pygame.draw.rect(self.screen, pygame.Color("green"), self.rect)
41            else:
42                # Not clicked, do normal stuff
43                pygame.draw.rect(self.screen, pygame.Color("red"), self.rect)
44 
45            clock.tick(FPS)
46            pygame.display.update()
47
48            screen.blit(GameStart,(0,0))
49            screen.blit(StartButton,(0,0))
50            screen.blit(text_surface,(115,25))
51            
52if __name__ == '__main__':
53    pygame.init()
54    Game().run()