Following the release of IronHax and TubeHax for 3DS prompted me into looking at 3DS Homebrew. I had previously attempted to create some DS homebrew but was quickly turned off by the nonsense of C and C++.
Initially I looked at a "Hello World" example and wrote it line for line, but it would not compile, giving an error that an escape command was attempting to do something unexpected. After several attempts that did not rectify the problem, I instead just copy-pasted the example and it compiled fine despite the code being identical. Code gonna code, I guess.
After examining some more text based functionality, I then turned my hand to rendering. However the example project would not compile no matter what I tried, citing that something was missing. Being unable to figure out what it was, I then took the source code for a finished game and attempted to compile that and was successful. Now the question for me was - what do I attempt to develop?
I wanted something simple. As much as everybody loves to dive in and try and make something like one of their favourite games, attempting to make Pokémon at this point isn't really an uphill battle but more of brick wall that will eventually topple backwards and squash you. I decided to look at mobile games for inspiration, and then realised I had made Tic Tac Toe for Android with relative ease, so decided to do that.
I had originally copied the bulk of the code into the main.cpp file (like the example game had done), but after receiving errors about things not being declared in the scope, I decided it was better to separate it into it's own class. This got rid of most of the scope errors, as I declared everything in the header first, but then there were issues with syntax where Java likes arrays to be int val and C++ prefers int val. After eventually getting no compile errors (Yay!) with the ported logic, it was time to turn my attention to input and rendering.
Most of the stuff I had studied so far had referred to button inputs. But, I wanted to utilise the touch screen - this was an Android port after all. In the Android version, each box in the grid is actually an invisible button which has code that runs following a touch event, returning whether the button was touched or not. This meant bringing the button code over too. Soon after, everything compiled with no errors once more.
|The main screen of Tic Tac Toe - Screenshot captured using Citra|
|Computer player wins|
|A winner is you!|
The source code and .3dsx file are located here.