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