青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

創建游戲內核(16)

 

本篇是創建游戲內核(15)的續篇,關于DirectInput使用的基礎知識請參閱使用DirectInput進行交互

 

輸入內核

通過鍵盤、鼠標和游戲桿,輸入內核提供了一種手段,使玩家能夠同游戲進行交互。使用兩個簡單的類:INPUT和INPUT_DEVICE產生輸入設備。INPUT類用來初始化DirectInput,而INPUT_DEVICE類用來包含一個DirectInput設備接口對象。如果要使用多個設備,需要對每個設備使用單獨的INPUT_DEVICE對象。

 

使用INPUT初始化DirectInput

使用輸入系統的第一步就是初始化DirectInput,這也是INPUT類的用途。

//============================================================================
// This class encapsulates DirectInput initialize and release.
//============================================================================
class INPUT
{
protected:
    HWND            _hwnd;
    IDirectInput8*  _directinput;

public:
    INPUT();
    ~INPUT();

    IDirectInput8*  get_directinput_com();
    HWND            get_hwnd();

    BOOL init(HWND hwnd, HINSTANCE inst);
    
void shutdown();
};

//---------------------------------------------------------------------
// Constructor, initialize member data.
//---------------------------------------------------------------------
INPUT::INPUT()
{
    
// only need to clear the DirectInput interface pointer
    _directinput = NULL;
}

//---------------------------------------------------------------------
// Release all DirectInput objects.
//---------------------------------------------------------------------
INPUT::~INPUT()
{
    
// force a shutdown
    shutdown();
}

//---------------------------------------------------------------------
// Return the parent window handle.
//---------------------------------------------------------------------
HWND INPUT::get_hwnd()
{
    
return _hwnd;
}

//---------------------------------------------------------------------
// Return a pointer to IDirectInput8 object.
//---------------------------------------------------------------------
IDirectInput8* INPUT::get_directinput_com()
{
    
return _directinput;
}

//---------------------------------------------------------------------
// Create DirectInput and set window handle which pointer parent window.
//---------------------------------------------------------------------
BOOL INPUT::init(HWND hwnd, HINSTANCE inst)
{
    
// free DirectInput resource first
    shutdown();

    
// record parent window handle
    _hwnd = hwnd;

    
// create a DirectInput interface
    if(FAILED(DirectInput8Create(inst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**) &_directinput, NULL)))
        
return FALSE;

    
return TRUE;
}

//---------------------------------------------------------------------
// Release all DirectInput objects.
//---------------------------------------------------------------------
void INPUT::shutdown()
{
    Release_COM(_directinput);

    _hwnd = NULL;
}
 
 


輸入設備和INPUT_DEVICE

INPUT_DEVICE類是輸入內核中真正起作用的類,INPUT_DEVICE類用于初始化一種特定的輸入設備(鍵盤、鼠標、游戲桿),并提供一種取得游戲使用的設備信息的方法。

//============================================================================
// This class encapsulate for all input devices (keyboard, mouse, joystick).
//============================================================================
class INPUT_DEVICE
{
public:
    INPUT*                  m_input;
    IDirectInputDevice8*    m_di_device;

    
short                   m_type;             // device type, can be (MOUSE, KEYNOARD, JOYSTICK)
    BOOL                    m_use_window_mode;  // whether use window mode to read mouse coordinate

    
char                    m_state[256];       // all keys information and button press information

    DIMOUSESTATE*           m_mouse_state;      
// pointer to mouse state information
    DIJOYSTATE*             m_joystick_state;   // pointer to joystick state information

    BOOL                    m_locks[256];       
// lock flags for keyboard or button

    
long                    m_x_pos, m_y_pos;   // mouse or joystick coordinate

    
static BOOL FAR PASCAL  enum_joysticks(LPCDIDEVICEINSTANCE device_inst, LPVOID ref);

public:
    INPUT_DEVICE();
    ~INPUT_DEVICE();

    IDirectInputDevice8* get_device_com();

    BOOL create(INPUT* input, 
short type, BOOL window_mode = TRUE);
    
void free();

    
void clear();
    BOOL read();
    BOOL acquire(BOOL is_active = TRUE);

    BOOL get_lock(unsigned 
char index);
    
void set_lock(unsigned char index, BOOL lock_flag = TRUE);

    
long get_x_pos();
    
void set_x_pos(long x_pos);
    
long get_y_pos();
    
void set_y_pos(long y_pos);
    
long get_x_delta();
    
long get_y_delta();

    
// keyboard specific functions
    BOOL get_key_state(unsigned char index);
    
void set_key_state(unsigned char index, BOOL state);
    BOOL get_pure_key_state(unsigned 
char index);
    
short get_key_press(long timeout = 0);
    
long get_num_key_press();
    
long get_num_pure_key_press();

    
// mouse/joystick specific functions
    BOOL get_button_state(unsigned char index);
    BOOL set_button_state(unsigned 
char index, BOOL state);
    BOOL get_pure_button_state(unsigned 
char index);
    
long get_num_button_press();
    
long get_num_pure_button_press();
};

來看看它的實現:

//---------------------------------------------------------------------
// Constructor, initialize member data.
//---------------------------------------------------------------------
INPUT_DEVICE::INPUT_DEVICE()
{
    m_input = NULL;
    m_di_device = NULL;

    m_type = NONE;          
// setup device to none
    m_use_window_mode =  TRUE;  // set windowed usage to TRUE

    // point the mouse and joystick structures to the state buffer
    m_mouse_state    = (DIMOUSESTATE*) &m_state;
    m_joystick_state = (DIJOYSTATE*) &m_state;

    
// clear the device variables
    clear();
}

//---------------------------------------------------------------------
// Destructor, free resource.
//---------------------------------------------------------------------
INPUT_DEVICE::~INPUT_DEVICE()
{
    free();
}

//---------------------------------------------------------------------
// Return the pointer to the IDirectDevice8 object
//---------------------------------------------------------------------
IDirectInputDevice8* INPUT_DEVICE::get_device_com()
{
    
return m_di_device;
}

//---------------------------------------------------------------------
// Create DirectInput device with specified type.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::create(INPUT* input, short type, BOOL window_mode)
{
    DIDATAFORMAT* data_format;

    
// free a pior device
    free();

    
// check for a valid parent INPUT class
    if((m_input = input) == NULL)
        
return FALSE;

    
// create the device and rember device data format
    switch(type)
    {
    
case KEYBOARD:
        
if(FAILED(m_input->get_directinput_com()->CreateDevice(GUID_SysKeyboard, &m_di_device, NULL)))
            
return FALSE;

        data_format = (DIDATAFORMAT*) &c_dfDIKeyboard;
        
break;

    
case MOUSE:
        
if(FAILED(m_input->get_directinput_com()->CreateDevice(GUID_SysMouse, &m_di_device, NULL)))
            
return FALSE;

        data_format = (DIDATAFORMAT*) &c_dfDIMouse;
        
break;

    
case JOYSTICK:
       
if(FAILED(m_input->get_directinput_com()->EnumDevices(DI8DEVCLASS_GAMECTRL, enum_joysticks, this
           DIEDFL_ATTACHEDONLY)))
           
return FALSE;

       
if(m_di_device == NULL)
           
return FALSE;

       data_format = (DIDATAFORMAT*) &c_dfDIJoystick;
       
break;

    
default:
        
return FALSE;
    }

    
// set the windowed usage
    m_use_window_mode = window_mode;

    
if(FAILED(m_di_device->SetDataFormat(data_format)))
        
return FALSE;

    
if(FAILED(m_di_device->SetCooperativeLevel(m_input->get_hwnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
        
return FALSE;

    DIPROPRANGE prop_range;
    DIPROPDWORD prop_dword;

    
// set the special properties if it's a joystick
    if(type == JOYSTICK)
    {
        
// set the special properties of the joystick (range)
        prop_range.diph.dwSize       = sizeof(DIPROPRANGE);
        prop_range.diph.dwHeaderSize = 
sizeof(DIPROPHEADER);
        prop_range.diph.dwHow        = DIPH_BYOFFSET;
        prop_range.lMin              = -1024;
        prop_range.lMax              = +1024;

        
// set x range
        prop_range.diph.dwObj = DIJOFS_X;

        
if(FAILED(m_di_device->SetProperty(DIPROP_RANGE, &prop_range.diph)))
            
return FALSE;

        
// set y range
        prop_range.diph.dwObj = DIJOFS_Y;

        
if(FAILED(m_di_device->SetProperty(DIPROP_RANGE, &prop_range.diph)))
            
return FALSE;

        
// set the special properties of the joystick (deadzone 12%)
        prop_dword.diph.dwSize       = sizeof(DIPROPDWORD);
        prop_dword.diph.dwHeaderSize = 
sizeof(DIPROPHEADER);
        prop_dword.diph.dwHow        = DIPH_BYOFFSET;
        prop_dword.dwData            = 1200;

        
// set x deadzone
        prop_dword.diph.dwObj = DIJOFS_X;

        
if(FAILED(m_di_device->SetProperty(DIPROP_DEADZONE, &prop_dword.diph)))
            
return FALSE;

        
// set y deadzone
        prop_dword.diph.dwObj = DIJOFS_Y;

        
if(FAILED(m_di_device->SetProperty(DIPROP_DEADZONE, &prop_dword.diph)))
            
return FALSE;
    }

    
// acquire the device for use
    if(FAILED(m_di_device->Acquire()))
        
return FALSE;

    
// set the device type
    m_type = type;

    
return TRUE;
}

//---------------------------------------------------------------------
// Release DirectInput device resource, reset state informations and 
// lock flags.
//---------------------------------------------------------------------
void INPUT_DEVICE::free()
{
    
// unaquire and release the object
    if(m_di_device != NULL)
    {
        m_di_device->Unacquire();
        release_com(m_di_device);
    }

    
// set to no device installed
    m_type = NONE;

    
// clear state information and lock flags, reset mouse or joystick position.
    clear();
}

//---------------------------------------------------------------------
// clear state information and lock flags, reset mouse or joystick 
// position.
//---------------------------------------------------------------------
void INPUT_DEVICE::clear()
{
    ZeroMemory(&m_state, 256);

    
for(short i = 0; i < 256; i++)
        m_locks[i] = FALSE;

    m_x_pos = m_y_pos = 0;
}

//---------------------------------------------------------------------
// Read data from DirectInput device.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::read()
{
    
long buffer_sizes[3] = { 256, sizeof(DIMOUSESTATE), sizeof(DIJOYSTATE) };

    
// make sure to have a valid IDirectInputDevice8 object
    if(m_di_device == NULL)
        
return FALSE;

    
// make sure devicec type if in range
    if(m_type < 1 || m_type > 3)
        
return FALSE;

    HRESULT rv;

    
// loop polling and reading until succeeded or unknown error, also take care of lost-foucs problems.
    while(1)
    {
        m_di_device->Poll();

        
// read in state
        if(SUCCEEDED(rv = m_di_device->GetDeviceState(buffer_sizes[m_type-1], (LPVOID) &m_state)))
            
break;
        
        
// return on an unknown error
        if(rv != DIERR_INPUTLOST && rv != DIERR_NOTACQUIRED)
            
return FALSE;

        
// reacquire an try again
        if(FAILED(m_di_device->Acquire()))
            
return FALSE;
    }

    
// since only the mouse coordinate are relative, you will have to deal with them now.
    if(m_type == MOUSE)
    {
        
// if windowed usage, ask windows for coordinates
        if(m_use_window_mode)
        {
            POINT mouse_pos;

            GetCursorPos(&mouse_pos);
            ScreenToClient(m_input->get_hwnd(), &mouse_pos);

            m_x_pos = mouse_pos.x;
            m_y_pos = mouse_pos.y;
        }
        
else
        {
            m_x_pos += m_mouse_state->lX;
            m_y_pos += m_mouse_state->lY;
        }
    }

    
// released keys and button need to be unlocked
    switch(m_type)
    {
    
case KEYBOARD:
        
for(short i = 0; i < 256; i++)
        {
            
if(! (m_state[i] & 0x80))
                m_locks[i] = FALSE;
        }
        
break;

    
case MOUSE:
        
for(short i = 0; i < 4; i++)
        {
            
if(! (m_mouse_state->rgbButtons[i]))
                m_locks[i] = FALSE;
        }
        
break;

    
case JOYSTICK:
        
for(short i = 0; i < 32; i++)
        {
            
if(! (m_joystick_state->rgbButtons[i]))
                m_locks[i] = FALSE;
        }
        
break;
    }

    
return TRUE;
}

//---------------------------------------------------------------------
// Acquire or unacquire DirectInput device.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::acquire(BOOL is_active)
{
    
if(m_di_device == NULL)
        
return FALSE;

    
if(is_active)
        m_di_device->Acquire();
    
else
        m_di_device->Unacquire();

    
return TRUE;
}

//---------------------------------------------------------------------
// Get key or button lock flag with specified index.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::get_lock(unsigned char index)
{
    
return m_locks[index];
}

//---------------------------------------------------------------------
// Set lock flag.
//---------------------------------------------------------------------
void INPUT_DEVICE::set_lock(unsigned char index, BOOL lock_flag)
{
    m_locks[index] = lock_flag;
}

//---------------------------------------------------------------------
// Get x coordinate of mouse or joystick.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_x_pos()
{
    
// update coordinates if a joystick
    if(m_type == JOYSTICK)
        m_x_pos = m_joystick_state->lX;

    
return m_x_pos;
}

//---------------------------------------------------------------------
// Set x coordinate of mouse or joystick.
//---------------------------------------------------------------------
void INPUT_DEVICE::set_x_pos(long x_pos)
{
    m_x_pos = x_pos;
}

//---------------------------------------------------------------------
// Get y coordinate of mouse or joystick.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_y_pos()
{
    
// update coordinates if a joystick
    if(m_type == JOYSTICK)
        m_y_pos = m_joystick_state->lY;

    
return m_y_pos;

}

//---------------------------------------------------------------------
// Set y coordinate of mouse or joystick.
//---------------------------------------------------------------------
void INPUT_DEVICE::set_y_pos(long y_pos)
{
    m_y_pos = y_pos;
}

//---------------------------------------------------------------------
// Get x coordinate delta of mouse or joystick.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_x_delta()
{
    
switch(m_type)
    {
    
case MOUSE:
        
return m_mouse_state->lX;

    
case JOYSTICK:
        
return m_joystick_state->lX - m_x_pos;
    }

    
return 0;
}

//---------------------------------------------------------------------
// Get y coordinate delta of mouse or joystick.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_y_delta()
{
    
switch(m_type)
    {
    
case MOUSE:
        
return m_mouse_state->lY;

    
case JOYSTICK:
        
return m_joystick_state->lY - m_y_pos;
    }

    
return 0;
}

//---------------------------------------------------------------------
// Check if key/button is pressed, check lock flag.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::get_key_state(unsigned char index)
{
    
if((m_state[index] & 0x80) && m_locks[index] == FALSE)
        
return TRUE;

    
return FALSE;
}

//---------------------------------------------------------------------
// Set key state for specified key.
//---------------------------------------------------------------------
void INPUT_DEVICE::set_key_state(unsigned char index, BOOL state)
{
    m_state[index] = state;
}

//---------------------------------------------------------------------
// Check if key/button is pressed, do not check lock flag.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::get_pure_key_state(unsigned char index)
{
    
return (m_state[index] & 0x80) ? TRUE : FALSE;
}

//---------------------------------------------------------------------
// Get key which has been pressed and return it's ascii value.
//---------------------------------------------------------------------
short INPUT_DEVICE::get_key_press(long timeout)
{
    
// Retrieves the active input locale identifier (formerly called the keyboard layout) for the specified thread. 
    // If the idThread parameter is zero, the input locale identifier for the active thread is returned.
    static HKL keyboard_layout = GetKeyboardLayout(0);

    
// make sure it's a keyboard and it is initialized
    if((m_type != KEYBOARD) || (m_di_device == NULL))
        
return 0;

    
// calculate end time for timeout
    unsigned long end_time = GetTickCount() + timeout;

    unsigned 
char win_key_states[256], di_key_states[256];

    
// loop until timeout or key pressed
    while(1)
    {
        
// get windows keyboard state
        GetKeyboardState(win_key_states);

        
// get DirectInput keyboard state
        m_di_device->GetDeviceState(256, di_key_states);

        
// scan through looking for key presses
        for(unsigned short i = 0; i < 256; i++)
        {
            
// if one found, try to convert it.
            if(di_key_states[i] & 0x80)
            {
                unsigned 
short scan_code = i;
                unsigned 
short virtual_key, ascii_char;

                
// get virtual key code
                if((virtual_key = MapVirtualKeyEx(scan_code, 1, keyboard_layout)))
                {
                    
// get ascii code of key and return it
                    if(ToAsciiEx(virtual_key, scan_code, win_key_states, &ascii_char, 0, keyboard_layout))
                        
return ascii_char;
                }
            }
        }

        
// check for timeout
        if(timeout && GetTickCount() > end_time)
            
return 0;
    }

    
return 0;
}

//---------------------------------------------------------------------
// Return number of key which have been pressed down, check lock flag.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_num_key_press()
{
    
long num = 0;

    
for(long i = 0; i < 256; i++)
    {
        
if((m_state[i] & 0x80) && m_locks[i] == FALSE)
            num++;
    }

    
return num;
}

//---------------------------------------------------------------------
// Return number of key which have been pressed down, ignore lock flag.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_num_pure_key_press()
{
    
long num = 0;
    
    
for(long i = 0; i < 256; i++)
    {
        
if(m_state[i] & 0x80)
            num++;
    }

    
return num;
}

//---------------------------------------------------------------------
// Return button state of mouse or joystick, check lock flag.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::get_button_state(unsigned char index)
{
    
char state = 0;

    
if(m_type == MOUSE)
        state = m_mouse_state->rgbButtons[index];

    
if(m_type == JOYSTICK)
        state = m_joystick_state->rgbButtons[index];

    
// check if key/button is pressed
    if((state & 0x80) && m_locks[index] == FALSE)
        
return TRUE;

    
return FALSE;
}

//---------------------------------------------------------------------
// Set button state of mouse or joystick.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::set_button_state(unsigned char index, BOOL state)
{
    
if(m_type == MOUSE)
    {
        m_mouse_state->rgbButtons[index] = state;
        
return TRUE;
    }

    
if(m_type == JOYSTICK)
    {
        m_joystick_state->rgbButtons[index] = state;
        
return TRUE;
    }

    
return FALSE;
}

//---------------------------------------------------------------------
// Return button state of mouse or joystick, ignore lock flag.
//---------------------------------------------------------------------
BOOL INPUT_DEVICE::get_pure_button_state(unsigned char index)
{
    
if(m_type == MOUSE)
        
return m_mouse_state->rgbButtons[index];

    
if(m_type == JOYSTICK)
        
return m_joystick_state->rgbButtons[index];

    
return FALSE;
}

//---------------------------------------------------------------------
// Return number of buttons of mouse and joystick which have been pressed 
// down, check lock flag.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_num_button_press()
{
    
long num = 0;

    
if(m_type == MOUSE)
    {
        
for(long i = 0; i < 4; i++)
        {
            
if((m_mouse_state->rgbButtons[i] & 0x80) && m_locks[i] == FALSE)
                num++;
        }
    }
    
else if(m_type == JOYSTICK)
    {
        
for(long i = 0; i < 32; i++)
        {
            
if((m_joystick_state->rgbButtons[i] & 0x80) && m_locks[i] == FALSE)
                num++;
        }
    }

    
return num;
}

//---------------------------------------------------------------------
// Return number of buttons of mouse and joystick which have been pressed 
// down, ignore lock flag.
//---------------------------------------------------------------------
long INPUT_DEVICE::get_num_pure_button_press()
{
    
long num = 0;

    
if(m_type == MOUSE)
    {
        
for(long i = 0; i < 4; i++)
        {
            
if(m_mouse_state->rgbButtons[i] & 0x80)
                num++;
        }
    }
    
else if(m_type == JOYSTICK)
    {
        
for(long i = 0; i < 32; i++)
        {
            
if(m_joystick_state->rgbButtons[i] & 0x80)
                num++;
        }
    }

    
return num;
}

//---------------------------------------------------------------------
// Enumerate first usable joystick.
//---------------------------------------------------------------------
BOOL FAR PASCAL INPUT_DEVICE::enum_joysticks(LPCDIDEVICEINSTANCE device_inst, LPVOID ref)
{
    INPUT_DEVICE* input_device = (INPUT_DEVICE*) 
ref;

    
// stop enumeration if no parent INPUT_DEVICE pointer
    if(input_device == NULL)
        
return DIENUM_STOP;

    IDirectInput8* di = input_device->m_input->get_directinput_com();

    
// try to create a joystick interface
    if(FAILED(di->CreateDevice(device_inst->guidInstance, &input_device->m_di_device, NULL)))    
        
return DIENUM_CONTINUE;    

    
// all done, stop enumeration.
    return DIENUM_STOP;
}

INPUT_DEVICE類將所有的設備(鍵盤、鼠標、游戲桿)囊括在一個完美的包中。通過調用INPUT_DEVICE::create函數并傳遞一個預初始化的INPUT類對象,就可以使用INPUT_DEVICE類對象了。還需要給type參數設置一個合適的值(KEYBOARD、MOUSE或JOYSTICK),以告訴類要使用哪種設備。最后,還需要告訴類如何讀取鼠標狀態,包括使用DirectInput的設備讀取函數或windows的設備讀取函數兩種方式。將window_mode參數設置為TRUE會強制類對象使用windows的設備讀取函數,而使用FALSE就會強制類對象使用 DirectInput的設備讀取函數。如果計劃使用窗口應用程序(或希望windows光標可見),就要確將window_mode參數設置為TRUE。

使用INPUT_DEVICE::read函數可以讀取正在使用的設備的當前狀態。

下面編寫測試代碼:

點擊下載源碼和工程

/*****************************************************************************
PURPOSE:
    Test for class INPUT and INPUT_DEVICE.
*****************************************************************************/


#include "Core_Global.h"

class APP : public APPLICATION
{
private:
    GRAPHICS     _graphics;
    INPUT        _input;
    INPUT_DEVICE _keyboard;
    INPUT_DEVICE _mouse;
    INPUT_DEVICE _joystick;
    
    LONG _joystick_x, _joystick_y;

public:
    APP()
    {
        _joystick_x = _joystick_y = 0;
    }

    BOOL init();
    BOOL frame();
};

BOOL APP::init()
{
    
// initialie graphics
    if(! _graphics.init())
        
return FALSE;

    
// get screen width and height
    int screen_width  = GetSystemMetrics(SM_CXSCREEN);
    
int screen_height = GetSystemMetrics(SM_CYSCREEN);

    
// set display mode for graphics
    if(! _graphics.set_mode(get_hwnd(), TRUE, FALSE, screen_width, screen_height, 16))
        
return FALSE;

    
// initialize DirectInput
    _input.init(get_hwnd(), get_inst());    
    
    
// create keyboad, mouse, joystick
    _keyboard.create(&_input, KEYBOARD);
    _mouse.create(&_input, MOUSE, FALSE);
    _joystick.create(&_input, JOYSTICK, FALSE);

    
return TRUE;
}

BOOL APP::frame()
{
    
// clear display with specified color
    _graphics.clear_display(D3DCOLOR_RGBA(0, 0, 0, 255));  

    
// read current state information
    _keyboard.read();   
    _mouse.read();
    _joystick.read();

    
// begin scene
    if(_graphics.begin_scene())
    {        
        
// if key 'ESC' has been pressed, show message box.
        if(_keyboard.get_key_state(KEY_ESC))
        {
            
// lock this key
            _keyboard.set_lock(KEY_ESC, TRUE);
            
            
// show information
            MessageBox(get_hwnd(), "ESCAPE", "Key Pressed!", MB_OK);
        }

        
char buffer[200];

        
// if left button of mouse is pressed, show message box.
        if(_mouse.get_pure_button_state(MOUSE_LBUTTON))
        {           
            sprintf(buffer, "%ld, %ld", _mouse.get_x_pos(), _mouse.get_y_pos());
            MessageBox(get_hwnd(), buffer, "Mouse Coordinate!", MB_OK);
        }

        
if(_joystick.get_button_state(JOYSTICK_BUTTON0))
        {            
            MessageBox(get_hwnd(), "Joystick button0 is pressed down!", "Joystick", MB_OK);

            _joystick.set_lock(JOYSTICK_BUTTON0, TRUE);
        }

        
if(_joystick_x != _joystick.get_x_pos() || _joystick_y != _joystick.get_y_pos())
        {
            sprintf(buffer, "%ld, %ld", _joystick.get_x_pos(), _joystick.get_y_pos());
            MessageBox(get_hwnd(), buffer, "Joystick Coordinate!", MB_OK);
            
            _joystick_x = _joystick.m_x_pos;
            _joystick_y = _joystick.m_y_pos;
        }

        
// end the scene
        _graphics.end_scene();  
    }

    
// display video buffer
    _graphics.display();   

    
return TRUE;
}

int PASCAL WinMain(HINSTANCE inst, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
    APP app;

    
return app.run();
}
 

程序截圖:

按下游戲桿按鍵0:

獲得游戲桿的坐標:

按下鍵盤按鍵ESC:

按下鼠標左鍵:


posted on 2007-09-22 20:26 lovedday 閱讀(535) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩精品久久奇米色影视| 欧美韩日亚洲| 亚洲大胆美女视频| 性一交一乱一区二区洋洋av| 亚洲午夜成aⅴ人片| 亚洲一区二区三区三| 亚洲女同精品视频| 欧美自拍偷拍午夜视频| 久久久亚洲人| 亚洲电影免费在线| 亚洲性图久久| 久久米奇亚洲| 欧美日韩免费看| 国产一区成人| 亚洲国产一区二区a毛片| 99国产精品国产精品毛片| 亚洲视频在线视频| 久久天堂成人| 亚洲精品一区二区三区婷婷月 | 亚洲国产成人精品女人久久久| 亚洲国产欧美一区| 欧美小视频在线观看| 欧美专区在线观看一区| 理论片一区二区在线| 亚洲国产va精品久久久不卡综合| 一区二区三区欧美激情| 久久精品免费电影| 欧美午夜剧场| 亚洲人成网站777色婷婷| 亚洲在线观看免费| 欧美激情一区二区三区不卡| 亚洲一区免费视频| 欧美va天堂| 国产综合自拍| 午夜精品影院| 99亚洲一区二区| 美女日韩欧美| 激情成人中文字幕| 欧美一区二区视频97| 亚洲美女在线视频| 久热精品视频在线| 国内精品久久久| 欧美一区免费| 亚洲视频在线观看一区| 欧美日韩a区| 亚洲精品视频中文字幕| 麻豆精品一区二区av白丝在线| 一本色道综合亚洲| 欧美女主播在线| 亚洲每日更新| 亚洲福利av| 久久男人资源视频| 国产一区二区三区四区五区美女| 亚洲图片激情小说| 日韩视频一区二区三区在线播放免费观看| 久久蜜桃精品| 亚洲第一精品福利| 欧美激情按摩在线| 欧美成人免费在线观看| 最新中文字幕亚洲| 亚洲东热激情| 欧美激情一区二区三区不卡| 亚洲激情不卡| 欧美二区视频| 欧美高清视频在线| 日韩视频永久免费| 亚洲激情成人在线| 欧美日韩亚洲高清一区二区| 中国av一区| 亚洲欧美怡红院| 黄色影院成人| 亚洲高清自拍| 欧美日韩一区二区三区视频| 亚洲天堂网在线观看| 亚洲一区二区三区激情| 国产精品色婷婷久久58| 欧美中文字幕在线播放| 欧美在线关看| 91久久精品网| 中国女人久久久| 国产女人精品视频| 久久久久久久网站| 国产精品揄拍一区二区| 性感少妇一区| 久久久综合网站| 日韩视频在线永久播放| 国产精品99久久久久久有的能看 | 国产精品电影网站| 欧美一区日韩一区| 久久免费视频一区| 亚洲午夜激情网页| 久久精品人人做人人爽电影蜜月| 亚洲国产一区在线观看| 亚洲一区二区网站| 亚洲国产综合在线看不卡| 亚洲视频axxx| 91久久精品国产91久久| 午夜精品理论片| 亚洲日韩第九十九页| 亚洲午夜性刺激影院| 亚洲二区三区四区| 亚洲人成精品久久久久| 国产精品美女xx| 女同性一区二区三区人了人一 | 亚洲精品日韩在线| 亚洲综合激情| 亚洲韩国日本中文字幕| 一本色道久久综合亚洲二区三区| 尤妮丝一区二区裸体视频| 亚洲国产三级网| 国产综合色一区二区三区| 日韩一级裸体免费视频| 国产偷国产偷亚洲高清97cao| 久久亚洲精品一区二区| 国产精品美女久久久久久久 | 亚洲欧美日韩精品久久亚洲区| 亚洲成人资源网| 亚洲视频999| 一区二区三区欧美| 久久久久久高潮国产精品视| 亚洲主播在线播放| 欧美伦理视频网站| 亚洲国产精品福利| 尤物yw午夜国产精品视频| 亚洲欧美资源在线| 午夜一区二区三视频在线观看| 欧美精品一区在线| 亚洲第一精品在线| 亚洲国产美女| 久久综合久久综合九色| 久久久最新网址| 国内精品嫩模av私拍在线观看| 一本色道久久综合一区| 中文国产一区| 欧美日本一区二区高清播放视频| 欧美国产日本在线| 亚洲第一天堂av| 久久久福利视频| 久久久久国产精品一区三寸| 国产精品亚洲不卡a| 亚洲丝袜av一区| 午夜精品视频在线观看一区二区 | 99精品国产99久久久久久福利| 国产丝袜一区二区| 亚洲欧美日韩成人| 欧美一区二区三区啪啪| 国产乱码精品| 欧美一区二区三区在线免费观看| 午夜精品视频在线| 国产一区二区中文字幕免费看| 中文网丁香综合网| 性色av一区二区三区| 国产日韩欧美一二三区| 午夜精品在线看| 免费视频一区二区三区在线观看| 国产一区二区三区自拍| 久久视频精品在线| 亚洲欧洲精品一区二区三区不卡 | 午夜精品亚洲| 国产一区二区三区在线观看视频 | 久久激情综合网| 欧美激情亚洲国产| 亚洲精品欧美一区二区三区| 亚洲欧美视频一区二区三区| 国产精品视频久久久| 久久精品免费看| 亚洲国产成人精品久久| 午夜精品福利一区二区三区av | aa国产精品| 久久香蕉国产线看观看网| 亚洲卡通欧美制服中文| 欧美视频在线免费| 午夜精品理论片| 亚洲精品久久久久久一区二区 | 欧美专区在线观看一区| 亚洲黄一区二区| 国产欧美日韩高清| 欧美激情按摩在线| 久久高清福利视频| 亚洲精选一区二区| 美乳少妇欧美精品| 亚洲免费婷婷| 亚洲国产高清视频| 国产日韩在线不卡| 欧美日韩视频不卡| 久久综合免费视频影院| 亚洲欧美精品伊人久久| 亚洲精品免费在线观看| 美腿丝袜亚洲色图| 久久超碰97中文字幕| 一区二区三区黄色| 91久久国产综合久久| 国产一区二区三区的电影 | 国产精品日韩一区二区| 欧美精品一区二区三区蜜臀| 欧美综合国产精品久久丁香| 亚洲伦伦在线| 91久久久久久国产精品| 久久在线免费观看| 久久九九精品|