elukjanovica 2024-01-29 11:22:57 +02:00
parent 58fbf688dd
commit 328e703f89
1 changed files with 18 additions and 21 deletions

23
main.py
View File

@ -133,7 +133,7 @@ character2 = Character(400, 300, 50, 50, "blue", "Character 2")
character_sprites = pygame.sprite.Group(character1, character2)
player_sprite = pygame.sprite.Group(player)
# Define game states
# Менюм / Игровой режим
class GameState:
MENU = 0
GAMEPLAY = 1
@ -149,16 +149,16 @@ while running:
running = False
if current_state == GameState.MENU:
# Handle mouse clicks in the menu state
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_x, mouse_y = pygame.mouse.get_pos()
if play_button.is_hovered((mouse_x, mouse_y)):
# Transition to the gameplay state
# Переход в игровой режим
current_state = GameState.GAMEPLAY
elif current_state == GameState.GAMEPLAY:
# Handle events in the gameplay state
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
nearest_character = min(character_sprites, key=lambda c: pygame.math.Vector2(c.rect.center).distance_to(player.rect.center))
@ -177,12 +177,17 @@ while running:
background_img_image = pygame.image.load(BACKGROUND_IMAGE).convert_alpha()
screen.blit(background_img_image, (0, 0))
# Меню
if current_state == GameState.MENU:
screen.blit(play_button.image, play_button.rect)
screen.blit(continue_button.image, continue_button.rect)
screen.blit(menu_button.image, menu_button.rect)
mouse_pos = pygame.mouse.get_pos()
play_button.update(mouse_pos)
continue_button.update(mouse_pos)
menu_button.update(mouse_pos)
elif current_state == GameState.GAMEPLAY:
# Обновить игрока
player.update_position(5, 0)
@ -195,14 +200,6 @@ while running:
for sprite in player_sprite:
screen.blit(sprite.image, camera.apply(sprite.rect))
# Генерация кнопок
mouse_pos = pygame.mouse.get_pos()
play_button.update(mouse_pos)
continue_button.update(mouse_pos)
menu_button.update(mouse_pos)
pygame.display.flip()
deltatime = clock.tick(FPS) / 1000