?? runner.cpp
字號(hào):
#include "Runner.h"
void CRunner::UpdateRunner()
{
SDL_PumpEvents();
Uint8 * key = SDL_GetKeyState(NULL);
int stepx = RUNNERSPEED;
int stepy = RUNNERSPEED;
if (key[SDLK_LEFT])
{
stepy = 0;
stepx = -stepx;
}
else if (key[SDLK_RIGHT])
{
stepy = 0;
}
else if (key[SDLK_UP])
{
stepx = 0;
stepy = -stepy;
}
else if (key[SDLK_DOWN])
{
stepx = 0;
}
else
{
stepy = stepx = 0;
}
m_RunnerPos.x +=stepx;
m_RunnerPos.y +=stepy;
if(m_RunnerPos.x <= 0)
m_RunnerPos.x = RUNNERWIDTH;
if(m_RunnerPos.y <= 0)
m_RunnerPos.y = RUNNERWIDTH;
if(m_RunnerPos.x >= SCREEN_WIDTH)
m_RunnerPos.x = SCREEN_WIDTH - RUNNERWIDTH;
if(m_RunnerPos.y >=SCREEN_HEIGHT)
m_RunnerPos.y = SCREEN_HEIGHT - RUNNERWIDTH;
}
void CRunner::DrawRunner(SDL_Surface* g_pDisplay)
{
SDL_Rect Rect;
Rect.h = RUNNERWIDTH;
Rect.w = RUNNERWIDTH;
Rect.x = m_RunnerPos.x;
Rect.y = m_RunnerPos.y;
SDL_FillRect(g_pDisplay,&Rect,m_RunnerColor);
}
void CRunner::CleanRunner(SDL_Surface * g_pDisplay)
{
SDL_Rect Rect;
Rect.h = RUNNERWIDTH;
Rect.w = RUNNERWIDTH;
Rect.x = m_RunnerPos.x;
Rect.y = m_RunnerPos.y;
SDL_FillRect(g_pDisplay,&Rect,0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -