Ideally, I'd like the reticle to move when just the arrow keys are pressed.
When the alt-key is held and then an arrow key is pressed in combination, I'd like a separate group of pixels to move with velocity.
How to achieve this?
I've coded separate int's for each grouping of pixels. Basically, I set up the second grouping of pixels the way I did the first, but with Chili's explanation of how to achieve velocity. But the code is interfering with each other. I tried to achieve the combination key movements by creating a bool, initializing that bool if alt is pressed and then including code for each pixel to move under "if (name of bool).
Maybe I'm just going about it the wrong way. I'm very new to this.
At the moment, my code for the second grouping of pixels is interfering with the moving of the first image. And also, the way I've tried to code to get the second object to move only when the alt-key is pressed in combination with an arrow key is not working.
Also, if someone could tell me how to use a letter-key when doing KeyIsPressed(VK_???) that would be helpful. MSDN just says 'W' and that doesn't work. I was planning on using the W, A, D and X keys to move the second grouping of pixels. Even though I decided to go with the latter (alt-key in combination with arrow key) I'd still like to know.
Help me make my game!!!
Here's what I've done (and I'm sure you'll probably laugh)
Code: Select all
void Game::UpdateModel()
{
//Move reticle up
if (wnd.kbd.KeyIsPressed(VK_UP))
{
chy = chy - 3;
}
//Move reticle down
if (wnd.kbd.KeyIsPressed(VK_DOWN))
{
chy = chy + 3;
}
//Move reticle left
if (wnd.kbd.KeyIsPressed(VK_LEFT))
{
chx = chx - 3;
}
//Move reticle right
if (wnd.kbd.KeyIsPressed(VK_RIGHT))
{
chx = chx + 3;
}
//Color change for reticle
if (wnd.kbd.KeyIsPressed(VK_CONTROL))
{
gb = 0;
}
ShapeIsChanged = wnd.kbd.KeyIsPressed(VK_SHIFT);
BoatIsInitiated = wnd.kbd.KeyIsPressed(VK_MENU);
if (BoatIsInitiated)
{
//Move boat up
if (wnd.kbd.KeyIsPressed(VK_UP))
{
bvy = bvy - 1;
}
//Move boat down
if (wnd.kbd.KeyIsPressed(VK_DOWN))
{
bvy = bvy + 1;
}
//Move boat left
if (wnd.kbd.KeyIsPressed(VK_LEFT))
{
bvx = bvx - 1;
}
//Move boat right
if (wnd.kbd.KeyIsPressed(VK_RIGHT))
{
bvx = bvx + 1;
}
}
bx = bx + bvx;
by = by + bvy;
}
void Game::ComposeFrame()
{
if (ShapeIsChanged)
{
gfx.PutPixel(3 + chx, 8 + chy, 255, gb, gb);
gfx.PutPixel(4 + chx, 9 + chy, 255, gb, gb);
gfx.PutPixel(5 + chx, 10 + chy, 255, gb, gb);
gfx.PutPixel(-3 + chx, -1 + chy, 255, gb, gb);
gfx.PutPixel(-4 + chx, -2 + chy, 255, gb, gb);
gfx.PutPixel(-5 + chx, -3 + chy, 255, gb, gb);
gfx.PutPixel(3 + chx, -1 + chy, 255, gb, gb);
gfx.PutPixel(4 + chx, -2 + chy, 255, gb, gb);
gfx.PutPixel(5 + chx, -3 + chy, 255, gb, gb);
gfx.PutPixel(-3 + chx, 8 + chy, 255, gb, gb);
gfx.PutPixel(-4 + chx, 9 + chy, 255, gb, gb);
gfx.PutPixel(-5 + chx, 10 + chy, 255, gb, gb);
}
else
{
//Crosshair gfx (first image/grouping of pixels)
gfx.PutPixel(-3 + bx, by, 255, gb, gb);
gfx.PutPixel(-4 + bx, by, 255, gb, gb);
gfx.PutPixel(-5 + bx, by, 255, gb, gb);
gfx.PutPixel(2 + bx, by, 255, gb, gb);
gfx.PutPixel(3 + bx, by, 255, gb, gb);
gfx.PutPixel(4 + bx, by, 255, gb, gb);
gfx.PutPixel(bx, -3 + by, 255, gb, gb);
gfx.PutPixel(bx, -4 + by, 255, gb, gb);
gfx.PutPixel(bx, -5 + by, 255, gb, gb);
gfx.PutPixel(bx, 2 + by, 255, gb, gb);
gfx.PutPixel(bx, 3 + by, 255, gb, gb);
gfx.PutPixel(bx, 4 + by, 255, gb, gb);
}
//Boat gfx (second image/grouping of pixels)
gfx.PutPixel(30 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(31 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(32 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(33 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(34 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(35 + bx, 20 + by, 0, 255, 0);
gfx.PutPixel(31 + bx, 21 + by, 0, 255, 0);
gfx.PutPixel(32 + bx, 21 + by, 0, 255, 0);
gfx.PutPixel(33 + bx, 21 + by, 0, 255, 0);
gfx.PutPixel(34 + bx, 21 + by, 0, 255, 0);
}