SPACE INVADERS 8
In this project, we'll continue building our Space Invaders game by animating our ship using a sprite.
I/O (Input/Output) RaspberrySTEM Cell
LED Matrix RaspberrySTEM Cell
Accelerometer RaspberrySTEM Cell
Having issues? Check out the Troubleshooting Guide.

We should now have a working Space Invaders game, but we can make it more visually appealing by custom designing our ship using "Sprite" functionality in the API.


What Are Sprites?

Sprites are two-dimensional bitmaps, which are representations of images created by encoding information for each individual pixel in the image. On the RaspberrySTEM CREATOR Kit, Sprites allow you to define graphics on the 8x8 LED Matrix display, by defining a "color" for each pixel of the graphic. The LED Matrix only has one color, but the intensity of the pixel brightness can be altered for each pixel in the sprite, or a pixel can be turned off completely.

For more information on how to use sprites, click on the "API" button at the top of this page, then click on "rstem.led_matrix" and finally, click on "Sprite." The API documentation will tell you how the various sprite functions work, and we demonstrate using sprites in our project below.

To change the ship to a custom sprite, we need to include some basic initialization code, code to design the sprite configuration and code to draw the sprite.

Here is the initialization code:



Here is the sprite code:



Here is the drawing code:



And here is what our full project should look like at this point -- when you run the code, you should now see our spaceship dot replaced with a nicer spaceship design:


home | prev | next