Public Group

Moving a character around in a console?

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am wanting to try and make a text based RPG game but am stuck on how i could move a character around the screen in a console. Is this possible to do? if it is can someone pleas explain how i could achive this, i have made text move before and made a number counter were it kept on re-writing text but i am finding text based games tricky to make moving characters.

Share on other sites
Dam can't get it to work, i compile it using the -tW command in borland but it isn't creating the win32 executible.

Share on other sites
If you are going to do so in a Console, then you will first need to specify the object to be drawn beforehand.

typedef char OBJECT[3][3];OBJECT square = {    {'|', '-', '|'},    {'|', ' ', '|'},    {'|', '-', '|'}};

A 3x3 array is used in this case. Now, you want to draw that object.
#define DISPLAY(t) std::cout << tVOID DrawObject(OBJECT obj){    HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);    COORD crd = {0, 0};    SetConsoleCursorPosition(out, crd);    DISPLAY(obj[0][0]); DISPLAY(obj[0][1]); DISPLAY(obj[0][2]); DISPLAY("\n");    DISPLAY(obj[1][0]); DISPLAY(obj[1][1]); DISPLAY(obj[1][2]); DISPLAY("\n");    DISPLAY(obj[2][0]); DISPLAY(obj[2][1]); DISPLAY(obj[2][2]); DISPLAY("\n");    }

that should draw an object at 0x, 0y. Now, lets say we need to specify the location.

#include <iostream>#include <conio.h>#include <windows.h>#define DISPLAY(t) std::cout << tVOID DrawObject(OBJECT obj, short x, short y){    HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);    COORD crd = {x, y};    SetConsoleCursorPosition(out, crd);    DISPLAY(obj[0][0]); DISPLAY(obj[0][1]); DISPLAY(obj[0][2]); DISPLAY("\n");    COORD crd = {x, y+1};    SetConsoleCursorPosition(out, crd);    DISPLAY(obj[1][0]); DISPLAY(obj[1][1]); DISPLAY(obj[1][2]); DISPLAY("\n");    COORD crd = {x, y+2};    SetConsoleCursorPosition(out, crd);    DISPLAY(obj[2][0]); DISPLAY(obj[2][1]); DISPLAY(obj[2][2]); DISPLAY("\n");    }

NOTE: I didnt test this code out yet, so you might have to make some changes.

Share on other sites
I am not well up on windows programming yet so don't know what some of them windows functions do but some look easy and some i can just get how they work. Thanks.

1. 1
Rutin
73
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633426
• Total Posts
3011816
• Who's Online (See full list)

There are no registered users currently online

×