all repos — Legends-RPG @ 97226ef32d8c0fe20424beca13a494787cc000a4

A fantasy mini-RPG built with Python and Pygame.

data/states/player_menu.py (view raw)

 1"""
 2This is the state where the player can look at
 3his inventory, equip items and check stats.
 4"""
 5import pygame as pg
 6from .. import tools, setup, menugui
 7from .. import constants as c
 8
 9
10class Player_Menu(tools._State):
11    def __init__(self):
12        super(Player_Menu, self).__init__()
13        self.get_image = tools.get_image
14
15
16
17    def startup(self, current_time, game_data):
18        """Call when state is switched to"""
19        inventory = game_data['player inventory']
20        self.next = game_data['last state']
21        self.allow_input = False
22        self.game_data = game_data
23        self.current_time = current_time
24        self.background = self.make_background()
25        self.gui = menugui.MenuGui(self, inventory)
26
27
28    def make_background(self):
29        """Makes the generic black/blue background"""
30        background = pg.sprite.Sprite()
31        surface = pg.Surface(c.SCREEN_SIZE).convert()
32        surface.fill(c.BLACK_BLUE)
33        background.image = surface
34        background.rect = background.image.get_rect()
35
36        player = self.make_sprite('player', 96, 32)
37
38        background.image.blit(player.image, player.rect)
39
40        return background
41
42
43    def make_sprite(self, key, coordx, coordy, x=40, y=25):
44        """Get the image for the player"""
45        spritesheet = setup.GFX[key]
46        surface = pg.Surface((32, 32))
47        surface.set_colorkey(c.BLACK)
48        image = self.get_image(coordx, coordy, 32, 32, spritesheet)
49        rect = image.get_rect()
50        surface.blit(image, rect)
51
52        surface = pg.transform.scale(surface, (192, 192))
53        rect = surface.get_rect(left=x, top=y)
54        sprite = pg.sprite.Sprite()
55        sprite.image = surface
56        sprite.rect = rect
57
58        return sprite
59
60
61    def update(self, surface, keys, current_time):
62        self.gui.update(keys)
63        self.draw(surface)
64
65
66    def draw(self, surface):
67        surface.blit(self.background.image, self.background.rect)
68        self.gui.draw(surface)
69