-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitems.py
213 lines (167 loc) · 6.68 KB
/
items.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import global_values as g
import graphics as gfx
import entities
import particles
import creatures
import levels
import actions
import sounds
import pygame as p
import random as r
import math as m
class Item:
def __init__(self, name):
self.name = name
try:
self.icon = gfx.load_image(name+"_icon")
except:
self.icon = None
try:
self.surface = gfx.load_image(name)
except:
self.surface = None
self.amount = 1
def pickup(self):
pass
def __getstate__(self):
return gfx.pickle_state(self.__dict__)
def __setstate__(self, state):
self.__dict__ = gfx.unpickle_state(state)
class Consumable(Item):
def __init__(self, name):
super().__init__(name)
def consume(self):
pass
class Medkit(Consumable):
def __init__(self):
super().__init__("Medkit")
def consume(self):
super().consume()
g.player.change_health(3)
class HealthDrink(Consumable):
def __init__(self):
super().__init__("Vit Drink")
def consume(self):
super().consume()
actions.VarChangeAction( g.player.pipe, 6, g.player, "health", g.player.health+3, blocking=False, blockable=False, force=False, max_val=g.player.max_health)
class Ammunition(Item):
def __init__(self, name, gun_name, ammunition_amount):
self.gun_name = gun_name
self.ammunition_amount = ammunition_amount
super().__init__(name)
def pickup(self):
super().pickup()
gun = g.player.inventory.check_for_named_item(self.gun_name)
if gun:
gun.change_ammunition(self.ammunition_amount)
else:
g.player.inventory.ammunition_reserves[self.gun_name] = g.player.inventory.ammunition_reserves.get(self.gun_name, 0) + self.ammunition_amount
g.player.inventory.remove(self)
class HandgunAmmunition(Ammunition):
def __init__(self):
super().__init__("H. ammo", "Handgun", 10)
class ShotgunAmmunition(Ammunition):
def __init__(self):
super().__init__("S. ammo", "Shotgun", 5)
class RevolverAmmunition(Ammunition):
def __init__(self):
super().__init__("R. ammo", "Revolver", 3)
class Gun(Item):
def __init__(self, name, damage, cooldown, fire_range, projectiles=1, spread=0, max_ammunition=50, recharge=0, stun=0, fire_effect=1):
super().__init__(name)
self.damage = damage
self.max_cooldown = cooldown
self.range = fire_range
self.last_fire_time = None
self.max_ammunition = max_ammunition
self.ammunition = int(self.max_ammunition*0.2)
self.recharge = recharge
self.stun = stun
self.fire_effect = fire_effect
self.projectiles = projectiles
self.spread = spread
self.holder = None
def attempt_fire(self):
if self.ammunition >= 1:
if not self.last_fire_time or (p.time.get_ticks()-self.last_fire_time)/1000 >= self.max_cooldown:
self.fire()
self.change_ammunition(-1)
self.ammunition = int(self.ammunition)
self.last_fire_time = p.time.get_ticks()
return True
return False
def change_ammunition(self, amount):
self.ammunition += amount
if self.ammunition < 0:
self.ammunition = 0
if self.ammunition >= self.max_ammunition:
self.ammunition = self.max_ammunition
def fire(self):
"""
Fire weapon
"""
#I am lazy
if self.holder is None:
self.holder = g.player
sounds.play_sound(self.name+"_fire", volume=0.5)
for _ in range(self.projectiles):
angle = self.holder.angle + ((r.random()-0.5)*self.spread)
bullet_rect = p.Rect(self.holder.rect.centerx, self.holder.rect.centery, 1, 1)
bullet_mask = p.mask.Mask((bullet_rect.w, bullet_rect.h), fill=True)
bullet_mask.fill()
bullet = entities.Entity(bullet_rect,
self.holder.level, collision_exceptions=[self.holder], solid=False, mask=bullet_mask)
target_x = self.holder.rect.centerx + m.cos(angle)*self.range
target_y = self.holder.rect.centery + m.sin(angle)*self.range
result = bullet.move_towards(target_x, target_y, self.range, detail=True)
if result:
if isinstance(result, creatures.Creature):
if bullet.y < result.rect.bottom-(result.rect.h*0.70):
#boom, headshot
damage = self.damage*1.5
headshot = True
else:
damage = self.damage
headshot = False
if self.damage > 0:
particles.create_blood(bullet.level, (bullet.x, bullet.y), self.holder.angle + m.pi ,headshot=headshot)
result.take_damage(damage, source=self.holder)
if self.stun:
result.stun(self.stun)
if isinstance(result, levels.Level) and self.damage:
#level, position, angle, colour, spread, amount, power, timer
particles.Particles(bullet.level, (bullet.x, bullet.y), self.holder.angle + m.pi, g.colour_remaps["beige"], 1, 5, 5, 10)
else:
pass
bullet.delete()
#guns
class Handgun(Gun):
def __init__(self):
super().__init__("Handgun", 1, 0.5, 200)
class Shotgun(Gun):
def __init__(self):
super().__init__("Shotgun", 0.8, 1, 100, projectiles=5, spread=0.5, max_ammunition=25, recharge=0)
class Stungun(Gun):
def __init__(self):
super().__init__("Stungun", 0.0, 1.5, 20, projectiles=1, spread=0, max_ammunition=3, recharge=0.4, stun=5, fire_effect=2)
self.ammunition = self.max_ammunition
class Revolver(Gun):
def __init__(self):
super().__init__("Revolver", 5, 1.5, 300, projectiles=1, spread=0, max_ammunition=6)
#keys
class BathroomKey(Item):
def __init__(self):
super().__init__("K. Bath")
class ReactorKey(Item):
def __init__(self):
super().__init__("K. Reactor")
class StorageKey(Item):
def __init__(self):
super().__init__("K. Store")
def create_item(name):
"""
Create item from name
"""
# XXX be careful what you name your items (._.)
new_item = eval(f"{name}()")
return new_item