FicEngine: Joysticks and Input
The first system in the FicEngine I’d like to go into detail about is the Input Manager. I’ve come up with a very robust, extendable, and reusable system for input, and best of all it handles joysticks too!
One common mistake I see when it comes to input in games is coders will try to directly poll the state of their input devices, and execute code if say button 0×002F is down. Not only is this ugly, it’s also not cross platform, makes remapping controls a bitch, and it’s completely unusable when it comes to future projects. There’s also a few logical problems which I’ll talk about in a bit.
In the FicEngine, the user can register game controls with the Input Manager, which is a constant layer between the programmer and the input devices. Game controls all have mappings, which makes them easy to change. Not only this, but the Input Manager automatically handles the state of each input; maybe you only want something to happen when you press a key, not every frame while the key is held down. This was a huge drawback to the input system we were using in XBLA Marathon: because input devices were polled directly, the logic for detecting only the first frame a button was pressed had to be repeated in many places throughout the code. FicEngine solves this by having that constant layer in front of the programmer, which handles all that internally. You can then specify if you want a control to be on KeyDown only, every frame a key is down, KeyUp only (for instance, releasing a charged shot), or you can specify timed delays.
Now on to the real good stuff.
The FicEngine game controls can be mapped to the keyboard, mouse, or any USB joystick. It’s a goal of mine to work both a keyboard + mouse control scheme into my game designs, as well as a paddle-based control scheme. Effectively and intuitively using keyboard + mouse is crucial for Mac and PC games, and especially Mac, whose gamers are used to a user-friendly experience. But being able to play a game with a paddle brings it to a whole new level, and I’d be a fool not to support it for the console-type games I want to make.
I also have coded special support for the Xbox 360 Controller. It’s by far the best conventional controller I’ve held (I’d argue the Wiimote is just as fun, maybe more so for shooters like RE4 or the new Metroid Prime, but that’s hardly conventional) and as of this writing over 9 million Xbox 360s have been sold around the world. So if you have a 360, you’ll be able to plug your sticks into your Mac while playing a JustinFic game and get the VIP treatment! Normally it’s a pain in the ass to map controller buttons in games. You map one and the typical visual feedback you get is “Button 1″. What the fuck is button 1? Sure, it’s the button I just hit but GOD DAMN. With the 360 controller, not only can I refer to every single button by name, I can also have the entire controller laid out graphically on screen and even have some preset schemes the player can use, just like on a console. Excellent!
The other cool feature that the InputManager boasts is the concept of combos. Creating a combo is easy- just add another mapping to the control! DONE. Not only that, but combos can be of three types: Any, All, and Sequence. Any and All modes should be obvious: Any means that any key in the combo will trigger the control, so you can have several buttons for the same control (this is useful for me, since I use right click a lot in my games, and since some Mac users don’t use a multi-button mouse, I can use the Spacebar as a good alternative to right-click.) All mode means ALL buttons have to be down. A common example is command-q for quit.
The third mode is the cool one: Sequence mode. This means that every input needs to be entered in succession. This makes implementing cheat codes a trivial matter, and also allows me to code in complex combo moves like the Hadoken motion (Down, Down-Forward, Forward, Punch) or the Konami Code.
So that’s the Input system. I’ll be detailing more on the Engine in the days to come, so stay tuned!
No comments yet.