下面实现的方向控制是基于键盘上的W A S D,来控制运动物体的方向的。下面是实现~
#pragma once
//========================================================================
// File: MovementController.h 就是实现键盘按钮 WASD 的方向控制
//========================================================================
#include "../GameCode4/Interfaces.h"
#include "Geometry.h"
// Forward declarations
class SceneNode;
typedef unsigned int DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef unsigned int ActorId;
typedef unsigned int GameViewId;
typedef D3DXCOLOR Color;
typedef float FLOAT;
typedef unsigned int UINT;
#ifdef UNICODE
typedef wchar_t TCHAR;
#else
typedef unsigned char TCHAR;
#endif
typedef unsigned char CHAR;
typedef unsigned wchar_t WCHAR;
enum HRESULT
{
E_INVALIDARG,
E_FAIL,
S_OK,
};
//
// MovementController Description
//
// Implements a WASD style movement controller
//
// class MovementController
//
class IPointerHandler
{
public:
virtual bool VOnPointerMove(const Point &pos, const int radius) = 0;
virtual bool VOnPointerButtonDown(const Point &pos, const int radius, const std::string &buttonName) = 0;
virtual bool VOnPointerButtonUp(const Point &pos, const int radius, const std::string &buttonName) = 0;
};
class IKeyboardHandler
{
public:
virtual bool VOnKeyDown(const BYTE c)=0;
virtual bool VOnKeyUp(const BYTE c)=0;
};
class MovementCon