Sky Checkers

Apr 28, 2019

Over 10 years ago I dreamt of creating a fun 3-D multiplayer action packed game and started developing Sky Checkers. Last week, I released an update including major refinements developed in the past few months. Let me introduce the game and mention some of the highlights!

Gameplay

Gameplay

Sky Checkers is a 1-4 player game where players knock other players off a checkerboard stage using their tile-crushing weapon. The last one standing wins! This game is most fun when battling several friends next to each other or online, but the game has AI (bots) to accompany missing humans.

Not much has actually changed recently in terms of gameplay, but I want to highlight the improved AIs and how they function generally.

For movement, every one or two seconds the AIs make a change in direction. They also change directions when they collide with another player or reach an end of the board. Previously, the AIs often stayed in one direction and didn’t change often. Now, they are a little smarter in making more changes, enabling them to be in the middle of the stage more often rather than the outer edges.

For firing, AIs make a new decision every 0.25 seconds (the average human reaction time). They may decide to do nothing which occurs more often for easy mode AIs than hard mode ones, or they will fire if they think they can knock another player out. Previously, the AIs would fire only if they were on the same row or column as another player. Now, the AIs also fire if their row or column is neighboring another player’s row or column. This enables AIs to fire based on predicting where players will move, which often imitates what humans do!

While play testing with my friends and having other people provide feedback, I observed skills amongst them can vary widely. Easy mode AIs (the default mode) are tuned to be challenging for beginners. More experienced players can play against the medium or hard mode AIs which react more often.

Renderers

The rendering code used to draw the 3-D graphics on screen has changed significantly behind the scenes.

Previously, Sky Checkers was using immediate mode OpenGL (eg: glBegin, glEnd) and GLUT for drawing some spherical objects and text.

To support modern versions of OpenGL, I removed using GLUT utility functions and plotted coordinates for specific objects myself, replaced glTranslate/glRotate/glScale by managing matrix multiplications myself, and created buffer objects from vertices, texture coordinates, or colors that are passed to shader programs to produce a final output.

Once I supported modern OpenGL, I added a Metal renderer for macOS and a Direct3D 11 renderer for Windows, which are now the preferred backends for those respective platforms. In this process of adding more renderers, I needed to fix the draw order by rendering opaque objects first followed by translucent objects (from z-far to z-near).

As for the rationale behind Metal and Direct3D: Metal is justified because OpenGL is deprecated on macOS and Metal provides better performance even for single threaded code. I also found both Metal and Direct3D to have a better explicit API and better platform support. I noticed OpenGL programs failed to run via remote desktop on Windows as one particular example where OpenGL didn’t shine.

Moreover, learning to use other graphics APIs is fun and a worthwhile investment 😉. One day I may consider adding renderers for Direct3D 12 and then Vulkan if Linux support becomes better. I didn’t start with Vulkan because Metal seems easier and I didn’t want to rely on a 3rd party library that creates an impedance mismatch between the APIs (eg: MoltenVK).

Netcode

The netcode used to play with people online has improved the most in this update. Previously, online play was only usable in LAN environments or if players lived very close to each other. Now, this game can be played comfortably with friends on the opposite side of the country. Watch a video clip (no audio) of me being crushed by such friends!

Message reliability has improved to achieve better latency. Messages are transferred using UDP which doesn’t guarantee that packets will arrive onto the other end or arrive in the correct order. To tackle the out of order problem, each packet is tagged with an increasing number to ensure they are processed in correct order. To ensure messages are not lost, packets for important messages are resent continously until the other side acknowledges that a message has been received. Important messages includes change in direction or firing, but not messages like position updates where the previous state doesn’t need to be processed. Individual messages are now also bit-packed and aggregated minimizing the number of bytes and how often packets are transferred.

Interpolation has also been added to achieve smoother animation. When a client receives position updates from the server, instead of setting the position naively, the client now renders a few updates before the latest positional update allowing the client to smoothly interpolate to a target position. This also allows the client to have a position to update to in case one or two updates don’t arrive due to UDP unreliability. When positions of players become out of sync, the client tries to correct the position gradually over multiple frames.

Prediction has lastly been added to achieve better responsiveness. When a client makes a decision such as firing or changing directions, the client immediately renders or predicts those changes before sending them and waiting for the server to tell the client what actions to perform. If a client makes a decision incorrectly, it can correct its prediction once the actions are received from the server. Without prediction, input on the clients side would feel lagged. Note to prevent cheating, servers are authorative and clients can only make decisions such as changing direction and firing, but not where to fire or where to be positioned on the stage.

Conclusion

Sky Checkers is perceived as my first significant programming project. It has now been updated to support modern rendering APIs and smoother online play! Minor improvements have also been made recently in the AIs, animation, audio, and keyboard & gamepad input. The game also has been updated to using SDL 2 recently. Sky Checkers still has ways to go regarding polish and gameplay experience, but the recent behind the scenes improvements are satisfying.

Please be sure to check out the game and let me know what you think!