Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / 2D Tile Map

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd May 2008 18:36
Alright. I'm learning C++ and the DarkGDK. With some help from Lilith and others, I've formulated a basic plan for a Mario Clone of sorts ( for the learning experience ).

The plan is to create an array of numbers 0 - 19. Then, a loop will read the array and fill a second array based on what number is in each piece of the array. For instance, if it finds the number "1" in ( 10, 5 ) of the first array, it will copy information about the type of tile associated with the number 1 into ( 10, 5 ) of the second array ( solid, image for sprite, damaging, etc. ). The world will be drawn off of this information.

Now, my question is, how would I go about making the program load the information for the first array from a text file? That way, I could make a text file for each world that contains a grid of numbers 0 - 19, each one representing a certain type of tile ( rock, brick, enemy, etc. ).
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd May 2008 18:47 Edited at: 2nd May 2008 18:51
Here's some of the code to illustrate what I mean. I would like to load the initial array from a text file. I'm very new to this, so, I apologize if it is horribly written:

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd May 2008 19:37 Edited at: 2nd May 2008 19:48
Ambitious, eh?

This is really something that needs to be done in stages. You need data in the file in order to have something to read in. Your main program aside, you'll probably want to start with a program that will let you build and test your levels. This could be in the form of a graphics screen where you have your various building images as sprites that you click and drag into position and then place the appropriate value in your array to indicate what building block has been placed in what location. When finished you can then write the binary data in the array out to the file.



This creates a file called "levelOut" which needs to be opened, when necessary, in binary mode so that saving it won't cause conversions for text content. With the .write() function you're telling it to take the contents at the address where TileMap begins and save sizeof (TileMap) bytes to the file. Then you close it so the buffers are flushed and the file is closed.

When you run your game you create a file for input



and open it for binary reading



and your data should be in your array.

Mind you, this is about as detailed as I'm willing to get on something like this. Writing a fully featured game isn't as simple as creating a loop within your main () function and executing things. If you tried it that way things would get nested so deep you'd never find your way out of your jungle of curly braces. You need to use classes and functions to break your functionality down into small enough units to keep the confusion level at a minimum. Most likely your file saving functionality won't be at your main () (or DarkGDK) level but rather buried inside a function somewhere.

Edit: Though I haven't gotten to that point yet, it's safer to store your level data for all levels in one file. It helps to prevent hacking and modification of your data by not having a separate, identifiable file for each of your game components. By collecting the data in a limited number of files it makes it more difficult for someone to modify the play and thus run up high scores on games that have been reduced in difficulty.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd May 2008 20:05
The code I posted isn't in the Main loop. It's in a separate file. The main loop calls on the setupScenery ( ); function.

I'm new to C++, so the file commands you posted are Greek to me. And as far as modification worries, I was choosing to load maps from text files for that purpose, to allow easy map modifications. I wanted something easily customized. This isn't for any purpose except a learning experience.

Login to post a reply

Server time is: 2024-11-17 13:00:53
Your offset time is: 2024-11-17 13:00:53