moving cursor in consol applications

Started by
5 comments, last by XDaWNeDX 12 years, 10 months ago
I know it's possible.


How do I MOVE the cursor in a console application?



I am a sesquipidalian.

Go not where the path leads, but rather walk somewhere new and leave a trail.
Advertisement
Depends on the language. In C or C++ there is no standard way. The Win32 API exposes some methods to do this kind of thing or there is the highly regarded ncurses library that is platform independant.
In standard C++, you can't. This kind of functionality is dependent on the operating system. For instance, with Windows, you can use the Win32 Console Functions
Yes, it's c++.

How would I use those console functions? I've already seen them but I have no clue how to use them properly. I suppose I'll just make a test application and see if I can't make it work somehow.
I am a sesquipidalian.

Go not where the path leads, but rather walk somewhere new and leave a trail.
[source lang="c++"]
void f()
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);

COORD c;
c.X=19;
c.Y=8;

SetConsoleCursorPosition(out,c);
}
[/source]

Simples. :)

[source lang="c++"]
void f()
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);

COORD c;
c.X=19;
c.Y=8;

SetConsoleCursorPosition(out,c);
}
[/source]

Simples. :)



Mmk, thanks SOOO much.

I'm trying to make an RPG with moving characters and stuff in a console application. But whenever you push the up/left/down/right buttons the WHOLE screen re-writes itself which makes it kinda bleh...
I am a sesquipidalian.

Go not where the path leads, but rather walk somewhere new and leave a trail.
You can find some decent (but not excellent!) examples of using the Windows console API here. The code was written in 3 hours so be warned, it isn't hugely pretty or necessarily the best example of how to do certain things. But it should at least get you started and give you a rough idea of how things could be done.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


You can find some decent (but not excellent!) examples of using the Windows console API here. The code was written in 3 hours so be warned, it isn't hugely pretty or necessarily the best example of how to do certain things. But it should at least get you started and give you a rough idea of how things could be done.



Mm, yes, well what I currently have is as follows:
http://www.barnumize...lease0.01.5.rar
(up/down/right/left to move, space for pause menu/select)
Removed the AI because I'm doing other stuff right now, and when I'm testing it the monsters keep attacking me. D: Plus, all it really did was make them walk into walls.
That's basically MOST of my game. I HAVE made other updates since uploading it to my website though.

Although, what you've shown me has different colours, so I'll download it..
That's too in depth for me. Surely I could use it, and really make my game look good. But if I wanted to do that, I'd use allegro, or directx, or some form of graphics API.
The point of my game is to make it as simple as possible.
Using what Aardvajk told me. Thanks again Aardvajk!
I am a sesquipidalian.

Go not where the path leads, but rather walk somewhere new and leave a trail.

This topic is closed to new replies.

Advertisement