Water.py (2537B)
1 # Water - collisions demo 2 3 import PyIgnition, pygame, sys, math 4 5 6 screen = pygame.display.set_mode((800, 600)) 7 pygame.display.set_caption("PyIgnition demo: collisions") 8 clock = pygame.time.Clock() 9 10 11 effect = PyIgnition.ParticleEffect(screen, (0, 0), (800, 600)) 12 source = effect.CreateSource((0, 0), initspeed = 2.0, initdirection = math.pi, initspeedrandrange = 1.0, initdirectionrandrange = math.pi, particlesperframe = 20, particlelife = 80, drawtype = PyIgnition.DRAWTYPE_CIRCLE, colour = (100, 100, 250), radius = 10.0) 13 grav = effect.CreateDirectedGravity(0.2, 0.0, [0, 1]) 14 circle1 = effect.CreateCircle((100, 200), (0, 0, 0), bounce = 0.1, radius = 50.0) 15 circle2 = effect.CreateCircle((400, 100), (0, 0, 0), bounce = 0.1, radius = 50.0) 16 circle3 = effect.CreateCircle((300, 300), (0, 0, 0), bounce = 0.1, radius = 50.0) 17 circle4 = effect.CreateCircle((500, 250), (0, 0, 0), bounce = 0.1, radius = 50.0) 18 circle5 = effect.CreateCircle((150, 400), (0, 0, 0), bounce = 0.1, radius = 50.0) 19 rect1 = effect.CreateRectangle((500, 450), colour = (100, 200, 200), width = 250.0, height = 100.0, bounce = 0.2) 20 rect1.CreateKeyframe(200, pos = (400, 100), width = 400.0, interpolationtype = PyIgnition.INTERPOLATIONTYPE_COSINE) 21 rect1.CreateKeyframe(300, colour = (255, 0, 0)) 22 circle2.CreateKeyframe(250, pos = (400, 500), interpolationtype = PyIgnition.INTERPOLATIONTYPE_COSINE) 23 circle2.CreateKeyframe(300, colour = (0, 255, 50)) 24 circle4.CreateKeyframe(200, pos = circle4.pos) 25 circle4.CreateKeyframe(230, pos = (100, 300), interpolationtype = PyIgnition.INTERPOLATIONTYPE_COSINE) 26 source.CreateParticleKeyframe(60, colour = (100, 100, 250), radius = 10.0) 27 source.CreateParticleKeyframe(80, colour = (255, 255, 255), radius = 20.0) 28 line = effect.CreateBoundaryLine((700, 500), colour = (0, 0, 0), bounce = 0.1, normal = [-1.4142, -1.4142]) 29 line.CreateKeyframe(300, normal = [-2, -1]) 30 line.CreateKeyframe(500, normal = [-1, 0]) 31 line2 = effect.CreateBoundaryLine((0, 600), colour = (0, 0, 0), bounce = 0.1, normal = [0, -1]) 32 line3 = effect.CreateBoundaryLine((0, 600), colour = (0, 0, 0), bounce = 0.1, normal = [1, 0]) 33 34 effect.SaveToFile("Water.ppe") 35 #effect.LoadFromFile("Water.ppe") 36 37 38 while True: 39 for event in pygame.event.get(): 40 if event.type == pygame.QUIT: 41 sys.exit() 42 43 screen.fill((255, 255, 255)) 44 45 source.SetPos(pygame.mouse.get_pos()) 46 if source.curframe % 30 == 0: 47 source.ConsolidateKeyframes() 48 49 effect.Update() 50 effect.Redraw() 51 pygame.display.update() 52 clock.tick(30)