Sign in to follow this  
kingpinzs

How put interacitve objects on a map

Recommended Posts

How do people put there interactive iteams on a map? I heard that link list can be used to put the tiles on the map. but I am not sure how that would work. and would you use the same way to put your units and npc's on the map also? Any ideas will be helpful thanks

Share this post


Link to post
Share on other sites
Just like you said. Have a list of objects. The implementation depends on how you like it.

You could have a general class like cInteractive or cEntity or whatever, and have all objects that are interactive derrive from it. Then have only one manager like cInteractivity or cEntityMgr, that controls the array/vector/list.
You could also have a manager for all types of objects, like cItemMgr, cNPCMgr.
Heck! You could even make this not encapsulated in classes, but just in an array/vector/list with supporting functions.

This is a more game-datastructure related question, and there are 'general ways' to do it, but I think it's much more fun to think of your own ways and make it how you want it to be. That's what programming is about, creative coding!

Share this post


Link to post
Share on other sites
well first I dont know how to use classes so that will not work.

second can any one show me how to use link list in a simple dos program?

and should I use just link list or is there a better way to do it?

Share this post


Link to post
Share on other sites
Did a quick google, this should clarify linked-lists in C++

http://richardbowles.tripod.com/cpp/linklist/linklist.htm

Share this post


Link to post
Share on other sites
You gotta learn about classes... how do you make a game without classes... espcially with NPCs and maps?

I use a class for my characters called Entity.
In this class it has a pointer to a list. The pointer holds animation sequences, which is basically just lists of pictures used in a sequence. You then use something called an iterator to move back and forth through the list.
So, for example, I have a function called CheckAnimTime(), which just checks to see how much time has passed in my game loop and if it is time it will get the next image in the list using my iterator.

The list is a pointer because it needs to be dynamic, which means you can add sequences on the go. So you say player1->AddList(BREATHING); and then booya, you got a list you can add images to that will be used for player1's breathing sequence. You can do that for DYING, WALKING, RUNNING, ICESKATING, etc.

I am a noob at animation, but it works for me.

Share this post


Link to post
Share on other sites
well you can teach me how to do classes or I can use structs instead.

I have read the article on this site for link list and also the link that was in this post and servral others I found. I think I figured out what link list are just have not figured out how to make one.

as far as I can tell link list are like a array of types stored in memory and have pointers pointing to the data and you can add,remove or rearange the data in the link list useing the pointers

If I am wrong let me know.

So can some one show me how to add data into the link list and the read the link list?

Thanks for the help so far.

Share this post


Link to post
Share on other sites
You have the basic idea. Yes, a list is just another data structure. A way to store data for later manipulation and retrieval. They are not exactly like arrays though. An array gives you random access to data stored in it. If you want item "x", you can just go to element "y" in the array. If you want item "x" in a list, you have to iterate through the list until you find the node that has "x" (unless you already have a pointer to the node).

Quote:
So can some one show me how to add data into the link list and the read the link list?


A starting place...

Share this post


Link to post
Share on other sites
so if arrays are random accses then why use link list that are not? why not just have arrays? is it because you can add or take away data better or what?

EDIT: also how could I load the data from a text file into the list?

[Edited by - kingpinzs on May 26, 2005 8:10:49 PM]

Share this post


Link to post
Share on other sites
You can split wooden boards with a hammer right? So why would you ever use a saw? It's all about knowing which tool is right for the job. Yes, in many cases lists can grow, shrink and sort faster than arrays. But there are no hard and fast rules. As is often the case, the answer is "it depends". You just have to know when to use which and that only comes with study and experience. It can't be taught in a round of posts on a message board.

There are some general cases where people often choose one over the other. If you need to add or remove items from a structure constantly, it may be a good idea to use a list. For example, you may want to store the items to draw on the screen for the current frame. For this you may use a list. This is because you don't know from frame to frame how many items will be in that list (it can change a lot depending on where the user is looking or what state the game is in), and you don't necessarily need access to a particular item in the list (don't need random access), you just iterate through and draw them.
Conversely, if the number of items never changes, you might just use an array. For instance, if your game always has two players, you may just store two Player objects in an array with two elements. Then you can quickly perform actions on a player by indexing the appropriate element. Again, these are just examples, there are no rules to this. Just pick the structure that makes sense for the job.

[Edited by - CodeMunkie on May 26, 2005 9:23:19 PM]

Share this post


Link to post
Share on other sites
well this is what I have came up with

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

struct node
{
char name[20];
int age;
float height;
int xpos, ypos;
node *nxt;
};

node *start_ptr = NULL;



int main(int argc, char *argv[])
{
node *temp,*temp2;
int input;
cout<< "Enter 1 to input data enter 2 to read data: ";
cin>>input;

if (input == 1){
ofstream bout("data.txt");
temp = new node;
cout<<" Enter unit name: ";
cin>>temp->name;
bout<<temp->name;

}
if (input ==2){
temp = new node;
ifstream bin("data.txt");
cout<<"Unit name:";
bin>>temp->name;
cout<<temp->name;
}
// else




system("PAUSE");
return EXIT_SUCCESS;
}


am I on the right track?

Thanks for the help so far

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