main
parent
58fbf688dd
commit
328e703f89
39
main.py
39
main.py
|
@ -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,31 +177,28 @@ 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)
|
||||
player.change_movement('right')
|
||||
player.draw()
|
||||
# Обновить игрока
|
||||
player.update_position(5, 0)
|
||||
player.change_movement('right')
|
||||
player.draw()
|
||||
|
||||
for sprite in character_sprites:
|
||||
screen.blit(sprite.image, camera.apply(sprite.rect))
|
||||
for sprite in character_sprites:
|
||||
screen.blit(sprite.image, camera.apply(sprite.rect))
|
||||
|
||||
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)
|
||||
for sprite in player_sprite:
|
||||
screen.blit(sprite.image, camera.apply(sprite.rect))
|
||||
|
||||
pygame.display.flip()
|
||||
deltatime = clock.tick(FPS) / 1000
|
||||
|
|
Loading…
Reference in New Issue