/usr/lib/krank/Effect.py is in krank 0.7+dfsg2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #
# Part.py
import k
from Krank import *
from Math import *
from Sprite import *
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
class Effects:
#-------------------------------------------------------------------------------------------
def __init__ (self):
#log(log='startup')
self.effects = []
k.effects = self
self.sparkImages = []
self.sparkShades = 10
for i in range(self.sparkShades):
self.sparkImages.append(pygame.image.load('levels/images/spark.png'))
array = pygame.surfarray.pixels_alpha(self.sparkImages[-1])
for x in range(8):
for y in range(8):
array[x][y] = max(0, array[x][y]-128.0*i/self.sparkShades)
#-------------------------------------------------------------------------------------------
def reset (self):
self.effects = []
#-------------------------------------------------------------------------------------------
def add (self, item):
self.effects.append(item)
#-------------------------------------------------------------------------------------------
def remove (self, item):
self.effects.remove(item)
#-------------------------------------------------------------------------------------------
def onFrame (self, delta):
for effect in self.effects:
effect.onFrame(delta)
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
class Spark:
#-------------------------------------------------------------------------------------------
def __init__ (self, dict={}):
self.pos = vector(dict.get('pos'))
self.vel = vector(dict.get('vel'))
self.sprite = Sprite(self.pos, k.effects.sparkImages[0])
k.effect_sprites.add(self.sprite)
#-------------------------------------------------------------------------------------------
def onFrame (self, delta):
self.pos += self.vel * delta
self.sprite.setPos(self.pos)
#-------------------------------------------------------------------------------------------
def onExit (self):
self.sprite.kill()
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
class SparkGroup:
#-------------------------------------------------------------------------------------------
def __init__ (self, pos, num=80):
if num == 0: return
dict = {}
dict['pos'] = pos
self.age = 0
self.max_age = dict.get('max_age', 500)
self.sparks = []
maxsparks = min(int(k.clock.get_fps()/5), 80)
for i in range(min(num, maxsparks)):
angle = random.random()*math.pi*2
dict['vel'] = vector.withAngle(angle, random.random()*0.3)
self.sparks.append(Spark(dict))
k.effects.add(self)
#-------------------------------------------------------------------------------------------
def onFrame (self, delta):
self.age += delta
if self.age > self.max_age:
for spark in self.sparks:
spark.onExit()
self.sparks = []
k.effects.remove(self)
else:
agefac = float(self.age)/self.max_age
for spark in self.sparks:
spark.sprite.image = k.effects.sparkImages[int(agefac*(k.effects.sparkShades-1))]
spark.onFrame(delta)
|