-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
66 lines (56 loc) · 1.73 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
56
57
58
59
60
61
62
63
64
65
66
import pygame, entity, items, config
from inventory import *
BASE_STATS = ['coins','gears','karma','speed_mod']
class Player(entity.Entity):
coins = 0
gears = 0
karma = 0
inventory = False
def __init__(self, tileX, tileY, colliders):
super(Player, self).__init__('player', tileX, tileY, colliders)
self.inventory = Inventory()
def pickup(self, tile_items):
coords = str(self.tile[0]) + ':' + str(self.tile[1])
if coords in tile_items and tile_items[coords].pickup:
item = tile_items[coords]
if item.type == items.RESOURCE:
self.useItem(item)
else:
self.inventory.addItem(item)
del tile_items[coords]
if item.owner != 0:
print("Stole the '" + item.name + "' item")
self.karma -= 2
print("Lost " + str(item.karma) + " karma")
else:
print("Picked up the '" + item.name + "' item")
return True
return False
def useItem(self, item):
if not item.consumable:
return
if item.coins > 0:
self.coins += item.coins
print("Gained " + str(item.coins) + " coins")
elif item.coins < 0:
self.coins += item.coins
print("Lost " + str(item.coins) + " coins")
if item.karma < 0:
self.karma += item.karma
print("Lost " + str(item.karma) + " karma")
elif item.karma > 0:
self.karma += item.karma
print("Gained " + str(item.karma) + " karma")
if item.gears < 0:
self.gears += item.gears
print("Lost " + str(item.gears) + " gears")
elif item.gears > 0:
self.gears += item.gears
print("Gained " + str(item.gears) + " gears")
if item.speed < 0:
self.speed_mod += item.speed
print("Lost " + str(item.speed) + " speed")
elif item.speed > 0:
self.speed_mod += item.speed
print("Gained " + str(item.speed) + " speed")
item.special_effect(self)