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've got problems or questions, join the official SGDK Discord! It's full of people a lot smarter and skilled than me. Of course you're also welcome to just hang out and have fun!
Download the Project Files!All patrons on Patreon get the complete source code for this tutorial, as well as other perks such as early access! And Patreon support also ensures that I can keep working on tutorials like this one. Become a Patron!
Just Want to Buy Me a Coffee?
Check out the rest of this tutorial series!
If you’ve popped over to the tutorial section recently you might have noticed that I’ve added my very first HaxeFlixel tutorial! It shows how to implement a simple, pixel-perfect 2D water shader which I used for Go! Go! PogoGirl. But a few of you might be wondering what a HaxeFlixel is. Well, it’s a 2D game framework that is as powerful as it is underrated! It runs on the (also underrated) Haxe language, is extremely well documented, open source, and has built-in functions for almost anything you’d need.
As I’m sure many of you will remember, the original Streets of Rage for the Mega Drive had multiple endings. The real canonical ending has you beat the crap out of Mr. X, thereby ending his reign of terror forever (yeah, right). However, if you confronted Mr. X with a buddy in tow, a new possible path unlocked. A quick refresher is in order. When you confront Mr. X he will ask you to join his organization.
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.