Theres no way I'm reading all that but try this:
if (input == 77) ... //Right
if (input == 75) ... //Left
if (input == 80) ... //Down
if (input == 72) ... //Up
Theres no way I'm reading all that but try this:
if (input == 77) ... //Right
if (input == 75) ... //Left
if (input == 80) ... //Down
if (input == 72) ... //Up
"There's always another way"
-lightatdawn (lightatdawn.cprogramming.com)
Yes. I agree with sangdrax. you need to change the way you increment and decrement. i gor teally woird things coming out of my early progs when i would use x = x++. Use x++ by itself, or x += 1. (except with your variables in there.)
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
Change this!!Originally posted by BMJ
end_game = end_game--; //Game_Over is reduced by 1
end_game--;
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Hmm, why do you need to post all your code for something that small. It's just a matter of chnaging some evaluation values, as lightatdawn said.
ok, well he still doesn't need to post all his code. And why use the arrow keys? That feels to cramped and is too far away from the other keys.
How did you do that code formatting.. I mean that colours etc.. You didn't format them YOURSELF did you???
what does signature stand for?
By the way.. I have the same problem using the direction keys as well... I tried GetKeyState() but virtual keys don't work (excluding VK_RETURN) (Console) .. I also tried that getch() but when you press one of the arrows.. it just says p:
Code:int main() { char choice[1]; choice[0] = getch(); cout << choice[0]; return 0; }
what does signature stand for?
Testing PHP...
PHP Code:
int main()
{
cout << "Hello World!";
return 0;
}
what does signature stand for?
YEY!! PHP!!.. But the code colours are kinda anti-C++, maybe we should ask an admin to change them...
what does signature stand for?
You need to use Windows' virtual keys
*sigh*
Example of virtual key usage:Code:#include <windows.h> #include <iostream> bool Keypress(char &Key) { INPUT_RECORD Event; DWORD NumberOfEvents, EventsRead, EventCounter; GetNumberOfConsoleInputEvents(GetStdHandle(STD_INPUT_HANDLE), &NumberOfEvents); if (NumberOfEvents == 0) return false; for (EventCounter = 0; EventCounter < NumberOfEvents; EventCounter++) { PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &Event, 1, &EventsRead); if ((Event.EventType == KEY_EVENT) && ((Event.Event.KeyEvent.bKeyDown))) { ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &Event, 1, &EventsRead); Key = Event.Event.KeyEvent.wVirtualKeyCode; if (!(FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)))) exit(0); return true; } else ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &Event, 1, &EventsRead); } return false; } int main() { char key = 0; for (;;) { if (Keypress(key)) { if (key == VK_LEFT) std::cout << "Left\n"; if (key == VK_RIGHT) std::cout << "Right\n"; if (key == VK_DOWN) std::cout << "Down\n"; if (key == VK_UP) std::cout << "Up\n"; if (key == VK_ESCAPE) return 0; } } return 0; }
Last edited by BMJ; 10-04-2002 at 04:33 PM.
No, it's not; What I did was totally different - as his subject says 'using directional keys'
Last edited by BMJ; 10-04-2002 at 04:31 PM.
Well for a game, keypress catching is much nicer than standard inputting; who wants to type "left" and press enter when you can just press the left arrow and have the action take place.
You don't even have to know how the function KeyPress works, just how to use it, which is simple.
EDIT: Driveway - whatever.
Last edited by BMJ; 10-04-2002 at 04:36 PM.
LOL! Dude, you copied the code above which got cut off!
Copy it from this...
(btw: don't forget to add a way to get out of the infinite for loop, like with escape)
hmmm what?
You can do it!
There, does that help?