Game Development Reference
In-Depth Information
The code queues a
event. Note that in a commercial game, this
wouldn ' t be hard-coded to the left mouse button necessarily. Instead, there would
be an intermediate layer that translated specific user interface events into mappable
game events, which enables the user to set up his keyboard and mouse the way he
likes it.
Fire Weapon
Hard-Coded WASD
The first game I worked on as an engineer was Barbie Diaries: High School
Mystery. The input system used a hard-coded WASD key configuring. We
were an adventure game company, so key configuration wasn
t a huge issue
for us. Unfortunately, the next project ended up being on the PlayStation 3, so
I was assigned the task of rewriting that system. It was pretty grueling, but I
learned a huge amount about designing an input system API. Sometimes the
painful tasks are the ones you learn the most from.
'
Here
'
s the OnUpdate() method of the controller:
void TeapotController::OnUpdate(DWORD const deltaMilliseconds)
{
if (m_bKey[
'
W
'
] || m_bKey[
'
S
'
])
{
const ActorId actorID = m_object->VGet()->ActorId();
shared_ptr<EvtData_Thrust> pEvent(
GCC_NEW EvtData_Thrust(actorID, m_bKey[
'
W
'
]? 1.0f : -1.0f));
IEventManager::Get()->VQueueEvent(pEvent);
}
if (m_bKey[
'
A
'
] || m_bKey[
'
D
'
])
{
const ActorId actorID = m_object->VGet()->ActorId();
shared_ptr<EvtData_Steer> pEvent(
GCC_NEW EvtData_Steer(actorID, m_bKey[
'
A
'
]? -1.0f : 1.0f ));
IEventManager::Get()->VQueueEvent(pEvent);
}
}
The controller keeps a record of what keys are down on the keyboard, and it
responds to the mouse-down event as well. Since the controller implements the
IMouseHandler and IKeyboardHandler interfaces, it wires in nicely to the base
HumanView class. The interface events are translated into the two gameplay events
that are handled in Lua:
Thrust
and
Steer.
You
'
ll see their definitions later on in
this chapter.
 
Search WWH ::




Custom Search