Slight prettier but much hackier keypad requirement color.
[koperkapel.git] / koperkapel / gamelib / keypad.py
1 # A doors / keypads set
2
3 import os
4 from pgzero.loaders import images
5 from pgzero.ptext import getsurf
6 from ..actors.orientatedsurf import SurfActor
7
8
9 class Keypad(SurfActor):
10
11     def __init__(self, x, y, doors, required_smart=0):
12         self._doors = doors
13         self.game_pos = (x, y)
14         self.required_smart = required_smart
15         surf = images.load(os.path.join('fixtures', 'keypad')).copy()
16         ocolor = (96, 96, 128, 255)
17         surf.blit(getsurf(
18             str(required_smart), owidth=2,
19             ocolor=ocolor, color="black"), (0, 0))
20         super().__init__(surf, anchor=(1, 1))
21
22     def activate(self, smart):
23         if smart >= self.required_smart:
24             for door in self._doors:
25                 if door.is_closed():
26                     door.open()
27                 else:
28                     door.close()
29         else:
30             print("You are not smart enough for this keypad.")