-
Notifications
You must be signed in to change notification settings - Fork 8
/
itemEffects.py
171 lines (136 loc) · 5.76 KB
/
itemEffects.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
# -*- coding: utf-8 -*-
# Screaming Strike item effects
# Copyright (C) 2019 Yukio Nozawa <[email protected]>
# License: GPL V2.0 (See copying.txt for details)
import math
import bgtsound
import random
import globalVars
import itemConstants
import window
class ItemEffectBase(object):
def initialize(self, player, onSound, offSound, name):
self.paused = False
self.player = player
self.active = False
self.timer = window.Timer()
self.onSound = onSound
self.offSound = offSound
self.lasts = itemConstants.BASE_EFFECT_TIME
self.name = name
self.on = None
self.off = None
self.ex = None
def activate(self, mode):
self.on = bgtsound.sound()
self.on.load(self.onSound)
self.on.play()
self.active = True
self.timer.restart()
self.player.field.log(_("A new \"%(item)s\" effect is starting!") % {"item": self.name})
def deactivate(self, mode):
self.off = bgtsound.sound()
self.off.load(self.offSound)
self.off.play()
self.active = False
self.player.field.log(_("One of your \"%(item)s\" effects is ending!") % {"item": self.name})
def extend(self, ms):
self.ex = bgtsound.sound()
self.ex.load(self.onSound)
self.ex.pitch = 130
self.ex.play()
self.lasts += ms
self.player.field.log(_("Your \"%(item)s\" effect has been extended for %(extended)d milliseconds! (now %(newtime)d)") %
{"item": self.name, "extended": ms, "newtime": self.lasts - self.timer.elapsed})
def summarize(self):
"""Returns the summary of this effect.
:rtype: str
"""
return _("%(name)s: %(sec).2f seconds left") % {"name": self.name, "sec": self.calculateTimeRemaining()}
def calculateTimeRemaining(self):
"""
Calculates the time after which this item expires in seconds.
:rtype: float
"""
return (self.lasts - self.timer.elapsed) / 1000
def frameUpdate(self, mode):
if self.active is not True:
return False
if self.timer.elapsed >= self.lasts:
self.deactivate(mode)
return False
return True
def setPaused(self, p):
"""Pauses / unpauses this effect."""
if p == self.paused:
return
self.paused = p
self.timer.setPaused(p)
if self.on:
self.on.setPaused(p)
if self.off:
self.off.setPaused(p)
if self.ex:
self.ex.setPaused(p)
# end setPaused
class ShrinkEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["shrink.ogg"], globalVars.appMain.sounds["shrinkFade.ogg"], "Shrink")
def activate(self, mode):
super().activate(mode)
self.player.setPunchRange(math.floor(self.player.punchRange * mode.getShrinkMultiplier()))
def deactivate(self, mode):
super().deactivate(mode)
self.player.setPunchRange(math.ceil(self.player.punchRange / mode.getShrinkMultiplier()))
class BlurredEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["blurred.ogg"], globalVars.appMain.sounds["blurredFade.ogg"], "Blurred")
def frameUpdate(self, mode):
if super().frameUpdate(mode) is False:
return False
if random.randint(1, 10) == 1:
while(True):
d = random.randint(0, self.player.field.getX() - 1)
if d != self.player.x:
break
# end while
self.player.moveTo(d)
# whether to trigger blurring?
return True
# end frameUpdate
class SlowDownEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["slowDown.ogg"], globalVars.appMain.sounds["slowDownFade.ogg"], "Slow down")
def activate(self, mode):
super().activate(mode)
self.player.setPunchSpeed(self.player.punchSpeed * mode.getSlowDownMultiplier())
def deactivate(self, mode):
super().deactivate(mode)
self.player.setPunchSpeed(self.player.punchSpeed / mode.getSlowDownMultiplier())
class MegatonPunchEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["megatonPunch.ogg"], globalVars.appMain.sounds["megatonPunchFade.ogg"], "Megaton punch")
def activate(self, mode):
super().activate(mode)
self.player.setPunchRange(self.player.punchRange * 5)
def deactivate(self, mode):
super().deactivate(mode)
self.player.setPunchRange(self.player.punchRange / 5)
class BoostEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["boost.ogg"], globalVars.appMain.sounds["boostFade.ogg"], "Boost")
def activate(self, mode):
super().activate(mode)
self.player.setPunchSpeed(self.player.punchSpeed / 2)
def deactivate(self, mode):
super().deactivate(mode)
self.player.setPunchSpeed(self.player.punchSpeed * 2)
class PenetrationEffect(ItemEffectBase):
def initialize(self, player):
super().initialize(player, globalVars.appMain.sounds["penetration.ogg"], globalVars.appMain.sounds["penetrationFade.ogg"], "Penetration")
def activate(self, mode):
super().activate(mode)
self.player.setPenetration(True)
def deactivate(self, mode):
super().deactivate(mode)
self.player.setPenetration(False)