This is a bit complicated to explain, you need to see the program first to see the problem, so here it is:
Now, if you run the program, you will see the 'STAR' kinda jumps up and goes down every time it moves, if you get out of full screen you will see that effect gets much bigger, I think the problem is that when the 'STAR' moves, the vertical scrolling bar moves, and goes back to its original position very fast, thus it seems the 'STAR' moves.Code:#include <iostream> #include <windows.h> using namespace std; #define STAR '%' #define S_HEIGHT 25 #define S_WIDTH 80 // Global Vars char Screen[S_WIDTH][S_HEIGHT]; int X, Y; // Global specific Vars: FPS int StartingTime; int Time; int Fps; // Global Functions void EreaseScreen(); bool FPS(int fps); bool InitVariables(); void PrintScreen(); bool PutCharInScreen(); int FullScreen(); void MoveStar(); int RealX() { return (X + (S_WIDTH / 2)); } int RealY() { return (Y + (S_HEIGHT / 2)); } // Cursor BOOL ShowScreenCursor (BOOL Show) { CONSOLE_CURSOR_INFO cci = {0}; BOOL StatusCCI = FALSE; if (Show) // show screen cursor { cci.dwSize = 30; cci.bVisible = TRUE; StatusCCI = SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci); } else // hide screen cursor { cci.dwSize = 100; cci.bVisible = FALSE; StatusCCI = SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cci); } return StatusCCI; } // Main int main() { ShowScreenCursor(false); // Going fullscreen... FullScreen(); InitVariables(); while (1) { if (FPS(Fps)) // Time to move star... { StartingTime = GetTickCount(); system("cls"); EreaseScreen(); MoveStar(); if (PutCharInScreen()) PrintScreen(); } } return 0; } // Global functions definitions void EreaseScreen() { for (int i = 0; i < S_HEIGHT; i++) for (int j = 0; j < S_WIDTH; j++) Screen[j][i] = '\0'; } bool FPS(int fps) { Time = GetTickCount() - StartingTime; if (Time > fps) return true; else return false; } bool InitVariables() { // Global Vars X = 0; Y = -10; EreaseScreen(); Screen[RealX()][RealY()] = STAR; // Global specific Vars: FPS Fps = 500; StartingTime = GetTickCount(); Time = 0; return true; } void PrintScreen() { for (int i = 0; i < S_HEIGHT; i++) { for (int j = 0; j < S_WIDTH; j++) cout << Screen[j][i]; cout << endl; } } bool PutCharInScreen() { if (RealX() > S_WIDTH || RealX() < 0) { cout << "ERROR" << endl; return false; } if (RealY() > S_HEIGHT || RealY() < 0) { cout << "ERROR" << endl; return false; } Screen[RealX()][RealY()] = STAR; return true; } int FullScreen() { keybd_event(VK_MENU,0x38,0,0); keybd_event(VK_RETURN,0x1c,0,0); keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0); keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0); return 0; } void MoveStar() { if (Y <= 0 && X >= 0) { X++; Y++; } if (Y >= 0 && X >= 0) { X--; Y++; } if (Y >= 0 && X <= 0) { X--; Y--; } if (Y <= 0 && X <= 0) { X++; Y--; } }
Can anyone tell me how to stop the vertical scrolling bar from moving? Thanks in advance and sorry for the long post.



LinkBack URL
About LinkBacks



