Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## this code was taken from the renpy core; I don't entirely know how it works.
- ## All I did was modify it to take an xpos tuple, so I could set a range
- ## in which particles will appear. Before they would be full screen width.
- init python:
- class MyParticleFactory(renpy.python.NoRollback):
- rotate = False
- def __setstate__(self, state):
- self.start = 0
- vars(self).update(state)
- self.init()
- def __init__(self, image, count, xspeed, yspeed, xpos, border, start, fast, rotate=False):
- self.image = renpy.easy.displayable(image)
- self.count = count
- self.xspeed = xspeed
- self.yspeed = yspeed
- self.xpos = xpos
- self.border = border
- self.start = start
- self.fast = fast
- self.rotate = rotate
- self.init()
- def init(self):
- self.starts = [ random.uniform(0, self.start) for _i in xrange(0, self.count) ] # W0201
- self.starts.append(self.start)
- self.starts.sort()
- def create(self, particles, st):
- def ranged(n):
- if isinstance(n, tuple):
- return random.uniform(n[0], n[1])
- else:
- return n
- if (st == 0) and not particles and self.fast:
- rv = [ ]
- for _i in xrange(0, self.count):
- rv.append(MyParticle(self.image,
- ranged(self.xspeed),
- ranged(self.yspeed),
- self.xpos,
- self.border,
- st,
- random.uniform(0, 100),
- fast=True,
- rotate=self.rotate))
- return rv
- if particles is None or len(particles) < self.count:
- # Check to see if we have a particle ready to start. If not,
- # don't start it.
- if particles and st < self.starts[len(particles)]:
- return None
- return [ MyParticle(self.image,
- ranged(self.xspeed),
- ranged(self.yspeed),
- self.xpos,
- self.border,
- st,
- random.uniform(0, 100),
- fast=False,
- rotate=self.rotate) ]
- def predict(self):
- return [ self.image ]
- class MyParticle(renpy.python.NoRollback):
- def __init__(self, image, xspeed, yspeed, xpos, border, start, offset, fast, rotate):
- # safety.
- if yspeed == 0:
- yspeed = 1
- self.image = image
- self.xspeed = xspeed
- self.yspeed = yspeed
- self.xpos = xpos
- self.border = border
- self.start = start
- self.offset = offset
- self.rotate = rotate
- if not rotate:
- sh = renpy.config.screen_height
- sw = renpy.config.screen_width
- else:
- sw = renpy.config.screen_height
- sh = renpy.config.screen_width
- if self.yspeed > 0:
- self.ystart = -border
- else:
- self.ystart = sh + border
- travel_time = (2.0 * border + sh) / abs(yspeed)
- xdist = xspeed * travel_time
- x0 = self.xpos[0] ## min(-xdist, 0)
- x1 = self.xpos[1] ## max(sw + xdist, sw)
- self.xstart = random.uniform(x0, x1)
- if fast:
- self.ystart = random.uniform(-border, sh + border)
- self.xstart = random.uniform(x0, x1) ## random.uniform(0, sw)
- def update(self, st):
- to = st - self.start
- xpos = self.xstart + to * self.xspeed
- ypos = self.ystart + to * self.yspeed
- if not self.rotate:
- sh = renpy.config.screen_height
- else:
- sh = renpy.config.screen_width
- if ypos > sh + self.border:
- return None
- if ypos < -self.border:
- return None
- if not self.rotate:
- return int(xpos), int(ypos), to + self.offset, self.image
- else:
- return int(ypos), int(xpos), to + self.offset, self.image
- def MyParticleSystem(d,
- count=10,
- border=50,
- xspeed=(20, 50),
- yspeed=(100, 200),
- xpos=(0.0,1.0),
- start=0,
- fast=False,
- horizontal=False):
- if horizontal:
- xspeed, yspeed = yspeed, xspeed
- return Particles(MyParticleFactory(image=d,
- count=count,
- border=border,
- xspeed=xspeed,
- yspeed=yspeed,
- xpos=xpos,
- start=start,
- fast=fast,
- rotate=horizontal))
- ## The rest is my own code. I've trimmed out some irrelevant stuff.
- ## the particle itself, which has baked in instructions for its startng state and ending state.
- ## It starts wide and flat, then fades out as it gets narrow and tall.
- image dustybit:
- "visual-fx/dusty.png"
- xzoom 0.5 yzoom 0.2 xalign 0.5
- linear 1.5 alpha 0.0 xzoom 0.05 yzoom 2.0
- ## Creating a particle system using that particle.
- image dusty = MyParticleSystem("dustybit", count=3, xspeed=(-25,35), xpos=(40,160))
- ## The final composited image for the background.
- image donnawood-foyer = LiveComposite(
- (1920,1080),
- (0,0),"bg/donnawood-foyer.jpg", ## static bg
- (0,0),"donnawood-foyer1", ## overall lighting tone shift
- (0,0),"dusty", ## PARTICLE SYSTEM
- (183,362),"donnawood-foyer2") ## flickering candle lamp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement