-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
55 lines (48 loc) · 2.29 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Defines the player class"""
import pyxel
from const import ICON_WIDTH, ICON_HEIGHT
from shop import INVENTORY_BOX_BORDER_THICKNESS
import marker
class Player:
"""A class representing the player character"""
def __init__(self):
self.funding = 100
self.inventory = []
self.global_buffs = []
def add_funding(self, funding_to_add):
"""Adds to the player's available funding"""
self.funding += funding_to_add
def add_inventory(self, new_markers):
"""Adds a list of markers to the player's inventory"""
self.inventory += new_markers
def add_global_buffs(self, global_buffs):
"""Takes in a list of global buffs and adds them to the player's global buffs"""
self.global_buffs += global_buffs
def draw_inventory(self, x_coord, y_coord, width, height):
"""Draws the icons of each item in the player's inventory to the screen starting at x, y in a region of
width x length"""
row_count = 0
for i in range(len(self.inventory)):
if i*ICON_WIDTH-row_count*(width//ICON_WIDTH) > width:
row_count += i
if (row_count+1)*ICON_HEIGHT > height:
break
pyxel.blt(x_coord+(i*ICON_WIDTH)+(i*2*INVENTORY_BOX_BORDER_THICKNESS),
y_coord+(row_count+ICON_HEIGHT),
0,
marker.markers[self.inventory[i]].icon_coords[0],
marker.markers[self.inventory[i]].icon_coords[1],
ICON_WIDTH,
ICON_HEIGHT, 0)
def draw_global_buffs(self, x_coord, y_coord, width, height):
"""Draws the icons of each item in the player's inventory to the screen starting at x, y in a region of
width x length"""
row_count = 0
for i in range(len(self.global_buffs)):
if i*ICON_WIDTH-row_count*(width//ICON_WIDTH) > width:
row_count += i
if (row_count+1)*ICON_HEIGHT > height:
break
pyxel.blt(x_coord+(i*ICON_WIDTH)+(i*2*INVENTORY_BOX_BORDER_THICKNESS), y_coord+(row_count+ICON_HEIGHT), 0,
marker.markers[self.global_buffs[i]].icon_coords[0],
marker.markers[self.global_buffs[i]].icon_coords[1], ICON_WIDTH, ICON_HEIGHT, 0)