def again(winner, lost, kicked): global repeat if kicked: text = large_font.render("You were kicked!", True, (10, 10, 10)) elif lost: text = large_font.render("You lost!", True, (10, 10, 10)) elif winner != '': text = large_font.render(winner, True, (10, 10, 10)) else: text = large_font.render("It's a draw!", True, (10, 10, 10)) x = screen.get_size()[0] // 2 - text.get_size()[0] // 2 y = screen.get_size()[1] // 2 - text.get_size()[1] // 2 text_r = medium_font.render('Press R to play again', True, (150, 150, 150)) x1 = screen.get_size()[0] // 2 - text_r.get_size()[0] // 2 y1 = y + text.get_size()[1] + 25 rep_loop = True while rep_loop: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: rep_loop = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: rep_loop = False if event.key == pygame.K_r: rep_loop = False repeat = True screen.fill((255, 255, 255)) screen.blit(text, (x, y)) screen.blit(text_r, (x1, y1)) pygame.display.flip()
def draw(self): colour = self.colour if not self.is_active else self.act_colour but = pygame.Surface((self.button_w, self.button_h)) but.fill(colour) but.set_alpha(180) screen.blit(but, (self.button_x, self.button_y)) pygame.draw.rect( screen, self.color_per, (self.button_x, self.button_y, self.button_w, self.button_h), 2) screen.blit(self.txt, (self.txt_x, self.txt_y))
def menu(): global screen, clock, gamemode hello_text = '' hello_text = large_font.render(hello_text, True, (50, 50, 50)) buttons = [] solo = ButtonPressed('Solo game', 100, 500, large_font, (0, 0, 0), (125, 255, 125), (10, 100, 10), start) buttons.append(solo) Mplayer = ButtonPressed('Multiplayer', 430, 500, large_font, (0, 0, 0), (255, 255, 0), (10, 100, 10), start) buttons.append(Mplayer) auto = ButtonPressed('AI - Mod', 800, 500, large_font, (0, 0, 0), (255, 125, 125), (10, 100, 10), start) buttons.append(auto) """ auto = ButtonPressed('Controls', 900, 500, large_font, (0, 0, 0), (255, 125, 125), (10, 100, 10), start) buttons.append(auto)""" menuloop = True while menuloop: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: menuloop = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: menuloop = False pos = pygame.mouse.get_pos() for button in buttons: dist_x = pos[0] - button.button_x dist_y = pos[1] - button.button_y if 0 <= dist_x <= button.button_w and 0 <= dist_y <= button.button_h: button.is_active = True if event.type == pygame.MOUSEBUTTONDOWN: gamemode = button.run(button.text) menuloop = False else: button.is_active = False screen.blit(poster, (0, 0)) screen.blit(hello_text, (screen.get_size()[0] // 2 - hello_text.get_size()[0] // 2, 80)) for button in buttons: button.draw() pygame.display.flip()
def draw(self): tank_c = (self.x + self.width // 2, self.y + self.width // 2) pygame.draw.rect(screen, self.color, (self.x, self.y, self.width, self.width)) pygame.draw.circle(screen, self.color, tank_c, self.width // 2) pygame.draw.circle(screen, (0, 0, 0), tank_c, self.width // 2 - 1, 1) if self.direction == Direction.RIGHT: pygame.draw.line(screen, self.color, tank_c, (tank_c[0] + self.width, tank_c[1]), 5) if self.direction == Direction.LEFT: pygame.draw.line(screen, self.color, tank_c, (tank_c[0] - self.width, tank_c[1]), 5) if self.direction == Direction.UP: pygame.draw.line(screen, self.color, tank_c, (tank_c[0], tank_c[1] - self.width), 5) if self.direction == Direction.DOWN: pygame.draw.line(screen, self.color, tank_c, (tank_c[0], tank_c[1] + self.width), 5) screen.blit( self.txt, (tank_c[0] - self.txt.get_size()[0] // 2, self.y + self.width + 2))
def draw(self): screen.blit(self.image, self.coord)