Re: How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the ot
Posted: August 2nd, 2019, 6:53 pm
Figured it out using step-over in the debugger.
Learn to program or die trying
https://forum.planetchili.net:443/
Code: Select all
void Game::UpdateModel()
{
// Keep all state changes in close vicinity to each other to make it
// easier to find
if( wnd.kbd.KeyIsPressed( VK_RETURN ) )
{
BoatIsInitiated = true;
CrossHairIsInitiated = false;
}
else if( wnd.kbd.KeyIsPressed( VK_SHIFT ) )
{
BoatIsInitiated = false;
CrossHairIsInitiated = true;
// While cross hair is active, don't need to inhibit movement
InhibitUp = false;
InhibitDown = false;
InhibitLeft = false;
InhibitRight = false;
}
if( BoatIsInitiated )
{
// What this pattern does is if UP or DOWN is pressed and
// not inhibited then update boat velocity and if they are
// but the keys is not pressed then set the inhibit flags to false.
// It also allows the cpu to skip the other cases once it finds a
// true case, so no need to check the rest.
if( wnd.kbd.KeyIsPressed( VK_UP ) == true && InhibitUp == false )
{
bvy = bvy - 1;
InhibitUp = true;
}
else if( wnd.kbd.KeyIsPressed( VK_DOWN ) == true && InhibitDown == false )
{
bvy = bvy + 1;
InhibitDown = true;
}
else if( wnd.kbd.KeyIsPressed( VK_UP ) == false && InhibitUp == true )
{
InhibitUp = false;
}
else if( wnd.kbd.KeyIsPressed( VK_DOWN ) == false && InhibitDown == true )
{
InhibitDown = false;
}
// Since you can move in diagonal directions, this is a separate block
// than the UP and DOWN, but still employs the same idea.
if( wnd.kbd.KeyIsPressed( VK_LEFT ) == true && InhibitLeft == false )
{
bvx = bvx - 1;
InhibitLeft = true;
}
else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) == true && InhibitRight == false )
{
bvx = bvx + 1;
InhibitRight = true;
}
else if( wnd.kbd.KeyIsPressed( VK_LEFT ) == false && InhibitLeft == true )
{
InhibitLeft = false;
}
else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) == false && InhibitRight == true )
{
InhibitRight = false;
}
}
else if( CrossHairIsInitiated )
{
//Color change for reticle
if( wnd.kbd.KeyIsPressed( VK_CONTROL ) )
{
chgb = 0;
}
if(wnd.kbd.KeyIsPressed(VK_UP))
{
//Move reticle up
chy = chy - 3;
}
else if( wnd.kbd.KeyIsPressed( VK_DOWN ) )
{
//Move reticle down
chy = chy + 3;
}
if( wnd.kbd.KeyIsPressed( VK_LEFT ) )
{
//Move reticle left
chx = chx - 3;
}
else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) )
{
//Move reticle right
chx = chx + 3;
}
}
bx = bx + bvx;
by = by + bvy;
}