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.
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
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.
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.