radian-software / TerrariaClone

🔥 An incomprehensible hellscape of spaghetti code.
MIT License
1.8k stars 134 forks source link

TerrariaClone

Discussed on: Hacker News, /r/programming, /r/programminghorror, /r/shittyprogramming.

Back when I was first learning to program in Java, I decided to try to make a clone of the excellent PC game Terraria. Of course, I was convinced that my version would have many more features than the official one.

But before I realized how silly that idea was, I produced 11,000 lines of, to date, the most atrocious code I have ever seen in my life. I make it available here mostly as a cautionary tale of what can happen if you don't pay attention to the quality of your code. (Lesson learned, in my case!) Here are some of the highlights:

Now, when importing this project into version control (you thought I was using version control when I wrote this??), I did fix a few of the most blatantly horrible style violations -- for instance, I normalized the whitespace, although other improvements (for example, removing the over 500 cases of unnecessary boxing) have been reverted by popular demand in the name of historical integrity. I also tried to get the main game actually working, which meant fixing a few resource path issues. Unfortunately, it's only working in the academic sense, since it's so slow that you only get about 0.03 FPS and it crashes when you click the mouse button. But, somewhere in there is a working game. You know, sort of.

Build and run

$ mkdir -p out
$ javac -d out src/*.java
$ java -cp out:textures TerrariaClone

As mentioned previously, although it runs, it fails to run very well. See this pull request.

TerraFrame?

This project was originally called TerraFrame (back when I created it in 2011). I believe the reasoning was that it was a Terraria clone, and it was in a JFrame. Yes, it's stupid, much like every other part of this project. Meanwhile, there is a completely unrelated company called TerraFrame. This led to an unfortunate misunderstanding wherein somebody thought that this garbage heap of a codebase was associated in some way with TerraFrame, the company. After receiving a very polite email pointing out the issue, I've changed the name to something that makes more sense (TerrariaClone).

Python?

You may notice a subdirectory named python. What is this, you ask? Why, nothing other than the original version of TerrariaClone, from before I rewrote it into Java! And yes, it's even more primitive, although I at least had a bit more understanding of idiomatic programming in Python than in Java.