File: particles.rst

package info (click to toggle)
pysdl2 0.9.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,328 kB
  • sloc: python: 24,685; makefile: 36; sh: 8
file content (96 lines) | stat: -rw-r--r-- 3,096 bytes parent folder | download
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
.. module:: sdl2.ext.particles
   :synopsis: A simple particle system.

A simple particle system
========================

.. class:: ParticleEngine()

   A simple particle processing system. The :class:`ParticleEngine`
   takes care of creating, updating and deleting particles via callback
   functions. It only decreases the life of the particles by itself and
   marks them as dead, once the particle's life attribute has reached 0
   or below.

   .. attribute:: createfunc

      Function for creating new particles. The function needs to take
      two arguments, the ``world`` argument passed to :meth:`process()`
      and a list of the particles considered dead (:attr:`Particle.life`
      <= 0). ::

        def creation_func(world, deadparticles):
            ...

   .. attribute:: updatefunc

      Function for updating existing, living particles. The function
      needs to take two arguments, the ``world`` argument passed to
      :meth:`process()` and a :class:`set` of the still living
      particles. ::

        def update_func(world, livingparticles):
            ...

   .. attribute:: deletefunc

      Function for deleting dead particles. The function needs to take
      two arguments, the ``world`` argument passed to :meth:`process()`
      and a list of the particles considered dead (:attr:`Particle.life`
      <= 0). ::

        def deletion_func(world, deadparticles):
            ...

   .. method:: process(world : World, components : iterable) -> None

      Processes all particle components, decreasing their life by 1.

      Once the life of all particle components has been decreased
      properly and the particles considered dead (life <= 0) are
      identified, the creation, update and deletion callbacks are
      invoked.

      The creation callback takes the passed world as first and the
      list of dead particles as second argument. ::

        def particle_createfunc(world, list_of_dead_ones):
            ...

      Afterwards the still living particles are passed to the update
      callback, which also take the passed world as first and the
      living particles as set as second argument. ::

        def particle_updatefunc(world, set_of_living_ones):
            ...

      Finally, the dead particles need to be deleted in some way or
      another, which is done by the deletion callback, taking the
      passed world as first and the list of dead particles as second
      argument. ::

        def particle_deletefunc(world, list_of_dead_ones):
            ...

.. class:: Particle(x, y, life : int)

   A simple particle component type. It only contains information about
   a x- and y-coordinate and its current life time. The life time will
   be decreased by 1, every time the particle is processed by the
   :class:`ParticleEngine`.

   .. attribute:: x

      The x coordinate of the particle.

   .. attribute:: y

      The y coordinate of the particle.

   .. attribute:: life

      The remaining life time of the particle.

   .. attribute:: position

      The x- and y-coordinate of the particle as tuple.