Skip to content

Commit

Permalink
v0.7.3
Browse files Browse the repository at this point in the history
# Реализовано меню
# Добавлены мелкие наработки
  • Loading branch information
Terfdas12 authored Jun 22, 2021
1 parent 33b5997 commit 6febbf7
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 37 deletions.
199 changes: 166 additions & 33 deletions CaveX.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ class Events: # Игровые события
isGameLoosed = False # Проиграна ли игра
isStatisticShown = False # Отображена ли статистика
isPause = False # Открыто ли меню паузы
isGameStart = False
isSaveMenu = False
isSettingsMenu = False
isMenu = True

@staticmethod
def get_game_events(): # Ивенты игрового блока
Expand Down Expand Up @@ -532,6 +536,93 @@ def show(self):
elif pygame.key.get_pressed()[pygame.K_SPACE]:
exit()

def blit(self):
self.screen.blit(self.surf, self.position)

class SaveMenu(Surface):
def __init__(self, screen):
super().__init__(screen, DISPLAY_SIZE, (0, 0))
self.font = pygame.font.Font("font.ttf", FONT_SIZE)
self.font2 = pygame.font.Font("font.ttf", FONT_SIZE-35)
self.time = get_time()


def add_save(self,index):
tmp_pos = PIXEL_SIZE*6
title = self.font2.render(f"Lvl: 0", 1, WHITE)
self.screen.blit(title, (50, tmp_pos + 400))
title = self.font2.render(f"Time: {self.time}", 1, WHITE)
self.screen.blit(title, (370, tmp_pos + 400))

def show(self):
self.surf.fill(RED)
self.blit()
tmp_pos = PIXEL_SIZE*6
title = self.font.render(f"Save menu", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0]/3)-50, tmp_pos+50))
title = self.font.render(f"Save menu", 1, BLACK)
self.screen.blit(title, (int(STATUS_BAR[0]/3)-48, tmp_pos+52))
title = self.font.render(f"Save slot 1", 1, WHITE)
self.screen.blit(title, (50, tmp_pos + 300))
title = self.font.render(f"Save slot 2", 1, WHITE)
self.screen.blit(title, (50, tmp_pos + 450))
title = self.font.render(f"Save slot 3", 1, WHITE)
self.screen.blit(title, (50, tmp_pos + 600))
pygame.display.flip()


def rectangle (self):

x, y = pygame.mouse.get_pos()
for i in range(3):
if LUC_SAVE_BUTTON[i][0] <= x <= (SAVE_MENU_BUTTON[i][0] + LUC_SAVE_BUTTON[i][0]) and \
LUC_SAVE_BUTTON[i][1] <= y <= (SAVE_MENU_BUTTON[i][1] + LUC_SAVE_BUTTON[i][1]):
pygame.draw.rect(self.screen, WHITE, (LUC_SAVE_BUTTON[i], SAVE_MENU_BUTTON[i]), 4)
if i==0 :self.add_save(1)

return True, i
else:
return False, -1

def blit(self):
self.screen.blit(self.surf, self.position)

class MainMenu(Surface):
def __init__(self, screen, play, settings):
super().__init__(screen, DISPLAY_SIZE, (0, 0))
self.font = pygame.font.Font("font.ttf", FONT_SIZE)
self.button = [play, settings]

def show(self):
self.surf.fill(RED)
self.blit()
tmp_pos = PIXEL_SIZE*6
title = self.font.render(f"CaveX {VERSION}", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0]/3)-75, tmp_pos+50))
title = self.font.render(f"CaveX {VERSION}", 1, BLACK)
self.screen.blit(title, (int(STATUS_BAR[0]/3)-73, tmp_pos+52))
title = self.font.render(f"Play", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0] / 3) + 15, tmp_pos+300))
title = self.font.render(f"Load", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0] / 3) + 35, tmp_pos + 400))
title = self.font.render(f"Settings", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0] / 3) - 35, tmp_pos + 500))
title = self.font.render(f"Exit", 1, WHITE)
self.screen.blit(title, (int(STATUS_BAR[0] / 3) + 35, tmp_pos + 600))
pygame.display.flip()

def rectangle (self):
x, y = pygame.mouse.get_pos()
for i in range(4):
if LUC_MENU_BUTTON[i][0] <= x <= (SIZE_MENU_BUTTON[i][0] + LUC_MENU_BUTTON[i][0]) and \
LUC_MENU_BUTTON[i][1] <= y <= (SIZE_MENU_BUTTON[i][1] + LUC_MENU_BUTTON[i][1]):
pygame.draw.rect(self.screen, WHITE, (LUC_MENU_BUTTON[i], SIZE_MENU_BUTTON[i]), 4)
return True, i
else: return False, -1




def blit(self):
self.screen.blit(self.surf, self.position)

Expand All @@ -540,8 +631,8 @@ class PauseMenu(Surface):
def __init__(self, screen):
super().__init__(screen, DISPLAY_SIZE, (0, 0))
self.font = pygame.font.Font("font.ttf", FONT_SIZE)
self.stat_font = pygame.font.Font("font.ttf", STAT_FONT_SIZE)
self.button = []
self.name = None

def show(self):
self.surf.fill(RED)
Expand All @@ -562,14 +653,11 @@ def show(self):
def rectangle(self):
x, y = pygame.mouse.get_pos()
for i in range(3):
if LUC_PAUSE_BUTTON[i][0]<=x<=(SIZE_PAUSE_BUTTON[i][0]+LUC_PAUSE_BUTTON[i][0]) and LUC_PAUSE_BUTTON[i][1]<=y<=(SIZE_PAUSE_BUTTON[i][1]+LUC_PAUSE_BUTTON[i][1]):
if LUC_PAUSE_BUTTON[i][0] <= x <= (SIZE_PAUSE_BUTTON[i][0]+LUC_PAUSE_BUTTON[i][0]) and \
LUC_PAUSE_BUTTON[i][1] <= y <= (SIZE_PAUSE_BUTTON[i][1]+LUC_PAUSE_BUTTON[i][1]):
pygame.draw.rect(self.screen, WHITE,(LUC_PAUSE_BUTTON[i],SIZE_PAUSE_BUTTON[i]), 4)
pressed = pygame.mouse.get_pressed()
if pressed[0]:
if i == 2:
exit()
else:
print(i)
return True, i
else: return False, -1

def blit(self):
self.screen.blit(self.surf, self.position)
Expand Down Expand Up @@ -598,6 +686,12 @@ def __init__(self):
self.timer = 0
self._map = None
self._hero = None
self.BMenu = False
self.buttonmenu = -1
self.BSave = False
self.buttonsave = -1
self.BPause = False
self.buttonpause = -1

if DEBUG: self.debug_cords = None

Expand Down Expand Up @@ -672,7 +766,9 @@ def start(self):
self.player_bar = PlayerBar(self.screen, self._hero)
self.statistic = Statistic(self.screen)
self.pausemenu = PauseMenu(self.screen)

self.savemenu = SaveMenu(self.screen)
self.settings = None
self.menu = MainMenu(self.screen, self.savemenu, self.settings)
self._map.render() # Рисуем карту
self.game.blit()
self.mainloop() # Цикл игры
Expand All @@ -682,30 +778,67 @@ def mainloop(self):
run = True
while run:
clock.tick(FPS) # Количество кадров в секунду
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Events.isPause = not Events.isPause
self.check_losed_game()
if Events.isGameLoosed:
self.statistic.show()
continue
if not Events.isPause:
self.player_movement()
self.units_action()
self.game.blit()
self.game_bar.blit()
self.player_bar.blit()
else:
self.pausemenu.show()
self.pausemenu.rectangle()


self.game.update()
self.game_bar.update()
self.player_bar.update()
if Events.isMenu:
self.menu.show()
self.BMenu, self.buttonmenu = self.menu.rectangle()
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif self.BMenu and event.type == pygame.MOUSEBUTTONDOWN:
if self.buttonmenu == 0 and event.button == 1:
Events.isMenu = False
Events.isGameStart = True
if self.buttonmenu == 1 and event.button == 1:
Events.isSaveMenu = True
Events.isMenu = False
if self.buttonmenu == 2 and event.button == 1:
exit()
elif Events.isSaveMenu:
self.savemenu.show()
self.BSave, self.buttonsave = self.savemenu.rectangle()
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
if not Events.isGameStart:
Events.isSaveMenu = False
Events.isMenu = True
else:
Events.isSaveMenu = False
Events.isPause = True
elif self.BSave and event.type == pygame.MOUSEBUTTONDOWN:
if self.buttonsave == 1 or self.buttonsave == 0:
print(f"Play Menu {self.buttonsave}")
elif Events.isGameStart:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Events.isPause = not Events.isPause
elif self.BPause and event.type == pygame.MOUSEBUTTONDOWN:
if self.buttonpause == 0 and event.button == 1:
Events.isSaveMenu = True
Events.isPause = False
elif self.buttonpause == 2 and event.button == 1:
exit()
self.check_losed_game()
if Events.isGameLoosed:
self.statistic.show()
continue
elif not (Events.isPause or Events.isSaveMenu):
self.player_movement()
self.units_action()
self.game.blit()
self.game_bar.blit()
self.player_bar.blit()
else:
self.pausemenu.show()
self.BPause, self.buttonpause = self.pausemenu.rectangle()
self.game.update()
self.game_bar.update()
self.player_bar.update()
pygame.display.flip()
# <<< Запуск игры

Expand Down
11 changes: 7 additions & 4 deletions Settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import time

VERSION = "0.7.2"
# Реализована пауза
# Сделана заготовка под меню с реагированием на нажатие определенный кнопки (вывод индекса кнопки в консоль или выход)
# Добавлена обводка части меню, на котором находиться курсор
VERSION = "0.7.3"
# Реализовано меню
# Добавлены мелкие наработки

# Константы
LOGGING = True # Логи разработчика
Expand Down Expand Up @@ -41,6 +40,10 @@
TAIL = {"up": (0, __FACE_NUM), "down": (0, __FACE_NUM), "left": (__FACE_NUM, 0), "right": (__FACE_NUM, 0)}
SIZE_PAUSE_BUTTON = [(164, 61), (269, 61), (125, 61)]
LUC_PAUSE_BUTTON = [(236, 374), (186, 474), (256, 574)]
SAVE_MENU_BUTTON = [(571, 61*2), (571, 61*2), (571, 61*2)]
LUC_SAVE_BUTTON = [(46, 374), (46, 524), (46, 674)]
SIZE_MENU_BUTTON = [(144, 61), (160, 61), (269, 61), (125, 61)]
LUC_MENU_BUTTON = [(236, 374), (256, 474),(186, 574), (256, 674) ]



Expand Down

0 comments on commit 6febbf7

Please sign in to comment.