Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Interacting with signs. I need advice.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 19 December 2012 - 11:37 PM

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.

Posted Image

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?

Sponsor:

#2 Magdev   Members   -  Reputation: 197

Like
1Likes
Like

Posted 19 December 2012 - 11:50 PM

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.

#3 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 19 December 2012 - 11:57 PM

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~!

#4 SuperVGA   Members   -  Reputation: 1118

Like
1Likes
Like

Posted 20 December 2012 - 01:29 AM

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.

Edited by SuperVGA, 20 December 2012 - 06:52 AM.


#5 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 20 December 2012 - 09:55 AM


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.


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?

#6 MrDaaark   Members   -  Reputation: 3555

Like
1Likes
Like

Posted 20 December 2012 - 10:03 AM

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, 20 December 2012 - 10:04 AM.


#7 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 20 December 2012 - 11:09 AM

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

Edited by black_darkness, 20 December 2012 - 11:13 AM.


#8 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 21 December 2012 - 12:12 AM

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, 21 December 2012 - 12:13 AM.


#9 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 21 December 2012 - 01:17 AM

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



#10 frob   Moderators   -  Reputation: 22787

Like
2Likes
Like

Posted 21 December 2012 - 01:31 AM

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.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#11 black_darkness   Members   -  Reputation: 280

Like
0Likes
Like

Posted 21 December 2012 - 01:41 AM

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.



#12 Servant of the Lord   Crossbones+   -  Reputation: 21191

Like
2Likes
Like

Posted 21 December 2012 - 01:43 AM

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:

myVector[(y * width) + x]

 

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:

myMap.assign((width * height), defaultTileValue);

This overwrites all the existing values with 'defaultTileValue'.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS