Animasi console pada C++


Animasi ini saya dapatkan dari mbah google yang kemudian saya modifikasi sesuai dengan selera saya. Program ini dibuat oleh T J Betsworth.

// animasi text yg bisa berubah

 

#include <windows.h>
#include <iostream>
#include <stdlib.h>

#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<<"YODI KEREN :D";
}
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<<"Gunakan panah pada keyboard untuk memindahkan text\n"
"tekan Ctrl+C untuk Exit";
while(1)
{
CONSOLE_CURSOR_INFO cci;
cci.dwSize = 25;
cci.bVisible = FALSE;
SetConsoleCursorInfo(hout, &cci);
COORD coord = {x, y};
SetConsoleCursorPosition(hout, coord);
movetext();
}
}

5 responses to “Animasi console pada C++

  1. karena sesuatu dan lain hal…
    kemaren kami balik ke console lagi pak…

    padahal dah enak main ke visual c++

    btw trims sharenya pak!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s