README.md
December 4, 2022 ยท View on GitHub
Description
keyboard controlled text animation
More Info
| Submitted On | |
| By | T J Betsworth |
| Level | Intermediate |
| User Rating | 5.0 (10 globes from 2 users) |
| Compatibility | C++ (general) |
| Category | Miscellaneous |
| World | C / C++ |
| Archive File |
Source Code
#include <windows.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
HANDLE hout= GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD InputRecord;
DWORD Events;
COORD coord;
int x = 30;
int y = 12;
void erase(){
SetConsoleTextAttribute(hout,0);
cout<<"XXXXXXXXXXXXXX";
}
void text(){
COORD coord = {x, y};
SetConsoleCursorPosition(hout, coord);
SetConsoleTextAttribute(hout,rand()%7+9);
cout<<"Planet Source!";
}
void movetext(){
SetConsoleMode(hin, ENABLE_PROCESSED_INPUT);
ReadConsoleInput(hin, &InputRecord, 1, &Events);
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
{
erase();
x++;
text();
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
{
erase();
x--;
text();
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP)
{
erase();
y--;
text();
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
{
erase();
y++;
text();
}
FlushConsoleInputBuffer(hin);
}
int main()
{
cout<<"press any arrow key to start use arrow keys to move text\n"
"keep text inside window Press Ctrl+C to Exit";
while(1)
{
CONSOLE_CURSOR_INFO cci;
cci.dwSize = 25;
cci.bVisible = FALSE;
SetConsoleCursorInfo(hout, &cci);
COORD coord = {x, y};
SetConsoleCursorPosition(hout, coord);
movetext();
}
}