1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| void HandleKeys()
{
HWND hWindow = _pGame->GetWindow();
HDC hDC = GetDC(hWindow);
RECT rcPos;
if (!_bGameOver && !_bDemo)
{
if (GetAsyncKeyState(VK_LEFT) < 0)
{
_bDirection = FALSE;
_pHerosSprite->SetVelocity(-10,0);
_pHerosBitmap->Create(hDC, IDB_HEROSGAUCHE, _hInstance);
_pHerosSprite->SetNumFrames(6);
_pGame->UpdateSprites();
// Move left
}
else if (GetAsyncKeyState(VK_RIGHT) < 0)
{
_bDirection = TRUE;
_pHerosSprite->SetVelocity(10,0);
_pHerosBitmap->Create(hDC, IDB_HEROSDROITE, _hInstance);
_pHerosSprite->SetNumFrames(6);
_pGame->UpdateSprites();
// Move right
}
else if ((GetAsyncKeyState(VK_UP) < 0) && _bDirection == FALSE)
{
_pHerosSprite->SetVelocity(-10,3);
_pHerosBitmap->Create(hDC, IDB_HEROSSAUTGAUCHE, _hInstance);
_pHerosSprite->SetNumFrames(6);
rcPos = _pHerosSprite->GetPosition();
while(!rcPos.top*2)
{
_pHerosSprite->SetPosition(rcPos.left+2, rcPos.top + 2);
//entre chaque affichage monte de 7 px
_pHerosSprite->SetVelocity(0, -7);
_pGame->AddSprite(_pHerosSprite);
}
while(!rcPos.top/2)
{
_pHerosSprite->SetPosition(rcPos.left-2, rcPos.top - 2);
//entre chaque affichage le laser 7 px
_pHerosSprite->SetVelocity(0, -7);
_pGame->AddSprite(_pHerosSprite);
}
_pGame->UpdateSprites();
// Move up
}
else if (GetAsyncKeyState(VK_UP) < 0 && _bDirection == TRUE)
{
_pHerosSprite->SetVelocity(10,3);
_pHerosBitmap->Create(hDC, IDB_HEROSSAUTDROITE, _hInstance);
_pHerosSprite->SetNumFrames(6);
rcPos = _pHerosSprite->GetPosition();
while(!rcPos.top*2)
{
_pHerosSprite->SetPosition(rcPos.left+2, rcPos.top + 2);
//entre chaque affichage le laser monte de 7 px
_pHerosSprite->SetVelocity(0, -7);
_pGame->AddSprite(_pHerosSprite);
}
while(!rcPos.top/2)
{
_pHerosSprite->SetPosition(rcPos.left-2, rcPos.top - 2);
//entre chaque affichage le laser monte de 7 px
_pHerosSprite->SetVelocity(0, -7);
_pGame->AddSprite(_pHerosSprite);
}
_pGame->UpdateSprites();
// Move down
}
else if(_bDirection == FALSE)
{
_pHerosSprite->SetVelocity(0,0);
_pHerosBitmap->Create(hDC,IDB_HEROSSTOPGAUCHE, _hInstance);
_pHerosSprite->SetNumFrames(1);
_pGame->UpdateSprites();
}
else if(_bDirection == TRUE)
{
_pHerosSprite->SetVelocity(0,0);
_pHerosBitmap->Create(hDC,IDB_HEROSSTOPDROITE, _hInstance);
_pHerosSprite->SetNumFrames(1);
_pGame->UpdateSprites();
}
}
// Start a new game based upon an Enter (Return) key press
if (GetAsyncKeyState(VK_RETURN) < 0)
if (_bDemo)
{
// Switch out of demo mode to start a new game
_bDemo = FALSE;
NewGame();
}
else if (_bGameOver)
{
// Start a new game
NewGame();
}
} |
Partager