Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. ## this code was taken from the renpy core; I don't entirely know how it works.
  2. ## All I did was modify it to take an xpos tuple, so I could set a range
  3. ## in which particles will appear. Before they would be full screen width.
  4.  
  5. init python:
  6. class MyParticleFactory(renpy.python.NoRollback):
  7.  
  8. rotate = False
  9.  
  10. def __setstate__(self, state):
  11. self.start = 0
  12. vars(self).update(state)
  13. self.init()
  14.  
  15. def __init__(self, image, count, xspeed, yspeed, xpos, border, start, fast, rotate=False):
  16. self.image = renpy.easy.displayable(image)
  17. self.count = count
  18. self.xspeed = xspeed
  19. self.yspeed = yspeed
  20. self.xpos = xpos
  21. self.border = border
  22. self.start = start
  23. self.fast = fast
  24. self.rotate = rotate
  25. self.init()
  26.  
  27. def init(self):
  28. self.starts = [ random.uniform(0, self.start) for _i in xrange(0, self.count) ] # W0201
  29. self.starts.append(self.start)
  30. self.starts.sort()
  31.  
  32. def create(self, particles, st):
  33.  
  34. def ranged(n):
  35. if isinstance(n, tuple):
  36. return random.uniform(n[0], n[1])
  37. else:
  38. return n
  39.  
  40. if (st == 0) and not particles and self.fast:
  41. rv = [ ]
  42.  
  43. for _i in xrange(0, self.count):
  44. rv.append(MyParticle(self.image,
  45. ranged(self.xspeed),
  46. ranged(self.yspeed),
  47. self.xpos,
  48. self.border,
  49. st,
  50. random.uniform(0, 100),
  51. fast=True,
  52. rotate=self.rotate))
  53. return rv
  54.  
  55. if particles is None or len(particles) < self.count:
  56.  
  57. # Check to see if we have a particle ready to start. If not,
  58. # don't start it.
  59. if particles and st < self.starts[len(particles)]:
  60. return None
  61.  
  62. return [ MyParticle(self.image,
  63. ranged(self.xspeed),
  64. ranged(self.yspeed),
  65. self.xpos,
  66. self.border,
  67. st,
  68. random.uniform(0, 100),
  69. fast=False,
  70. rotate=self.rotate) ]
  71.  
  72. def predict(self):
  73. return [ self.image ]
  74.  
  75.  
  76. class MyParticle(renpy.python.NoRollback):
  77.  
  78. def __init__(self, image, xspeed, yspeed, xpos, border, start, offset, fast, rotate):
  79.  
  80. # safety.
  81. if yspeed == 0:
  82. yspeed = 1
  83.  
  84. self.image = image
  85. self.xspeed = xspeed
  86. self.yspeed = yspeed
  87. self.xpos = xpos
  88. self.border = border
  89. self.start = start
  90. self.offset = offset
  91. self.rotate = rotate
  92.  
  93. if not rotate:
  94. sh = renpy.config.screen_height
  95. sw = renpy.config.screen_width
  96. else:
  97. sw = renpy.config.screen_height
  98. sh = renpy.config.screen_width
  99.  
  100. if self.yspeed > 0:
  101. self.ystart = -border
  102. else:
  103. self.ystart = sh + border
  104.  
  105. travel_time = (2.0 * border + sh) / abs(yspeed)
  106.  
  107. xdist = xspeed * travel_time
  108.  
  109. x0 = self.xpos[0] ## min(-xdist, 0)
  110. x1 = self.xpos[1] ## max(sw + xdist, sw)
  111.  
  112. self.xstart = random.uniform(x0, x1)
  113.  
  114. if fast:
  115. self.ystart = random.uniform(-border, sh + border)
  116. self.xstart = random.uniform(x0, x1) ## random.uniform(0, sw)
  117.  
  118. def update(self, st):
  119. to = st - self.start
  120.  
  121. xpos = self.xstart + to * self.xspeed
  122. ypos = self.ystart + to * self.yspeed
  123.  
  124. if not self.rotate:
  125. sh = renpy.config.screen_height
  126. else:
  127. sh = renpy.config.screen_width
  128.  
  129. if ypos > sh + self.border:
  130. return None
  131.  
  132. if ypos < -self.border:
  133. return None
  134.  
  135. if not self.rotate:
  136. return int(xpos), int(ypos), to + self.offset, self.image
  137. else:
  138. return int(ypos), int(xpos), to + self.offset, self.image
  139.  
  140.  
  141. def MyParticleSystem(d,
  142. count=10,
  143. border=50,
  144. xspeed=(20, 50),
  145. yspeed=(100, 200),
  146. xpos=(0.0,1.0),
  147. start=0,
  148. fast=False,
  149. horizontal=False):
  150.  
  151. if horizontal:
  152. xspeed, yspeed = yspeed, xspeed
  153.  
  154. return Particles(MyParticleFactory(image=d,
  155. count=count,
  156. border=border,
  157. xspeed=xspeed,
  158. yspeed=yspeed,
  159. xpos=xpos,
  160. start=start,
  161. fast=fast,
  162. rotate=horizontal))
  163.  
  164. ## The rest is my own code. I've trimmed out some irrelevant stuff.
  165.  
  166. ## the particle itself, which has baked in instructions for its startng state and ending state.
  167. ## It starts wide and flat, then fades out as it gets narrow and tall.
  168. image dustybit:
  169. "visual-fx/dusty.png"
  170. xzoom 0.5 yzoom 0.2 xalign 0.5
  171. linear 1.5 alpha 0.0 xzoom 0.05 yzoom 2.0
  172.  
  173. ## Creating a particle system using that particle.
  174. image dusty = MyParticleSystem("dustybit", count=3, xspeed=(-25,35), xpos=(40,160))
  175.  
  176. ## The final composited image for the background.
  177. image donnawood-foyer = LiveComposite(
  178. (1920,1080),
  179. (0,0),"bg/donnawood-foyer.jpg", ## static bg
  180. (0,0),"donnawood-foyer1", ## overall lighting tone shift
  181. (0,0),"dusty", ## PARTICLE SYSTEM
  182. (183,362),"donnawood-foyer2") ## flickering candle lamp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement