-# 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_Delay, \
- SDL_WarpMouseInWindow, SDL_ShowCursor, SDL_Rect, SDL_RenderCopy
- import sdl2.ext as sdl2ext
-# Import the particles module, so we have access to all relevant parts
-# for dealing with particles.
-import sdl2.ext.particles as particles
# Create a resource, so we have easy access to the example images.
-RESOURCES = sdl2ext.Resources(__file__, "resources")
+RESOURCES = sdl2ext.Resources(__file__, "resources")
# The Particle class offered by sdl2.ext.particles only contains the life
# want to flood our world with unused entities. Thus, we store a
# reference to the entity, the particle belongs to, too. This allows use
# to remove them easily later on.
def __init__(self, entity, x, y, vx, vy, ptype, life):
super(CParticle, self).__init__(x, y, 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)
# Create a simple rendering system for particles. This is somewhat
# similar to the TextureSprinteRenderer from sdl2.ext. Since we operate on
# particles rather than sprites, we need to provide our own rendering logic.
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 = SDL_RenderCopy
+ dorender = SDL_RenderCopy
# And some more shortcuts.
sdlrenderer = self.renderer.renderer
# Create the environment, in which our particles will exist.
- world = sdl2ext.World()
+ world = sdl2ext.World()
# Set up the globally available information about the current mouse
# position. We use that information to determine the emitter
# Create the particle engine. It is just a simple System that uses
# callback functions to update a set of components.
- engine = particles.ParticleEngine()
+ engine = particles.ParticleEngine()
# Bind the callback functions to the particle engine. The engine
# does the following on processing:
createparticles(world, None, 300)
# Initialize the video subsystem, create a window and make it visible.
- window = sdl2ext.Window("Particles", size=(800, 600))
+ window = sdl2.ext.Window("Particles", size=(800, 600))
# Create a hardware-accelerated sprite factory. The sprite factory requires
# a rendering context, which enables it to create the underlying textures
# that serve as the visual parts for the sprites.
- renderer = sdl2ext.RenderContext(window)
- factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)
+ renderer = sdl2.ext.RenderContext(window)
+ factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
# Create a set of images to be used as particles on rendering. The
# images are used by the ParticleRenderer created below.
# Center the mouse on the window. We use the SDL2 functions directly
# here. Since the SDL2 functions do not know anything about the
# sdl2.ext.Window class, we have to pass the window's SDL_Window to it.
- SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
+ SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
# Hide the mouse cursor, so 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
# The almighty event loop. You already know several parts of it.
- for event in sdl2ext.get_events():
- if event.type == SDL_QUIT:
+ for event in sdl2.ext.get_events():
+ if event.type == sdl2.SDL_QUIT:
- if event.type == SDL_MOUSEMOTION:
+ 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
if __name__ == "__main__":