Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Game Map Module
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aange10




PostPosted: Tue Jul 31, 2012 5:23 pm   Post subject: Game Map Module

Usually when I begin a project I try to outline what I want, and then jot down what I want the specific program to do. I'm trying to get a module to help keep track of my map.

What I mean is when I'm programming a game I always have to have a map, entities on it, x/y cords, and I always need to keep in mind how to draw the right section of the map (if it's bigger than the screen). I was thinking to make a module to do this, but I need a little bit of help with the concept inventory.

What I have so far:
code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   This program will keep track of a *map*. You will be able to do:    %
%       - A picture to use for the map.                                 %
%       - Adding entities to the map.                                   %
%   Keeps map at 0.0 and draws the part of the screen you need.         %
%   Uses unique Id's to keep track of entities.                         %
%   Every entity has:                                                   %
%       - A unique ID                                                   %
%       - A picture (or none)                                           %
%       - A pointer to the object                                       %
%       - A position                                                    %
%   The map should be able to:                                          %
%       - Tell what entity is at a given coordinate.                    %
%       - Draw all entities and the map.                                %
%       - Take in a change in X and change in Y to update.              %
%       - Take in a position relitve to the screen and plot it relative %
%               to the map.                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


I'm kind of wondering if any of this is unnecessary to add to the module, or maybe what else I need? It sounded pretty good to just have a module to A) Draw the map at the right section and B) Keep track of x/y coords. But I began considering something: If entities are moving and the map is handled internally in another module, then the entities can't tell where they're moving unless they know the map (or their position), which defeats the purpose.

So then I began thinking to add an 'update' to take in the changes so that the entities wont need to know about the map, only to tell the module how they're moving. But with that, I also had to riddle "How do they know where they start at?"

Those are my thoughts so far. Can anybody share their thoughts? I'm not sure if adding update()'s and stuff would add too much, but I'm also unsure as to how to go about this.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Jul 31, 2012 5:37 pm   Post subject: RE:Game Map Module

I don't think you need a module. All you should have to do is compare your enemies' movement with the player movement, and then adjust accordingly. As for where to draw the map, you have a map offset variable change every time your character moves.

Maybe I'm not getting it. How is this game set up? So is it tile based, or an open map? Do you have forced movement like in pokemon or is it a lot more free? Is it overhead or side view? I just want a visualization of what you're doing is all
Aange10




PostPosted: Tue Jul 31, 2012 5:43 pm   Post subject: RE:Game Map Module

I don't have a game. I'm more looking for a module that I can use when I decide I want to work on a project.

However I ideally want something that would work on a 2d scroller, since that seems to be what I mainly use. I could most certainetly create this module with specific attributes to help it be a 'tile' map or other types of maps. But I first want to get this down before i worry about making modules for different maps.

I know I don't need the module, but I want to make something that can handle the maps for me when I'm making a game, instead of my worrying about it. Kind of how I did my collision module, or my hash/dictionary module.
Raknarg




PostPosted: Tue Jul 31, 2012 6:11 pm   Post subject: RE:Game Map Module

Alright.

I feel you should make a map class rather than a module, however.

So, you said you wanted to have it keep track of enemies as well. Have you ever worked with linked lists before?
Aange10




PostPosted: Tue Jul 31, 2012 6:14 pm   Post subject: RE:Game Map Module

Yes I have. And yes, a map class could be beneficial for games with multiple maps.

I'm not exactly too worried about implementation, and I just need help seeing how I can keep the map class separate from the entities, but still tell the map what it needs to know.
Raknarg




PostPosted: Tue Jul 31, 2012 6:22 pm   Post subject: RE:Game Map Module

Exactly, you want to be able to have flexibility.

Fair enough. I can see two different paths for this. Either you turn the map class into a master class and base everything off that (that's what I would do), or you can make a map with little map controls, and just have the objects change to the map. I'm guessing you want something like the second.

Why do you want them separated? Is it so you can use it for any type of map situation? if that;s true, then you can try making the map something like a server. Have it keep track of all the information, and have it send messages to different objects when certain events happen
Aange10




PostPosted: Tue Jul 31, 2012 6:41 pm   Post subject: RE:Game Map Module

Yes, I wanted it seperated so I can use it in any project. I need it not to depend on anything but itself. Making the map something like a server sounds close to what I'm thinking, but I was thinking more like a database.

Where I'm stuck though is what is necessary to keep and how to keep it. For example if I went with a class for the map I'd think something like this:

code:

map : array 1 .. 10 of MAPS_CLASS
map (1).addMapPicture (myMap)
% ^ Adds the map
.
.
.
map (1).add(Entity (monster (1)), xPosition, yPosition, picture)
# ^ Keeps track of position of entities
map (1).draw ()
# ^ Draws the map


Which I can implement easily, and this sounded fantastic at first. But then my problem is, how do I add an xPosition/yPosition? Is it relative to my screen? If I'm keeping track of things relative to the screen is it even necessary?

In my mini-rpg, the monsters were assigned to a map when I initialized their class, then I either (A) Assigned them to a platform or (B) let them randomly pick a platform. From there they just randomly spawned on a point on the platform.

Would I need a way to do the same thing with this class? If I did, would there be anything (other than syntax) that I'd have to keep in mind about the class (this is what I'm avoiding)?

I'm thinking that I'd need to initialize a position on the map, and then have an update procedure to take change in x and change in y. Or, (more preferably), maybe I could just have the map be able to give out information, but not have it do anything itself. That away there is no 'behind the scenes' stuff going on when I'm programming. I could simply query what i needed from the map and then do whatever I need to do and then tell the map my new coordinate.


Sorry if I'm rambling, these are just my thoughts on how to solve the problem. What do you think?
Raknarg




PostPosted: Tue Jul 31, 2012 8:04 pm   Post subject: Re: Game Map Module

My friend tought me something really simple and cool. All you have to do is store and offset variable.

You keep this global, as mapOffsetX and mapOffsetY. So the bottomleft corner of the pitcture of your map is actually zero and zero. The map offset variable tells you where you want the map to be drawn.

There's lots of examples of this. I like using Epic War as an example. The entire map is a picture. If you look at the mini map, it shows you the section of the map it's showing. That's basically what you do. You tell the computer what part of the picture you want to draw using the offset. So if your picture is like 2000 pixels wide, but you initialize the bottom left corner of your screen at the 1200th pixel, you would set the offset to 1200 and draw the picture at -1200, 0.

You use this same concept for the enemies. Lets say the enemy spawns at 500 pixels to your right,and your initial screen starts at 1200. The enemy's x coordinate is 500, but when you're comparing it to the map, it's actually 1700.

Does that make sense? you just use the offset to compare what you're looking at to what it actually is. And also you can change the offset as a character moves.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Jul 31, 2012 8:20 pm   Post subject: RE:Game Map Module

maybe I should clarify that a bit. In the database, you take in account the offset, but when you draw it you draw it with (initial information + movement changes) - (current offset)
mirhagk




PostPosted: Tue Jul 31, 2012 9:11 pm   Post subject: RE:Game Map Module

I actually designed a "screen" class recently, basically I just made it so everything could work in world coordinates (where in the map it was) and only input and drawing needed to worry about where it actually was on the screen. This abstraction makes it easy to add things like zoom, more fine movement controls, multiple screen etc. I suggest you do the same.
Aange10




PostPosted: Tue Jul 31, 2012 9:25 pm   Post subject: RE:Game Map Module

So you made something where you could input your coordinates on the screen, and everything else was handled in the class?
mirhagk




PostPosted: Wed Aug 01, 2012 7:52 am   Post subject: RE:Game Map Module

Well it was more every object in the game stored it's world location. Then when it came time to draw, the screen class handled translating those coordinates to screen coordinates, and actually drawing the object. When you clicked your mouse on a location on the screen, it translated that into world coordinates.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: