Craig's Space / Tank Game

Introduction

I was working on this space / tank game during late January / early February 2017. If you're feeling agressive, you can try to shoot each other, but it's oftentimes just as fun to just fly around the screen. You'll need the Java JRE version 8+ to get it to run. The source code is available at github.com.

Motivation

The main reason I wanted to work on this project was so that I could try out some networking. I had made a couple of pretty similar games in the past, but hadn't ever gotten two computers to talk to each other in any meaningful way.

Features / Description

Space Shot

In one mode of the game, you can fly around as a spaceship. If the planet and gravity are enabled, then it's fun to try to put your ship in and out of orbit. Or it's also fun to try to use your ship's gravity to tug the other ships around the screen. In any case, I feel that if you play you'll learn a lot about inertia.

Tank Shot

In the other mode of the game, you can play as a tank driving around the screen. In pratical terms, this means that there is no inertia, no gravitational attraction, and the ships are rendered differently.

Synchronized space swimming

If you play where all the players have the same exact key assignments it can be kind of fun because you can make the ships to pretty intricate "synchronized swimming" routines.

Boundary

If you enable the "safe zone" option and your ship / tank leaves the safe zone, then your ship / tank will only survive for a little while.

Landing screen

The landing screen lets you select basic parameters about the game you'd like to play. After you hit "Play!", you are taken to an already running instance of the game.

Players screen

The players screen lets you edit the players for the game. You can change the buttons for each player or add new players with different colors and names. If you are running a game over the internet, you can boot out external players too.

Settings Screen

This screen lets you make edits to the game's settings. You can put a lifespan on the bullets, edit the "safe zone" settings (see below), tweak gravity settings, make the screen wrap-around, and a few other things. I'd like to add more options to this screen in the future.

Synchronized space swimming

Using the internet screen, you can host a game on the internet so that other people can join. In order to see other games in the world at large, I must be running my server to host game lists at my house. However, you should always be able to see games in your lan. And in the worst case, you can type in your friend's ip address and port number manually. I order to host a game, you must open up a port on your router so that connections can find their way to your computer. This is a disadvantage.

Tools

The main new tool that I used was sockets. It was a little bit tricky because I needed the connection to be two-way. The way the process works when you are playing online, there is one master computer that hosts the game. That computer handles all the physics, collisions, etc of the game and send updated versions of the game out to any connected computers, which should be listening for updates. Those connected computers can also send requests like "turn the booster off for the ship of player 2". The master computer listens for these requests and implements them as they come in.

I also used a lot of things I usually use for these kinds of projects: Swing, threads, functional interfaces, lambda expressions, graphics, etc etc.

Future Work / Improvements

  • Gameplay suffers massively when the two computers playing the same game online are far apart / have latency issues. A way I could fix this is by having each computer be in charge of its local players' own positions and reporting those positions back to the master computer, rather than having the computers send requests to move back to the master computer. This should be fairly feasible, but I don't have time to fix it right now.
  • The user interface is still somewhat janky and if I had unlimited time, I'd like to clean it up somewhat.
  • I'd like to make a point-of-view mode where you are playing from an individual ship's point of view.

Conclusions

This game was pretty fun to write and I'm fairly satisfied with how it turned out. Though I was motivated to start it mainly to work on sockets / internet connections, I did actually spend most of my time writing code that had nothing to do with that. Nonetheless, I did learn about some socket / internet stuff and am glad I worked on this project.