main
parent
58fbf688dd
commit
328e703f89
23
main.py
23
main.py
|
@ -133,7 +133,7 @@ character2 = Character(400, 300, 50, 50, "blue", "Character 2")
|
||||||
character_sprites = pygame.sprite.Group(character1, character2)
|
character_sprites = pygame.sprite.Group(character1, character2)
|
||||||
player_sprite = pygame.sprite.Group(player)
|
player_sprite = pygame.sprite.Group(player)
|
||||||
|
|
||||||
# Define game states
|
# Менюм / Игровой режим
|
||||||
class GameState:
|
class GameState:
|
||||||
MENU = 0
|
MENU = 0
|
||||||
GAMEPLAY = 1
|
GAMEPLAY = 1
|
||||||
|
@ -149,16 +149,16 @@ while running:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
if current_state == GameState.MENU:
|
if current_state == GameState.MENU:
|
||||||
# Handle mouse clicks in the menu state
|
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||||
mouse_x, mouse_y = pygame.mouse.get_pos()
|
mouse_x, mouse_y = pygame.mouse.get_pos()
|
||||||
|
|
||||||
if play_button.is_hovered((mouse_x, mouse_y)):
|
if play_button.is_hovered((mouse_x, mouse_y)):
|
||||||
# Transition to the gameplay state
|
# Переход в игровой режим
|
||||||
current_state = GameState.GAMEPLAY
|
current_state = GameState.GAMEPLAY
|
||||||
|
|
||||||
elif current_state == GameState.GAMEPLAY:
|
elif current_state == GameState.GAMEPLAY:
|
||||||
# Handle events in the gameplay state
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_e:
|
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))
|
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()
|
background_img_image = pygame.image.load(BACKGROUND_IMAGE).convert_alpha()
|
||||||
screen.blit(background_img_image, (0, 0))
|
screen.blit(background_img_image, (0, 0))
|
||||||
|
|
||||||
# Меню
|
|
||||||
if current_state == GameState.MENU:
|
if current_state == GameState.MENU:
|
||||||
screen.blit(play_button.image, play_button.rect)
|
screen.blit(play_button.image, play_button.rect)
|
||||||
screen.blit(continue_button.image, continue_button.rect)
|
screen.blit(continue_button.image, continue_button.rect)
|
||||||
screen.blit(menu_button.image, menu_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:
|
elif current_state == GameState.GAMEPLAY:
|
||||||
# Обновить игрока
|
# Обновить игрока
|
||||||
player.update_position(5, 0)
|
player.update_position(5, 0)
|
||||||
|
@ -195,14 +200,6 @@ while running:
|
||||||
for sprite in player_sprite:
|
for sprite in player_sprite:
|
||||||
screen.blit(sprite.image, camera.apply(sprite.rect))
|
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()
|
pygame.display.flip()
|
||||||
deltatime = clock.tick(FPS) / 1000
|
deltatime = clock.tick(FPS) / 1000
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue