In this tutorial series you will learn how to make a simple single-player Pong-like game for the Sega Mega Drive using SGDK! If you just want to see the full source code, you can get it from Github.
Megapong 2 - Setting Up The Environment
Welcome back! Last time we set up SGDK and made sure everything worked. This time we’ll set up a proper development environment, which will make things a lot easier and more fun for us. Believe me, it’ll be worth it!
Code for SGDK is written in C, so you can use basically any IDE that supports C. Some popular choices are Code::Blocks or Eclipse. However, the one I use and the one I would definitely recommend is Visual Studio Code. It’s free, open source, cross-platform, extremely customizable and offers extensions that make SGDK coding easier! All explanations and steps given here will be for VSCode, so if you want to follow along I’d definitely recommend downloading it. However, if you’re already familiar with another C environment, feel free to stick with it. You shouldn’t have much trouble getting SGDK to comfortably work in it if you know what you’re doing. Now, let’s get cracking!
- The first step to installing VSCode is to download VSCode. You can do so here.
- The next step is to actually install it. If you want more information you can check the official website but simply double-clicking and picking “next” a bunch of times should work just fine.
- Finally, we’ll need to install some additional things to get SGDK working properly. First we’ll need support for the C language, which is done via the C/C++ extension. Open up the Extensions menu on the left-hand side of VSCode, type the extension name into the search field and install it. (If you need further info, check the official website.)
Adding Support for SGDK
Now we have a VSCode installation that knows what C is. Next we’ll have to teach it about SGDK! This is as easy as installing an extension. In fact, it is just installing an extension. The Genesis Code extension, that is! It has been developed by @zerasul especially for SGDK development and it will give us everything we need. Go ahead and install it!
So what does it do and how do we use it? Well first of all, it can help you quickly create a new SGDK project. With VSCode open, press
Ctrl + Shift + P to open VSCode’s command palette. Then select the command
Genesis Code: Create Project and a window will pop up, asking you to set the location of the new project. Once you’ve done that, the extension will automatically generate a full SGDK project at that location and open it in VSCode! Very cool.
Note: If you get an error message, make sure that the default integrated terminal is set to CMD. You can do this by opening the terminal (if it’s not open already) by using the command
View: Toggle Integrated Terminal from the command palette. Then click on the down arrow in the box that says
gens-code. Set it to cmd and restart VSCode. You can find more info on the terminal on the official VSCode website.
main.c in the
src folder and you’ll see that there already is a hello world line added. But let’s add another one to test another cool feature! In the next line, start typing
VDP_ and wait a second. A list of all functions starting with
VDP_ should pop up! This autocompletion is extremely useful since you won’t have to remember everything at once. Pick
VDP_drawText from the list and add another line of text somewhere else on the screen.
Now let’s compile the rom and see what it all looks like! This is the moment you might notice that there is no
compile.bat file anymore. But luckily we don’t need it! Open the command palette again and run the command
Genesis Code: Compile Project. A few seconds later your rom should be waiting for you in the
Compile and Run
This is already really cool, but there is one more thing we can automate. The Genesis Code extension can not only compile your game, but also run it in your emulator automatically! For that to work, first we need to tell it where we’re keeping our emulator. Open the command palette and run the
Genesis Code: Set Gens Emulator Command Path command. Then simply enter the path to your emulator in the prompt that pops up (for example C:\gensk\gens.exe).
And that was it! Now open the command palette and run the
Genesis Code: Compile & Run Project command. This will now compile your project, fire up your emulator and load your rom automatically. How’s that for saving time and work, eh?
Alright, now we have a proper development environment set up! Now we’re all set to do some actual coding and create our first game for the Mega Drive. In the next instalment we will learn about:
- Importing Resources
- Drawing tiles
All of these things are very important in Mega Drive coding, so stay tuned!
Thanks for reading! Until next time and be excellent to each other!
If you have any questions, comments or criticism, post them in the comments below or reach out to me on Twitter @ohsat_games! Special thanks to Stephane Dallongeville for creating SGDK and everyone in the SGDK Discord for their help and keeping the dream alive!
Download the source codeAll patrons on Patreon get the complete source code for this tutorial, as well as other perks such as early access! Become a Patron!
Just Want to Buy Me a Coffee?
Check out the rest of this tutorial series!
A few years ago, Yuzo Koshiro posted a pile of old game design documents for Bare Knuckle 2 aka Streets of Rage 2 on the Ancient blog to commemorate the release of Streets of Rage 2 3D on the Nintendo 3DS. These documents gave a deep insight into the game’s inner workings, technical aspects, designs and even some cut content. They were an awesome resource for one of the most awesome games ever created.