Tuesday, December 29, 2015

LibGDX game jam - dev log #1


The LibGDX Game Jam is on!

In addition to using LibGDX for the coding, I'll be using Tiled (http://www.mapeditor.org/) for level design and Box2D (http://box2d.org/) for physics. For prototyping I'll be using some spritesheets from (http://kenney.nl/). If time permits, I'll work on some custom art assets later.

All the code will be posted on GitHub at https://github.com/stemkoski/LibGDX-Jam

The timing is great, as I've just finished writing Beginning Java Game Development with LibGDX, and this will be an excellent opportunity to build on the foundations presented by that book (source code from the book can be downloaded at http://www.apress.com/9781484215012). To get things up and running quickly, I'll be using (and improving) the following Java classes developed in the book:

  • BaseGame and BaseScreen. These are abstract classes that extend the LibGDX Game and Screen classes, respectively.
  • BaseActor. Extends the LibGDX Actor class, contains Texture data and collision Shape data (which we won't use, instead delegating collision handling to Box2D).
  • AnimatedActor. Extends the BaseActor class, contains Animation data. 
  • Box2DActor. Extends the AnimatedActor class, contains physics-related (Body) data for Box2D.
  • GameUtils. A utility class containing methods to simplify (1) creating animations from files, and (2) processing collisions from Box2D.
  • ParticleActor. Extends the Actor class, is useful for particle effects created with the LibGDX particle editor.


The theme for the LibGDX game jam is "Life in Space". My first thought was outer space -- planets, stars, rocketships, asteroids, etc. From a game design perspective, I've always had a great deal of respect for the classic arcade game Asteroids, for two reasons:

  • its use of immersion: the controls move the spaceship relative to its orientation, rather than relative to the screen directions
  • the shape of its universe: this game features wraparound (the left side of the screen is connected to the right; the top side of the screen is connected to the bottom), and so the Asteroids universe actually exists on the surface of a torus (the shape of a doughnut)

And this train of thought led me to my interpretation of the theme: a key gameplay mechanic is going to be the player figuring out the shape of the space they are in. There will be a series of rooms, but in this universe, they will not be connected as a flat grid. This game will be more puzzle/maze based rather than combat based.

The first step is going to be creating a data structure (called a Room) to hold tilemap data, physics objects, stage objects, etc. The current plan is for each map created with Tiled to have three layers: a tile image layer, a layer for interactive game objects (keys, doors, etc.), and a layer to store non-interactive physics objects (the walls). Each room will have an ID, a number of SpawnPoint objects (each with its own ID), and a number of Portal objects (which contain a destination room ID and spawn point ID). The main game will read in the Tiled TMX files, store each in a custom Room object, and store the set of Rooms in a HashMap (indexed by ID).

The images below show a room in Tiled, and as rendered in LibGDX.

a room in Tiled
room rendered in LibGDX

Working code that implements these steps is currently available on GitHub.


Monday, December 28, 2015

Book Published! Beginning Java Game Development with LibGDX


I've written a book called Beginning Java Game Development with LibGDX, published by Apress, and available here: http://www.apress.com/9781484215012



Here's what the book is about (quoted from the introduction):
In this book, you’ll learn how to program games in Java using the LibGDX game development framework. The LibGDX libraries are both powerful and easy to use, and they will enable you to create a great variety of games quickly and efficiently. LibGDX is free and open-source, can be used to make 2D and 3D games, and integrates easily with third-party libraries to support additional features. Applications created in LibGDX are truly cross-platform; supported systems include Windows, Mac OS X, Linux, Android, iOS, and HTML5/WebGL. 
I have taught courses in Java programming and video game development for many years, and I’ve often struggled to find game programming books that I can recommend to my students without reservation, which led me to write this book. In particular, you will find that this book contains the following unique combination of features, chosen with the aspiring game developer in mind:
  • This book recommends and explains how to use a simple Java development environment (BlueJ) so that you can move on to programming games more quickly.
  • By using the LibGDX framework, you won’t have to “reinvent the wheel” for common programming tasks such as rendering graphics and playing audio. (An explanation of how to write such code from scratch could easily require fifty or more additional pages of reading.) LibGDX streamlines the development process and allows you to focus on game mechanics and design.
  • This book contains many examples of video games that can be developed with LibGDX. The first few example projects will introduce you to the basic features provided by the framework; these starter projects will be extended in the chapters that follow to illustrate how to add visual polish and advanced functionality. Later projects will focus on implementing game mechanics from a variety of genres: shoot-’em-ups, infinite side scrollers, drag-and-drop games, platform games, adventure games with a top-down perspective, and 2.5D games. I believe that working through many examples is fundamental in the learning process; you will observe programming patterns common to many games, you will see the benefits of writing reusable code in practice, you will have the opportunity to compare and contrast code from different projects, and you will gain experience by implementing additional features on your own.
  • At the beginning of this book, I am only assuming that you have a basic familiarity with Java programming. (Details about what background knowledge you need are discussed in the appendix.) Throughout the first few chapters of this book, advanced programming concepts will be introduced and explained as they arise naturally and are needed in the context of game programming. By the time you reach the end of this book, you will have learned about many advanced Java programming topics that are also useful for software development in general.
And here are some screenshots of some of the many games and demos you'll create in the book:

Cheese, Please!
Balloon Buster
Starfish Collector
Space Rocks - inspired by Asteroids
Plane Dodger - inspired by Flappy Bird
Rectangle Destroyer - inspired by Breakout
52 Card Pickup
Starscape - a particle effects demo
Jumping Jack - a sandbox style physics demo
Jumping Jack 2 - a platformer game
Treasure Quest - a top-down adventure/rpg style game
Pirate's Cove - an interactive 3D (2.5D) demo

Interested? Check it out at: http://www.apress.com/9781484215012!