Oct 22, 2010 at 9:25pm UTC
Hi guys!!
I'm working on a simple Text-Based RPG in C + +
I just finished with the movement of characters on the map, but I do not know how to put NPCs on some coordinates so that players can interact with them.
Is there a possibility to draw a map which will mark a player and the NPC.
Something like this:
OOOOOOOO
OXXXXXXXXO P=Player
OXXXXXXXXO O=Wall
OXXXXXXPXO X=ground
OXXNXXXXXO N=opponent
OOOOOOOO
Here is the code for movement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#include <cstdlib>
#include <cctype>
#include <conio.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//STRUCT++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
struct room
{
char description[500];
char name[32];
int sizex;
int sizey;
};
void initializeRoom();
room roomArray[1];
//MAIN PROGRAM+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()
{
initializeRoom();
char move;
int currentposition = 0;
int npc=0;
int positionx = 5;
int positiony = 5;
// moving-----------------------------------
moving:system("CLS" );
cout << "\n You are in " << roomArray[currentposition].name;
cout << "\n " << roomArray[currentposition].description;
cout << "\n\n Surface size = " << roomArray[currentposition].sizex << "," << roomArray[currentposition].sizey;
cout << "\n Your position = " << positionx << "," << positiony;
cout << "\n\n\n ---------------MOVE---------------" ;
cout << "\n (N)orth (S)outh (E)ast (W)est " ;
cout << "\n\n\n INPUT---> " ;
cin >> move;
move = toupper(move);
switch (move)
{
case 'N' :
positionx = positionx +1;
break ;
case 'E' :
positiony = positiony +1;
break ;
case 'S' :
positionx = positionx -1;
break ;
case 'W' :
positiony = positiony -1;
break ;
}
if ( positionx < 0 )
{
positionx = positionx+1;
goto moving;
}
else if ( positiony < 0 )
{
positiony=positiony+1;
goto moving;
}
else if (positionx > roomArray[0].sizex)
{
positionx = positionx -1;
goto moving;
}
else if (positiony > roomArray[0].sizey)
{
positiony = positiony -1;
goto moving;
}
else
{
goto moving;
}
getch();
}
void initializeRoom()
{
strcpy(roomArray[0].description, "You are standing on grass surface.\n It is used to test programs and adding new components." );
strcpy(roomArray[0].name, "TEST FIELD" );
roomArray[0].sizex = 10;
roomArray[0].sizey = 10;
}
Last edited on Oct 22, 2010 at 9:33pm UTC
Oct 23, 2010 at 12:05am UTC
Hello all.
I am sorry to intrude, but I'm trying to figure out how to post something new in this forum.
I've been doing searches but don't see how to start a new thread.
Can someone direct me, please?
I apologize in advance for butting in here.
Oct 23, 2010 at 12:13am UTC
Click the "New Topic" button at the bottom of the forum page.
Oct 23, 2010 at 12:14am UTC
I found the new topic button ... again my apologizes
Oct 23, 2010 at 7:30am UTC
I am enlightened! Thanks Disch!