Sign in to follow this  

Moving a character around in a console?

This topic is 4527 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
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

This topic is 4527 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this