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