Moving a character around in a console?

Started by
4 comments, last by paulecoyote 18 years, 9 months ago
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.
Advertisement
Hi,

MSDN has an article Reading and Writing Blocks of Characters and Attributes that might be of help.
Dam can't get it to work, i compile it using the -tW command in borland but it isn't creating the win32 executible.
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.
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.
benryves knows tons about console stuff. See his website.
http://www.benryves.com/?page=anim
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.

This topic is closed to new replies.

Advertisement