Redrawing the screen and wiping what was already there - c++

I need some help - I'm trying to create a roguelike using C++, and at the moment, I have a very simple little screen going, with a void() that generates a map, using "#" for walls and "." for floors. It can draw the player by comparing some integers which map the X and Y values of the player.
I even have a little HUD which will display the player's stats.
But, the issue is, this is all being designed using a typical command-console window, and I'm starting to think I'm doing this wrong.
I want the player to move around this big empty room I have, by using the numpad -- this works. By using a Switch, I adjust the X and Y player value and then redraw the screen again.
Here's the issue. This actually redraws the screen all over again: it adds the 20-odd lines all over again, every single time I move. After a few moves, I have a command console window with text going for hundreds of lines.
So what am I doing wrong? Is there a command I don't know about to clear the screen?
Or am I doing this wrong from the start -- for instance, you have to press 'enter' to input your command, something that's not in any other roguelike. I'm a novice programmer, so any and all help is appreciated!
Thankyou!
Edit: Okay, thanks guys, I am now using PDCurses and trawling the docs to work out how to use the thing! Thanks again so much! Somebody please give the guy who suggested this a big tick! :D

What method are you using to draw the screen, just normal iostream? For this kind of work a library called curses is normally recommended. It would let you draw text anywhere on the screen without scrolling or redrawing the entire screen.

I don't know of any reliable way to do it with portability, maybe try looking for some console oriented lib... Anyway under Windows you can still use system("cls");

You can use the ansi escape sequence: printf ("\33[2]").

Related

Refresh image in command line (C++)

I want to make a game (something like theses) in C++ (Visual C++). Now a graphic game needs to refresh its picture quite often.
I can print around 20 blank lines. This method is unefficient and quite "laggy". What I need is something fast and efficient and that cause no memory problem because the game will process a lot of data (like mouvements, scores, coins...).
I've also tried to use system('cls'). This is quite bad because can "kinda" gives the player an epileptic attack!
Is there a better solution??
Thanks.
The command line has no image output. The only way you can fake it on the command line is the way you have described it.
The way to make a game efficient is to create a window yourself and then draw with DirectX or OpenGL something into that window. Then you can clear it and redraw it. This might not satisfy you at the moment, as it sounds more like a quick project. But in the long run, you will not be happy to "draw" on the command line if you search for efficiency.

Erase a couple lines on the screen, not clear the entire screen

I'm teaching myself C++ and I came to an interesting problem in my code. How would I erase only a couple lines previously printed on the screen instead of clearing the whole screen which system("CLS") does? This isn't homework, I'm trying to teach myself and haven't found anything on this subject. Thanks!
if you are programming in the DOS environment, you can use gotoxy() to position the cursor upon the text you want and print some space symbols

Weird graphical glitch in using winAPI to use color console

I'm programming a little game in C++ in the console for a school assignment. (Yes, being in console is required.)
I was using system("color 01") to pick an appropriate back and forecolor, but then I found a way to pick the color using the winAPI. Like so: http://www.cplusplus.com/articles/Eyhv0pDG/
This works great, however it produces an odd graphical glitch. It couts things one pixel to the left of where it should be. This gives me this unwanted behaviour when walking:
https://scontent-b-ams.xx.fbcdn.net/hphotos-prn1/v/1508323_1421353738101215_634234870_n.jpg?oh=b3bacc821cb924a6aa84025c9ead310d&oe=52AE68C5
EDIT: When I minimize the window and reactive it, the glitched areas are gone?
SOLUTION: I was able to fix it by redrawing the window with invalidateRect()

SDL drawing a sprite once a button is pressed

So, i'm a complete stranger to SDL and i found this nice code online:
http://gamedevgeek.com/tutorials/animating-sprites-with-sdl/
I was just wondering how to make it so that when i press space a shape gets placed infront of me? For instance, im just walking around and when i press space a rectangle or another bmp is places in front of me.
Sorry for not being explicit in what i want, i just dont know how to explain it.
You need:
Another Surface to draw (blit), made from the rectangle.bmp. This would use the same method as is used for the grass (or the player if you wanted animation).
Knowledge of where "in front" is: up, down, left or right. Look at the code and see what variables change when you press one of the arrow keys. (Hint: don't use rcSprite.) In a larger game, you would want to define a new variable for the direction that the player is facing, and then use that for both the sprite animation and for placing the rectangle, as it would make the code easier to understand.
Some new code in HandleEvent, which does something if the key is SDLK_SPACE.
Then calculate a position to place the rectangle (say, the player's position with 50 added to "x" if they were facing right), and draw the rectangle in the same way as the grass.
In general, look at what code has already been written, and Google for stuff you don't know (e.g. the name of SDLK_SPACE).
Good luck

gui for mpi program

I have a problem about a simple mpi program.This program have some 3D points and these points are moving during the program. I created an simple code by implemented c++ and then I tried to add an simple gui. I used gnuplot library and I have a problem. When I call the gui function the gui is created and it is disappeared at the same time. I mean, point object have x,y,z coordinate and I have an array that includes point objects. I want to create them as gui. Can you help me about this problem?
Thanks for any help..
what about Qt? You could use the Qt Graphics View Framework to simulate the 3D-environment - it even supports coordinate transformation (ok, it was originally designed for 2d scope). It supports OpenGL and maybe you are able to simulate the 3D points by drawing dots and setting their positions using simple cosinus and tangens mathematics.
Don't get afraid of the many functions and classes Qt offers - it's very easy and fast to learn - just check out the simple tutorials and after that you right can start your gui!
...and if you are used to Qt, you'll never want to miss it :)
Could it be that the plot is up correctly but that then your program ends? Ie everything's correct, the window goes up, but the next thing that happens is that the program is done, and the window gets destroyed? Try putting in a couple lines that wait for a keypress right after you throw up the window. Then, the window will stay until you press a key (and then the program will end).