Code Samples

On this page we have provided several samples illustrating various technical challenges in game development. These samples include many examples that are commonly requested in this course. All of these samples come with source code. You are allowed to use the code here as reference or directly in your own games.

This page has all of the demos that we will show in lecture throughout the semester. You are encouraged to look at them ahead of time to give you a jump start on your project. We find that these demos cover most of the major issues that you might run into when developing your game.

With that said, we are always looking for more demos. If you discover something cool that is not here, let us know. We are more than willing to add more demos for students to look at.

Ship Demo

This example demonstrates image drawing, rotation and scaling, and background drawing from an image. It also has sound effects and simple mathematics for physics. This is the code from the first programming lab.

JSON Demo

This example shows how to use JSON to define your level format. Modifying the json file allows you to change the level without recompiling the demo; just hit start.

Parallax Scrolling

This example shows off parallax scrolling to give your game some feeling of depth. Parallax scrolling does not actually give you 3D game play, but it does make the game look nicer.

Computational Shapes

This example shows off a recent advancement. One of the things that LibGDX lacks is good computational geometry tools for constructing polygons, and then drawing them. However, we have these tools in CUGL and they are are part of the GDIAC extensions. This demo shows off how to use these tools to create shapes that can be drawn with a SpriteBatch.

Texture Meshes

This example shows you how to do sophisticated texture mapping beyond what we can do with basics sprites. The application itself is simple and displays a single textured polygon. Press = or - to change the number of vertices on the polygon, and press numbers 1-6 to change the texture used. You can distort the polygon by clicking on a vertex and dragging it.

Offscreen Rendering

When we draw, we typically draw directly to the screen. But that is not the only option. We can also draw to a texture, and then use that texture in another drawing pass. In this demo, we have four physics demos running simulatenously. We draw each simulation to a texture, and then put those textures on the faces of a rotating cube.

box2d Lights

This example shows off how to use box2d to make a top-down game with simple lighting effects. It requires an additional library called box2DLights, which is included in the GDIAC extensions. Like the JSON Demo, this example defines the level layout with JSON files, allowing you to reset the lights on the fly. There are multiple light settings in this demo. Use the keys P and N to page through them all.