# Try to import SDL2. The import might fail, if the SDL2 DLL could
# not be loaded. In that case, just print the error and exit with a
+ from sdl2 import SDL_QUIT, SDL_MOUSEMOTION, SDL_FlushEvent, \
+ SDL_WarpMouseInWindow, SDL_ShowCursor, SDL_Rect, SDL_RenderCopy
import sdl2.ext as sdl2ext
- import sdl2.events as sdlevents
- import sdl2.mouse as sdlmouse
- import sdl2.timer as sdltimer
- import sdl2.render as sdlrender
- import sdl2.rect as sdlrect
# Import the particles module, so we have access to all relevant parts
# for dealing with particles.
import sdl2.ext.particles as particles
-# We will create some systems and an entity for creating the particle
-# simulation. Hence we will need some things from the ebs module.
-from sdl2.ext.ebs import Entity, System, World
-# Import the resources, so we have easy access to the example images.
-from sdl2.ext.resources import Resources
-RESOURCES = Resources(__file__, "resources")
+# Create a resource, so we have easy access to the example images.
+RESOURCES = sdl2ext.Resources(__file__, "resources")
# The Particle class offered by sdl2.ext.particles only contains the life
# A simple Entity class, that contains the particle information. This
# represents our living particle object.
def __init__(self, world, x, y, vx, vy, ptype, life):
self.cparticle = CParticle(self, x, y, vx, vy, ptype, life)
# similar to the TextureSprinteRenderer from mule.video. Since we
# operate on particles rather than sprites, we need to provide our own
def __init__(self, renderer, images):
# Create a new particle renderer. The surface argument will be
# the targets surface to do the rendering on. images is a set of
# The SDL_Rect is used for the blit operation below and is used
# as destination position for rendering the particle.
# The SDL2 blit function to use. This will take an image
# (SDL_Texture) as source and copies it on the target.
- dorender =
+ dorender = SDL_RenderCopy
# And some more shortcuts.
sdlrenderer = self.renderer.renderer
# Create the environment, in which our particles will exist.
+ world = World()
# Set up the globally available information about the current mouse
# position. We use that information to determine the emitter
# Center the mouse on the window. We use the SDL2 functions directly
# here. Since the SDL2 functions do not know anything about the
- # video.Window class, we have to pass the window's SDL_Window to it.
- sdlmouse.SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
+ # sdl2.ext.Window class, we have to pass the window's SDL_Window to it.
+ SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
- # Hide the mouse cursor,
os it does not show up - just show the
+ # Hide the mouse cursor, s it does not show up - just show the
# Create the rendering system for the particles. This is somewhat
# similar to the SoftSpriteRenderer, but since we only operate with
for event in sdl2ext.get_events():
- if event.type ==
+ if event.type == SDL_QUIT:
- if event.type ==
+ if event.type == SDL_MOUSEMOTION:
# Take care of the mouse motions here. Every time the
# mouse is moved, we will make that information globally
# available to our application environment by updating
# queue (10ths to 100ths!), and we do not want to handle
# each of them. For this example, it is enough to handle