My First Game
Last updated: 03 January 2024
Posted on: 01 January 2024
Introduction
So I built my first game when I was 13. After having spent a lot of time modding Minecraft, I felt like it was time to expand my horizons. At the time game engines were outside of what I was capable of learning, so I decided that I would continue in Java and make my own game.
Start
I decided that I would start with a 2D game since I had no clue where to start with learning 3D programming. But the first step was going to be making a menu. After a lot of learning, I still couldn't figure out how to change what shows up on a screen from what was there originally. So I decided that I would handle this by changing windows. So when the game starts you get a screen with starting the game.
After clicking on the "Start Game" Button you'll be brought to the Main Menu screen.
It was pretty simple, and I have to say I think the colour scheme is on point (not foreboding my design skills at all). The neon blue and grey buttons are classic. There were 10 levels that you could complete. And buttons would appear as you would complete levels.
The Game
The game was pretty simple, and there was no real way of dying. You would start as a duck or moose and your job was to collect CPUs from around the level. Yes, that yellow at the bottom was by choice, and if you were to remove the mountains, you could walk around the yellow area.
In the game, you have a score and health. There were some traps left around the map that would knock your health down by 1 point each time. However, it was impossible to die since I never left enough traps to wipe out the player. Most of the traps were also unavoidable. If you started as a moose and your health would drop to 0, you would then be replaced by the duck and your health would go back up to 1. This was supposed to be because the moose was the second animal to join your group, but this wasn't communicated at all. Before Trap:
After Trap:
Reflecting
All in all, I'm pretty proud of my first "game". For a 13-year-old who had no clue about programming outside of Minecraft, I think past me did a really good job. Building the game I did require a lot of problem-solving, especially without much online help for what I was doing. If you wish to download the game and play it for yourself, its available here on Github: Download Link. If you're not interested in a little look at the code feel free to stop reading here.
Code Highlights
So here's the bit where I'm going to review the code, and hopefully not cringe too much. If you would like to dive into my code from 12 years ago, please feel free to dive into it on my Github: Jave Maze Game
The first thing that becomes obvious is that clearing I understood the basics of what a class was but hadn't figured out that they were reusable yet. This led to each map having its own class file. These were all just copied and pasted with the map text changed.
I clearly was trying to think of re-useablity for code, even if I hadn't figured out actually how to do it. You can tell this in the way I built the map system. Each map is actually stored as a text file with each character representing a different tile. Here's an example of one:
mmmmmmmmmmmmmmmmmmmmmmmmmmmfm
mbbbbbbbbbbbbbmbbbbmbbbmbbbbm
mbbmbmmmmmbbmbmbmmbmbmbmbmbbm
mbmmbmcbmbbbmbmbmbbbbmbbbmbbm
mbbmbmbbbbmbmbmbbmmmmmmmmmmmm
mmbmbmmmmmmbmbmmbbbbbbbbbbbbm
mbbmbbbbbbbbmbbmmmbmmmmmmmmbm
mbmmmmnmmbmmmmbbbbbbmbbbbbbbm
mbmpbbbmbbmbbbbmmbmbmbmmmmmbm
mbmmmmmmbbmbmmmmmbmbmbbmbbbbm
mbbbbbbbbbmbbmlbbbmbbbbmbmmmm
mbmmmmmmmmmmbmmmmmmmmmbmbmmmm
mbbbbbbbbbbbbbbbbbbbbbbbbbbbm
mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
I believe that M was a mountain, and v was void (so the yellow area). For everything else, I have no clue what it stood for. In terms of code, I would loop through this map after it was loaded and build it from there.
public void readFile() {
while(map.hasNext()){
for(int i = 0; i < 29; i++){
Tiles[i] = map.next();
}
}
}
Each tile was loaded as an ImageIcon from Java's famously amazing swing library and then drawn on the screen. Aside from the maps, everything else is weirdly not so bad. The only exception to this is the window files, each screen, and level having their own file. The code again is mostly copied and pasted from the first window file. A couple of other notable features are that I had plans to add links to the game. It seems like I was planning on doing this by starting a new Java program on my own, and opening the link as follows:
public static void main(String[] args) throws MalformedURLException, IOException, URISyntaxException{
try{
String url = "http://www.youtube.com/channel/UC9EzN5XNxhxqHZevM9kSuaw";
String cmd = "cmd.exe /c start " + url;
Runtime.getRuntime().exec(cmd);
}catch (Exception ex){
Desktop.getDesktop().browse(new URL("http://www.youtube.com/channel/UC9EzN5XNxhxqHZevM9kSuaw").toURI());
}
}
Though the method of starting a new program to do this was clearly not a good idea, how I went about doing so doesn't hurt too much, so I'm pretty impressed with 13-year-old me.
Code Conclusion
A lot of the concepts explored here are the basics of programming and are very much done poorly. However, for a 13-year-old exploring the world outside of modding Minecraft (and trying it in Java), I'm pretty proud. I didn't have the basics down yet, but I was already thinking about important concepts such as reusability, even if it was just to make it easier to copy and paste.