Interacting with signs. I need advice.

Started by
10 comments, last by Servant of the Lord 11 years, 4 months ago
Here is a screenshot of me interacting with a sign. Every time I hit the enter key it checks if the square you are facing is interactable and then if yes if cout<<"Welcome to Negfaron". The problem I want your help solving is how do I go about managing which sign says what. Obviously I do not want them all saying the same thing.

2h34vvd.png

Now this is how I create a map. Each char represents a tile.

They each use the tile class.

class tile {
public:
char cid, pass, interaction;
int sy,sx;
void set_values (char,char,char,int,int);
string dialogue;
};
void tile::set_values(char cid1,char interaction1,char pass1,int sy1,int sx1) {
interaction = interaction1;
cid = cid1;
pass = pass1;
sy = sy1;
sx = sx1;
}



void init_map(string &grid) {
grid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XOOOOOOOOOOOOOOOOOOOOSOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX" //5
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX" //10
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOXXXXXOOXXXXXOOOOOOOOOOOX"
"XOOOOOXBBBBBBBBBBXOOOOOOOOOOOX"
"XOOOOOXBBBBBBBBBBXOOOOOOOOOOOX"
"XOOOOOXBBBBBBBBBBXOOOOOOOOOOOX" //15
"XOOOOOXBBBBBBBBBBXOOOOOOOOOOOX"
"XOOOOOXXXXXXXXXXXXOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX" //20
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX"
"XOOOOOOOOOOOOOOOOOOOOOOOOOOOOX" //25
"XTTTTTTGGGGGGGGGGGGGGGGGGGGGGX"
"XTTTTTTGGGGGGGGGGGGGGGGGGGGGGX" //27
"XTTTTTTGGGGGGGGGGGGGGGGGGGGGGX" //28
"XTTTTTTTTTTTTTTTTTTTTTTTTTTTTX" //29
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //30
// 123456789X123456789X123456789X
}



Here are some of my ideas I have so far is make each sign a different char and that will be the sign id, and depending on which char is displaid on the map grid it will say something else.

A problem I have with this idea is that eventually I will run out of chars since I plan on having a large game with many signs.

How would you solve this problem?
Advertisement
Having a character for each sign is a really bad idea. You should implement some sort of entity system so that you can add signs and other objects in the world separate from your tilemap. You gotta do it some time, right? Unless you don't plan on expanding your game past "The Adventures of Tinyguy: Rogue Sign-Reader Extreme".

I recommend looking through some general tile engine tutorials as well. Good luck, mang.
Thanks for the advice I will look into entity systems.


Unless you don't plan on expanding your game past "The Adventures of Tinyguy: Rogue Sign-Reader Extreme".


ROFL~!

Having a character for each sign is a really bad idea. You should implement some sort of entity system so that you can add signs and other objects in the world separate from your tilemap. You gotta do it some time, right? Unless you don't plan on expanding your game past "The Adventures of Tinyguy: Rogue Sign-Reader Extreme".
I recommend looking through some general tile engine tutorials as well. Good luck, mang.


Defining your maps in a text file is IMO a good way to create simple maps, or for prototyping.
If you were doing something fit for a gameboy, you might never need anything more than that, and then an entity system for the static bits would be overkill. You don't necessarily have to do it some time, but even if you do, this step is great for learning as well as being easier to debug. It's pretty much WYSIWYG. -t gives you a good feeling of the map, and doesn't take a lot of space, is portable etc.
I suggest that you keep a sign file, or a sign list further down in the same file:

MAP SIZE H,V
TILECHARSTILECHARSTILECHARSTILECHARS
TILECHARSTILECHARSTILECHARSTILECHARS
TILECHARSTILECHARSTILECHARSTILECHARS
[6,11] "Welcome home!"
[6,12] "We hope you enjoyed your visit!"
[7,11] "Happy birthday!"
[10,16] "Register Cosmo Today!"

And this map coordinates to strings.
You could keep lists of NPCs and monsters too.

[quote name='Magdev' timestamp='1355982653' post='5012717']
Having a character for each sign is a really bad idea. You should implement some sort of entity system so that you can add signs and other objects in the world separate from your tilemap. You gotta do it some time, right? Unless you don't plan on expanding your game past "The Adventures of Tinyguy: Rogue Sign-Reader Extreme".
I recommend looking through some general tile engine tutorials as well. Good luck, mang.


Defining your maps in a text file is IMO a good way to create simple maps, or for prototyping.
If you were doing something fit for a gameboy, you might never need anything more than that, and then an entity system for the static bits would be overkill. You don't necessarily have to do it some time, but even if you do, this step is great for learning as well as being easier to debug. It's pretty much WYSIWYG. -t gives you a good feeling of the map, and doesn't take a lot of space, is portable etc.
I suggest that you keep a sign file, or a sign list further down in the same file:

MAP SIZE H,V
TILECHARSTILECHARSTILECHARSTILECHARS
TILECHARSTILECHARSTILECHARSTILECHARS
TILECHARSTILECHARSTILECHARSTILECHARS
[6,11] "Welcome home!"
[6,12] "We hope you enjoyed your visit!"
[7,11] "Happy birthday!"
[10,16] "Register Cosmo Today!"

And this map coordinates to strings.
You could keep lists of NPCs and monsters too.
[/quote]

I implemented this and it works great. The only thing I need to do is figure out how to empty the previous events when I change rooms.

For example. vector<vector<Entity>> mve(width, vector<Entity>(height));
mve (map vector entity) is a vector of a vector of entities (a class made for entities). When I go from map to map, mve still stores the previous maps events. How do I clear a vector of a vector of a class?
You could delete your map object and make a new one with the file.

eg:
delete mapobject;
mapobject = 0;
mapobject = new maptype(filename);

That will flush out everything and let you start fresh.

You could delete your map object and make a new one with the file.

eg:
delete mapobject;
mapobject = 0;
mapobject = new maptype(filename);

That will flush out everything and let you start fresh.


I tried all three and a lot of other things.

When I write delete mve it says expression must have pointer or handle type. I tested this and outside of the game loop you can delete mve just fine.

Any ideas?
I am trying to clear mve on lines 242 and 245.

Here is main.cpp http://pastebin.com/ijniABZi
Here is main.h http://pastebin.com/C8czy6a5
Here is maps.h http://pastebin.com/LscF4HPj

I just don't get what is going wrong.

I have no idea why when I insert this


        Entity empty;
        for (int i=0;i<30;i++){
            for (int j = 0;j<30;j++) {
            mve[i][j] = empty;
            }
        }

before this


        Entity door;
        door.set_warp("house");
        door.set_hero_loc(16,15);
        mve[15][9] = door;

I get an vector subscript out of range error.

What is going on here? angry.png

I fixed it. That was the most painful bug I have ever experienced.

I fixed it. That was the most painful bug I have ever experienced.

If you follow a career in computer programming you will experience thousands of new and creative ways to break things. To me, that is part of the fun.

This topic is closed to new replies.

Advertisement