all repos — Legends-RPG @ 29279f0d4ae0de678743f8baccb7574024b042e1

A fantasy mini-RPG built with Python and Pygame.

data/states/main_menu/main_menu.py (view raw)

 1import pygame as pg
 2from ... import setup, tools
 3from ... import constants as c
 4
 5class Menu(tools._State):
 6    def __init__(self):
 7        super(Menu, self).__init__()
 8        self.next = c.OVERWORLD
 9        self.surface = setup.SCREEN
10        self.rect = self.surface.get_rect()
11        text = 'Arrows for navigation, space for input, Enter/Return for menu'
12        self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22)
13        self.rendered_text = self.font.render(text, 1, c.BLACK)
14        self.text_rect = self.rendered_text.get_rect()
15        self.text_rect.center = self.rect.center
16        self.game_data = tools.create_game_data_dict()
17        self.name = c.MAIN_MENU
18
19
20    def update(self, surface, keys, current_time):
21        self.current_time = current_time
22        surface.fill(c.WHITE)
23        surface.blit(self.rendered_text, self.text_rect)
24
25    def get_event(self, event):
26        if event.type == pg.KEYDOWN:
27            self.game_data['last state'] = self.name
28            self.done = True