add first steps for LevelMenu
parent
f8a46052e7
commit
4aef777081
|
@ -14,6 +14,7 @@ from sprite.Sprite import Sprite
|
||||||
from sprite.StaticSprite import StaticSprite
|
from sprite.StaticSprite import StaticSprite
|
||||||
from ui_elements.ClickEvent import ClickEvent
|
from ui_elements.ClickEvent import ClickEvent
|
||||||
from ui_elements.KeyManager import KeyManager
|
from ui_elements.KeyManager import KeyManager
|
||||||
|
from ui_elements.LevelMenu import LevelMenu
|
||||||
from ui_elements.TextLabel import TextLabel
|
from ui_elements.TextLabel import TextLabel
|
||||||
|
|
||||||
what_to_run = 'level'
|
what_to_run = 'level'
|
||||||
|
@ -29,7 +30,52 @@ def apply_frame_rate(number: float):
|
||||||
return number / (frame_rate / 30)
|
return number / (frame_rate / 30)
|
||||||
|
|
||||||
|
|
||||||
if what_to_run == 'level':
|
if what_to_run == 'menu':
|
||||||
|
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
screen = pygame.display.set_mode((12 * 71 * 1.5, 12 * 40 * 1.5))
|
||||||
|
pygame.display.set_caption("PM GAME")
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
frame_rate = 30
|
||||||
|
|
||||||
|
spritesheet_manager = SpritesheetManager("data/sprites", "data/sprites/sprites.json")
|
||||||
|
sprite_manager = SpriteManager()
|
||||||
|
key_manager = KeyManager()
|
||||||
|
|
||||||
|
parsed_levels_manager = LevelManager('data/levels')
|
||||||
|
parsed_levels_manager.load_from_config('data/levels/levels.json')
|
||||||
|
|
||||||
|
generated_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
||||||
|
|
||||||
|
level_menu = LevelMenu(parsed_levels_manager.levels, 0, 0)
|
||||||
|
level_menu.level_select_listener = lambda selected_level: print(selected_level.name, "selected")
|
||||||
|
# generated_level.load_level(selected_level)
|
||||||
|
|
||||||
|
for level_text_label in level_menu.level_text_labels:
|
||||||
|
sprite_manager.add_ui_element(DrawLayers.UI, level_text_label)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
clock.tick(frame_rate)
|
||||||
|
|
||||||
|
pygame_events: list[pygame.event.Event] = pygame.event.get()
|
||||||
|
key_manager.update_key_events(pygame_events)
|
||||||
|
click_events: list[ClickEvent] = ClickEvent.create_events(pygame_events, screen_transform)
|
||||||
|
|
||||||
|
for event in pygame_events:
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
quit()
|
||||||
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
generated_level.load_level(parsed_levels_manager.levels[0])
|
||||||
|
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
# level_menu.draw(screen, screen_transform)
|
||||||
|
sprite_manager.tick(TickData(apply_frame_rate(1), pygame_events, key_manager, click_events, screen_transform))
|
||||||
|
sprite_manager.draw(screen, screen_transform)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
elif what_to_run == 'level':
|
||||||
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
screen_transform = PositionScale((0, 0), (1.5, 1.5))
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
from level.Level import Level
|
||||||
|
from ui_elements.TextLabel import TextLabel
|
||||||
|
|
||||||
|
|
||||||
|
class LevelMenu:
|
||||||
|
|
||||||
|
def __init__(self, levels: [Level], x_pos: int, y_pos: int):
|
||||||
|
self.levels = levels
|
||||||
|
self.x_pos = x_pos
|
||||||
|
self.y_pos = y_pos
|
||||||
|
self.level_select_listener = lambda selected_level: None
|
||||||
|
self.level_text_labels = []
|
||||||
|
|
||||||
|
self.create_level_text_labels()
|
||||||
|
|
||||||
|
def create_level_text_labels(self):
|
||||||
|
current_text_label_x = self.x_pos
|
||||||
|
current_text_label_y = self.y_pos
|
||||||
|
|
||||||
|
for index, level in enumerate(self.levels):
|
||||||
|
# name=extraxt_level(level.name)
|
||||||
|
text_label = TextLabel(level.name, current_text_label_x, current_text_label_y, 35)
|
||||||
|
text_label.add_click_listener(lambda: self.level_select_listener(level))
|
||||||
|
|
||||||
|
if (index + 1) % 3 == 0:
|
||||||
|
current_text_label_y += text_label.current_height + text_label.current_height / 4
|
||||||
|
current_text_label_x = self.x_pos
|
||||||
|
else:
|
||||||
|
current_text_label_x += text_label.current_width + text_label.current_width / 3
|
||||||
|
self.level_text_labels.append(text_label)
|
||||||
|
if current_text_label_x % 10 != 0:
|
||||||
|
current_text_label_x = current_text_label_x + current_text_label_x % 10
|
||||||
|
# menu_labels.append(text_label)
|
||||||
|
|
||||||
|
def extract_level(name):
|
||||||
|
return name
|
Loading…
Reference in New Issue