My brain makes things explode.
Posts tagged Direct3D
C++/D3D Pong Tutorial 04: Adding Keyboard Input
Apr 25th
Tutorial Description
In the last tutorial, we established a rendering engine and got scene objects working, with basic physics. In this tutorial, we are going to implement the initial Input manager, which will be focusing on the keyboard. I was planning to include mouse input, but it turns out that DirectInput only handles the mouse in relative positioning – which is perfect for three-dimensional first-person shooter games that need to track the movement of the mouse – but it’s poor for two-dimensional casual games. For those of you that do wish to use mouse input, I will be covering it a later tutorial – the methods of getting absolute positioning will require a bit of modification to our engine.
Downloads
Please note that I’ve switched to using 7-zip in place of WinRAR for compression
Binary Only (20.4KB)
Full VS2010 Project Dir (26.8KB)
SVN Repository
As of this tutorial, I have created and added a Subversion repository on Assembla to store the code for the tutorial series. I will continue to upload the source for each tutorial – the SVN will merely contain the code as I write it, so you can feel free to play around with the code that I’m working on before I release a tutorial. Mostly, this is to help people play around with things if there’s a point where I’m slow to create the tutorial following the code (as was the case with this tutorial).
SVN URL: http://svn2.assembla.com/svn/d3dpong
Starting Words
Notice: This tutorial continues from where “C++/D3D Pong Tutorial 03” article left off. Please read it if you have not already.
Another update.
Apr 21st
Well, this has been a busier week than I’d thought. I’ve been more exhausted from the rifle range than I’d anticipated, and while I’ve gotten the code pulled back up and compiled on my reinstall of Windows, I haven’t gotten around to actually writing the tutorial. I have gotten a little work done on it, but not much. And this weekend, I’m probably going to be making another trip to Phoenix, and you can’t count on me to get any work done on my tutorials when I’m spending time with Erin – no offense, but she’s much better company. ;)
Anybody who’s been to my blog more than one time will probably notice that I’ve changed the theme. I’m just playing around with some different themes and such, and I’ve been in a very Apple mood recently, so I decided to pop that up. Other than the time I’ve been able to spend with Erin, nothing’s really changed about my life, that’s worth mentioning, so I guess that about wraps things up here.
Sorry for those who are still waiting on the next tutorial! I’ve got a project that popped up that I’m playing around with as far as Torque goes, but I’m still planning on working through writing up the next tutorial. I’ll probably create a Google Code project for the tutorial series, so that people can get the most up-to-date code from a Subversion repository and play with things themselves, but I haven’t really gotten around to doing anything at all recently. >.>
Some Changes
Apr 7th
For those of you watching my Direct3D tutorial series, I apologize for the continued delay of the Keyboard Input tutorial. I’ve been having some life issues coming up recently, and have been putting in ridiculously late hours at work, all of which take priority. I also got Red Steel 2 and Final Fantasy XIII (and a DSi XL), so my time’s been stolen. Decided it was time for a fresh start on my computer (I do that every now and then), and I was too lazy to download the copy of Windows 7 Ultimate that I had pre-ordered while I was in Afghanistan, so I installed Xubuntu for a while (I feel dirty. I really don’t like Ubuntu. It takes away the only reason anybody should ever want Linux in the first place.) Don’t worry, because I backed up the project files, and I’m going to be reinstalling Windows 7 tonight – assuming I get off work at a reasonable time – and will be able to continue the D3D Pong series.
Which brings me around to my next point. Unlike what I had planned, I am probably not going to be continuing this engine after the Pong clone is complete. I just don’t seem to have the time anymore, and I feel that my time is better spent with Erin and working on other life issues than releasing these tutorials. In short, I don’t feel that I could release the series in a timely manner. Don’t get me wrong, I’m still going to be programming, and I will still be developing tutorials – even a couple series tutorials. I’m just not going to be worrying about releasing the tutorials on any sort of deadline, and most of them will be one-shot tutorials (kind of like my XBOX 360 Controller Input tutorial at CodeProject).
Sorry if this is bad news for anybody, but you gotta do what you gotta do. I’ll still be available for help, if you want it. Best place to hit me up is #snoopy at Keyboard-Failure.
Beh
Mar 28th
Alright, so I thought I’d give a bit of an update, since I was trying to release the next tutorial in the D3D Pong series today. I spent this week (meaning my twenty-first birthday) with my girlfriend, and while I have the code written and in usable condition (written while she was at work), I have some tinkering to do to get the mouse input working properly, and then I have to actually write up the tutorial. I’m also in the process of setting up a GIT repository for the game engine, in which I will store the latest changes to the engine. But right now, my mind is still in Phoenix, and I’m not in the mood to write up the next bit of the tutorial. I will give you a bit of a roadmap for what is to come in the future, though: (subject to change)
Tutorial 4: Input
Tutorial: Basic Collision Detection and building the Pong prototype
Tutorial: Audio
Tutorial: Piecing the Game Together
Tutorial: High Scores
Polishing Addon: Shaders
Polishing Addon: “Event”-based programming
Polishing Addon: Particle Systems
C++/D3D Pong Maintenance: The Game Loop/Frame Delta
Mar 25th
Tutorial Description
While running the game/engine that we’ve been developing throughout this tutorial series, you may have noticed that the engine kind of runs… like crap. So, before moving onto the next tutorial in the series (the code for which is completed), which will cover keyboard and mouse input, I feel that it’s somewhat important to fix this. It’s just going to be some small updates to CGameEngine.cpp, so it won’t be hard.
Code Listing 1: CGameEngine.cpp -> CGameEngine::CGameEengine(void)
First, we’re going to correct an error with our game timer, which we never actually created an instance of in code – causing the GetRunTime feature to fail due to a member variable not being initialized (CGameTimer::_start). Replace the constructor for CGameEngine with the following, in CGameEngine.cpp
CGameEngine::CGameEngine(void)
: _windowHandle(NULL), _windowTitle(L"D3DPong"),
_screenWidth(640), _screenHeight(480), _colorDepth(32),
_gameRunning(true), _gameTimer(new CGameTimer())
{
}
Code Listing 2: CGameEngine.cpp -> CGameEngine::Update(void)
Our new Update method is much smaller than it was before. We’re still using fast-as-possible rendering and updating, so this isn’t going to fix the minor graphics tearing that you’ve no doubt noticed before this, but it is going to make things run a little better.
void CGameEngine::Update(void)
{
float delta = this->_gameTimer->GetRunTime();
GameUpdate(delta);
this->_gameTimer->Reset();
this->BeginRender();
GameRender(delta);
this->EndRender();
}
Nicer, cleaner, shorter. This was caused by a bit of an inconsistency and laziness on my part, but things should run a bit smoother now. In the next tutorial, we’re going to be adding input, and will put the beginning pieces of our game into effect. I’ll cover enabling VSync at a later point, because I’m too lazy to deal with it right now. It’ll probably be in another “Maintenance” mini-tutorial.
Expect Tutorial 4 soon!
