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.
4Most of the logic is in menugui.MenuGUI()
5"""
6import pygame as pg
7from .. import tools, setup, menugui
8from .. import constants as c
9
10
11class Player_Menu(object):
12 def __init__(self, game_data, level):
13 inventory = game_data['player inventory']
14 stats = game_data['player stats']
15 self.get_image = tools.get_image
16 self.allow_input = False
17 self.background = self.make_background()
18 self.gui = menugui.MenuGui(level, inventory, stats)
19
20 def make_background(self):
21 """
22 Makes the generic black/blue background.
23 """
24 background = pg.sprite.Sprite()
25 surface = pg.Surface(c.SCREEN_SIZE).convert()
26 surface.fill(c.BLACK_BLUE)
27 background.image = surface
28 background.rect = background.image.get_rect()
29
30 player = self.make_sprite('player', 96, 32)
31
32 background.image.blit(player.image, player.rect)
33
34 return background
35
36 def make_sprite(self, key, coordx, coordy, x=40, y=25):
37 """
38 Get the image for the player.
39 """
40 spritesheet = setup.GFX[key]
41 surface = pg.Surface((32, 32))
42 surface.set_colorkey(c.BLACK)
43 image = self.get_image(coordx, coordy, 32, 32, spritesheet)
44 rect = image.get_rect()
45 surface.blit(image, rect)
46
47 surface = pg.transform.scale(surface, (192, 192))
48 rect = surface.get_rect(left=x, top=y)
49 sprite = pg.sprite.Sprite()
50 sprite.image = surface
51 sprite.rect = rect
52
53 return sprite
54
55 def update(self, surface, keys):
56 self.gui.update(keys)
57 self.draw(surface)
58
59 def draw(self, surface):
60 surface.blit(self.background.image, self.background.rect)
61 self.gui.draw(surface)
62