• Advertisement
Sign in to follow this  

Moving a character around in a console?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 << t
VOID 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 << t


VOID 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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement