Sign in to follow this  
black_darkness

Interacting with signs. I need advice.

Recommended Posts

black_darkness    280
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.

[img]http://i49.tinypic.com/2h34vvd.png[/img]

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

They each use the tile class.
[CODE]
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;
}
[/CODE]

[CODE]
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
}
[/CODE]


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?

Share this post


Link to post
Share on other sites
Magdev    197
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.

Share this post


Link to post
Share on other sites
black_darkness    280
Thanks for the advice I will look into entity systems.

[quote name='Magdev' timestamp='1355982653' post='5012717']
Unless you don't plan on expanding your game past "The Adventures of Tinyguy: Rogue Sign-Reader Extreme".
[/quote]

ROFL~!

Share this post


Link to post
Share on other sites
SuperVGA    1132
[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.
[/quote]

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:
[code]
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!"
[/code]
And this map coordinates to strings.
You could keep lists of NPCs and monsters too. Edited by SuperVGA

Share this post


Link to post
Share on other sites
black_darkness    280
[quote name='SuperVGA' timestamp='1355988556' post='5012727']
[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.
[/quote]

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:
[code]
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!"
[/code]
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?

Share this post


Link to post
Share on other sites
Daaark    3553
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. Edited by Daaark

Share this post


Link to post
Share on other sites
black_darkness    280
[quote name='Daaark' timestamp='1356019438' post='5012826']
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.
[/quote]

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 [url="http://pastebin.com/ijniABZi"]http://pastebin.com/ijniABZi[/url]
Here is main.h [url="http://pastebin.com/C8czy6a5"]http://pastebin.com/C8czy6a5[/url]
Here is maps.h [url="http://pastebin.com/LscF4HPj"]http://pastebin.com/LscF4HPj[/url] Edited by black_darkness

Share this post


Link to post
Share on other sites
black_darkness    280

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

Edited by black_darkness

Share this post


Link to post
Share on other sites
frob    44904
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.

Share this post


Link to post
Share on other sites
black_darkness    280
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.

I got a huge rush after I solved it. Feels great. Now I am just worried about how disorganized my code is getting. I am inexperienced when it comes to organizing things.

Share this post


Link to post
Share on other sites

Quick tip: An array of arrays is not the same thing as a 2D array. One major difference is that each "row" of the vector-of-vectors aren't forced to be the same size.

 

For 2D arrays, I recommend a single vector, resized to (width * height).

 

You can then index into the vector using this:

[code]myVector[(y * width) + x][/code]

 

Although it looks more pleasing to do myVector[x,y], having a vector-of-a-vector complicates things by forcing you to manually keep the vector's rows the same length anytime you resize it.

 

To clear the vector:

[code]myMap.assign((width * height), defaultTileValue);[/code]

This overwrites all the existing values with 'defaultTileValue'.

Share this post


Link to post
Share on other sites

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