-
Notifications
You must be signed in to change notification settings - Fork 8
/
item.py
115 lines (101 loc) · 4.15 KB
/
item.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
# -*- coding: utf-8 -*-
# Screaming Strike item handler
# Copyright (C) 2019 Yukio Nozawa <[email protected]>
# License: GPL V2.0 (See copying.txt for details)
import random
import bgtsound
import globalVars
from itemConstants import *
import window
class Item():
def __init__(self):
self.fallingBeep = None
self.shatter = None
self.paused = False
def __del__(self):
self.field = None
if self.fallingBeep is not None:
self.fallingBeep.stop()
if self.shatter is not None:
self.shatter.stop()
def initialize(self, field, x, speed, type, identifier):
self.field = field
self.x = x
self.y = field.getY()
self.speed = speed
self.state = STATE_ALIVE
self.stepTimer = window.Timer()
self.fallingBeep = bgtsound.sound()
self.fallingBeep.load(globalVars.appMain.sounds["itemfalling.ogg"])
self.fallingBeep.pan = self.field.getPan(self.x)
self.fallingBeep.volume = self.field.getVolume(self.y)
self.fallingBeep.pitch = self.field.getPitch(self.y)
self.fallingBeep.play_looped()
self.type = type
self.identifier = identifier
def frameUpdate(self):
if self.state == STATE_BROKEN and self.shatter.playing is False:
self.switchState(STATE_SHOULDBEDELETED)
if self.state == STATE_ALIVE and self.stepTimer.elapsed >= self.speed:
self.step()
def switchState(self, newState):
self.state = newState
if newState == STATE_BROKEN:
self.playShatter()
def step(self):
if self.destroyCheck() is True:
return
self.y -= 1
self.fallingBeep.pan = self.field.getPan(self.x)
self.fallingBeep.volume = self.field.getVolume(self.y)
self.fallingBeep.pitch = self.field.getPitch(self.y)
self.stepTimer.restart()
def destroyCheck(self):
if self.y != 0:
return False
self.switchState(STATE_BROKEN)
self.field.log(_("A \"%(item)s\" item fell on the ground and shattered into peaces!") % {"item": NAMES[self.type][self.identifier]})
return True
def obtain(self):
self.field.log(_("Obtained a \"%(item)s\" item!") % {"item": NAMES[self.type][self.identifier]})
s = bgtsound.sound()
s.load(globalVars.appMain.sounds["hit.ogg"])
s.pan = self.field.getPan(self.x)
s.pitch = random.randint(70, 130)
s.play()
s = bgtsound.sound()
s.load(globalVars.appMain.sounds["itemget.ogg"])
s.pan = self.field.getPan(self.x)
s.volume = self.field.getVolume(self.y)
s.play()
self.field.itemVoicePlayer.play("get %s.ogg" % NAMES[self.type][self.identifier], self.field.getPan(self.x))
self.fallingBeep.stop()
self.switchState(STATE_SHOULDBEDELETED)
def punch(self):
"""Called when this item was punched and destroyed."""
s = bgtsound.sound()
s.load(globalVars.appMain.sounds["hit.ogg"])
s.pan = self.field.getPan(self.x)
s.pitch = random.randint(70, 130)
s.play()
self.destroy()
def destroy(self):
self.field.log(_("A \"%(item)s\" item was shattered into peaces!") % {"item": NAMES[self.type][self.identifier]})
self.switchState(STATE_BROKEN)
def playShatter(self):
self.field.itemVoicePlayer.play("lose %s.ogg" % NAMES[self.type][self.identifier], self.field.getPan(self.x))
self.shatter = bgtsound.sound()
self.shatter.load(globalVars.appMain.sounds["item_destroy%d.ogg" % random.randint(1, 2)])
self.shatter.pitch = random.randint(70, 130)
self.shatter.pan = self.field.getPan(self.x)
self.shatter.volume = self.field.getVolume(self.y)
self.shatter.play()
self.fallingBeep.stop()
def setPaused(self, p):
"""Pauses / unpauses this item."""
if p == self.paused:
return
self.paused = p
self.fallingBeep.setPaused(p)
self.stepTimer.setPaused(p)
# end setPaused