Game Development Reference
In-Depth Information
// Ramp the acceleration by the elapsed time.
float numberOfSeconds = 2.0f;
m_currentSpeed += m_maxSpeed * ( (elapsedTime*elapsedTime) / numberOfSeconds);
if (m_currentSpeed > m_maxSpeed)
m_currentSpeed = m_maxSpeed;
The elapsed time should be a floating-point number measuring the number of sec-
onds it has been since the last time this code was called. It turns out that humans
have a keen sense of how things should accelerate, probably because we watch things
fall under the acceleration of gravity all the time. If those things are coconuts and we
happen to be standing beneath them, this skill becomes quite life saving. Whenever
you accelerate anything related to a control in your game, always accelerate it with a
time-squared component so that it will
feel
more natural.
Working with the Keyboard
There are many ways to grab keyboard input from Win32. They each have their good
and bad points, and to make the right choice, you need to know how deep you need
to pry into keyboard input data. Before we discuss these various approaches, let
'
s get
'
a few vocabulary words out of the way so that we
re talking the same language:
n Character code: Describes the ASCII or UNICODE character that is the return
value of the C function, getchar() .
n Virtual scan code: Macros defined in Winuser.h that describe the components
of data sent in the wParam value of WM_CHAR , WM_KEYDOWN , and WM_KEYUP
messages.
n OEM scan code: The scan codes provided by OEMs. They are useless unless you
care about coding something specific for a particular keyboard manufacturer.
Those definitions will resonate even more once you ' ve seen some data, so let ' s pry
open the keyboard and do a little snooping.
Mike
s Keyboard Snooper
I wrote a small program to break out all the different values for Windows keyboard
messages, and as you
'
ll see shortly, this tool really uncovers some weird things that
take place with Windows. Taken with the definitions we just discussed, however,
you
'
ll soon see that the different values will make a little more sense. Each line in
the tables below contains the values of wParam and lParam for Windows keyboard
messages. I typed the following sequence of keys: 12ab , to produce the first table.
'
 
 
 
 
Search WWH ::




Custom Search