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