TA的每日心情 | 郁闷 2024-11-22 16:10 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
Judgement
世界第一公主殿下
- 积分
- 2168

|
- 1 #include <windows.h>
- 2 #include <mmsystem.h>
- 3 #include <stdio.h>
- 4
- 5 #pragma comment(lib, "winmm.lib")
- 6
- 7
- 8 #define DATAFILE "BADAPPLE.txt"
- 9
- 10 #define FRAME_WIDTH 80
- 11 #define FRAME_HEIGHT 32
- 12
- 13 #define DATA_TOKEN_SIZE ( 5 + 1 ) // $0000\n
- 14 #define DATA_PITCH_SIZE ( FRAME_WIDTH + 1 ) // ###...\n
- 15 #define DATA_FRAME_SIZE ( DATA_TOKEN_SIZE + ( DATA_PITCH_SIZE * FRAME_HEIGHT ) )
- 16
- 17 #define FRAME_COUNT 3271
- 18
- 19 #define VIDEO_TIME 218000.0f // 3:38 (218000ms)
- 20
- 21
- 22 void main(void)
- 23 {
- 24 HANDLE hOutput;
- 25
- 26 hOutput = GetStdHandle( STD_OUTPUT_HANDLE );
- 27
- 28 CONSOLE_CURSOR_INFO coc = { 1, FALSE };
- 29 COORD co = { FRAME_WIDTH, FRAME_HEIGHT };
- 30 SMALL_RECT rc = { 0, 0, FRAME_WIDTH - 1, FRAME_HEIGHT - 1 };
- 31
- 32 SetConsoleCursorInfo( hOutput, &coc );
- 33 SetConsoleScreenBufferSize( hOutput, co );
- 34 SetConsoleWindowInfo( hOutput, TRUE, &rc );
- 35
- 36 SetConsoleTitle( "Bad Apple By Crsky @2016" );
- 37
- 38 FILE *fp;
- 39 int size;
- 40 char *buf;
- 41 char *cur;
- 42 int start;
- 43
- 44 buf = NULL;
- 45
- 46 fp = fopen( DATAFILE, "rb" );
- 47
- 48 if ( !fp )
- 49 {
- 50 printf( "%s not found.\n", DATAFILE );
- 51 goto err;
- 52 }
- 53
- 54 size = DATA_FRAME_SIZE * FRAME_COUNT;
- 55
- 56 buf = new char[ size ];
- 57
- 58 if ( fread( buf, size - 1, 1, fp ) != 1 )
- 59 {
- 60 printf( "Failed to read in data file.\n" );
- 61 goto err;
- 62 }
- 63
- 64 buf[ size - 1 ] = '\0';
- 65
- 66 fclose( fp );
- 67
- 68 mciSendString( "open BADAPPLE.wma alias BGM", NULL, 0, NULL );
- 69 mciSendString( "play BGM", NULL, 0, NULL );
- 70
- 71 start = GetTickCount();
- 72
- 73 while ( 1 )
- 74 {
- 75 int time;
- 76 float percen;
- 77 int frame;
- 78 COORD xy = { 0, 0 };
- 79 DWORD written;
- 80
- 81 if ( GetKeyState( VK_SPACE ) )
- 82 {
- 83 printf( "Stop play.\n" );
- 84 break;
- 85 }
- 86
- 87 time = GetTickCount();
- 88 percen = ( time - start ) / VIDEO_TIME;
- 89
- 90 if ( percen > 1 )
- 91 {
- 92 printf( "End of play.\n" );
- 93 break;
- 94 }
- 95
- 96 frame = percen * FRAME_COUNT;
- 97 cur = &buf[ ( DATA_FRAME_SIZE * frame ) + DATA_TOKEN_SIZE ];
- 98
- 99 for ( ; xy.Y < FRAME_HEIGHT; xy.Y++, cur += DATA_PITCH_SIZE )
- 100 WriteConsoleOutputCharacter( hOutput, cur, DATA_PITCH_SIZE - 1, xy, &written );
- 101
- 102 Sleep( 60 );
- 103 }
- 104
- 105 mciSendString( "stop", NULL, 0, NULL );
- 106 mciSendString( "close", NULL, 0, NULL );
- 107
- 108 err:
- 109 if ( buf )
- 110 delete[] buf;
- 111
- 112 Sleep( 500 );
- 113 }
复制代码
|
|