Commits

Daniel Pope committed 7a61452

New: splash down particles

Comments (0)

Files changed (2)

Add a comment to this file

korovic/data/sprites/drip.png

Added
New image
 from pyglet.event import EventDispatcher
 from pyglet.graphics import Batch
 from pyglet.sprite import Sprite
-from lepton import ParticleSystem
+from lepton import ParticleSystem, ParticleGroup, Particle
+from lepton import domain
 from lepton.emitter import StaticEmitter
+from lepton import controller
 
+from .components.engines import Renderer
 
 from .vector import v
 from .camera import Rect
         self.particles = ParticleSystem()
         self.crashed = False
         self.won = False
+        self.splash_group = None
+
+    def particle_splash(self, pos, vel):
+        img = self.load_sprite('sprites/drip')
+        img.anchor_x = img.width / 2
+        img.anchor_y = img.height / 2
+        e = StaticEmitter(
+            position=domain.Disc(
+                (pos.x, SEA_LEVEL, 0),
+                (0, 0, 1),
+                50
+            ),
+            velocity=domain.Disc(
+                (vel.x, vel.y, 0),
+                (0, 0, 1),
+                200
+            ),
+            size=[(64.0, 64.0, 0), (80.0, 80.0, 0), (100.0, 100.0, 0)],
+            template=Particle(
+                color=(1.0, 1.0, 1.0, 1.0),
+            ),
+        )
+        self.splash_group = ParticleGroup(
+            controllers=[
+                controller.Movement(),
+                controller.Gravity((0, -900, 0)),
+                controller.Lifetime(max_age=2)
+            ],
+            renderer=Renderer(img),
+            system=self.particles
+        )
+        e.emit(30, self.splash_group)
 
     def load_sprite(self, img):
         if img not in self.images:
             self.crashed = True
             self.remove_squid()
             self.splash.play()
+            vx, vy = self.squid.body.velocity * 0.5
+            vy = max(20, vy * -1)
+            self.particle_splash(p, v(vx, vy))
             self.dispatch_event('on_crash', self.distance)
 
     def draw(self, viewport):
         for s in self.sprites:
             s.draw()
+        # Draw with depth testing
+        gl.glDepthFunc(gl.GL_LEQUAL)
+        if self.splash_group:
+            self.splash_group.draw()
         for a in self.actors:
             a.draw()
-        # Draw with depth testing
-        gl.glDepthFunc(gl.GL_LEQUAL)
         if self.crashed:
             # Keep particles going
             self.particles.draw()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.