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 / My plan ( open for suggestions )

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 04:42 Edited at: 21st Jun 2008 04:47
I've come across an interesting problem and would like all of your opinions on my planned solution.

The game I've been working on is a 2D Tile-based RPG with the mechanics of Dragon Warrior for the NES.

Wikipedia: http://en.wikipedia.org/wiki/Dragon_warrior

Youtube: http://www.youtube.com/watch?v=IihWAERWDDE

If you watch that video for a bit ( or skip about a minute into it ) you will see that, each step, the screen scrolls on tile. I like this type of movement for many reasons. Also, each frame, the NPC's are animated and randomly move. They move even if the character is moving. I think mimicking this would be a fun challenge. My plan is this:

Each frame, instead of calling a function like the one in my last post ( http://forum.thegamecreators.com/?m=forum_view&t=131895&b=22 ), I should make a queue. For instance, if the right arrow key is pressed, set the bool queuedMovementRight to true. Then, before the end of the main GDK loop, have a loop to handle any queued functions. Here is an attempt at demonstrating what I mean. It is a lot of code, but plenty of comments on the main section. Also, the definition of cTileMap is included afterward.

EDIT: The formatting is screwed up, so you can download the attached file with source for the first snippet.



And, as promised, cTileMap's definitions. A fair bit of code. You might as well just skip it. Not really worth looking at.









Any comments/opinions on this would be appreciated.

Attachments

Login to view attachments
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 04:55
I don't know enough about vectors or how you use them to help much.

To randomly animate an NPC, you'll want to do this:

-give each NPC a variable called something like m_iTimer. initialize it to equal dbTimer().

-make an array and fill it with the IDs of every NPC in the currently loaded area.

each cycle, call a function that goes through that array and check to see if enough time has gone by to do a random test to see if an animation should be done:

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:02
Actually, I was more hoping to get comments on the system of queues I set up. I'm curious what others more experienced than myself think of it.

I'll keep that code in mind when I get to the NPC's though.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:08
I think that a complex queue can be avoided if you go through a list of functions each cycle that:

do calculations for the map
do calculations for npcs
do other calculations
dbSync();

just make sure you don't have any infinite loops, and control should pass from function to function quite smoothly
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:14
What I was hoping to do in the actual game code is put that queue into a function that is called in the walking-mode of the game. The other modes would be handled in a more standard fashion. I just thought that the queue format would help make the drawing functions work together more effectively. Though, I'm sure there are many other methods that are just as good.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:16
i'll leave it up to you to mess around with the redrawing of the map, just know that calling dbSprite() thirty times each cycle will kill your game.

or will it?

just make sure you've got dbSyncRate(0); set
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:19
Quote: "just make sure you've got dbSyncRate(0); set "


Why would I set it to zero? Setting it to sixty allows the correction animation of scrolling the map.

Also, the draw functions are quite fast. It's amazing what C++ can handle ( especially with VC++ optimizations ).
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:21
Wait, should I add a static variable to the draw function allowing it to simply move the sprites if recalled?
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:23
just give each sprite an x and y member variable, and always draw from those variables. then just change those variables as needed, if i know what you mean.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:24
i don't know what this correction animation is, but setting it to 0 makes it go as fast as possible.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:28
If you take a look at my cTileMap class, you'll see how I've set it up.

I was thinking of adding another function like place_map that, instead of redrawing the map, moved the already drawn map to the desired position. I would think that would be more efficient.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:30
Quote: "i don't know what this correction animation is, but setting it to 0 makes it go as fast as possible. "


If I set it to zero, the speed of the program would be untamed. So, there wouldn't be any scroll animation. There would only be a jump from one spot to the other. I want the speed of the program automatically leveled out.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:54
untamed you say. unless you work with a pixel per # of ticks timer.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 05:55
what function(s) in the GDK would "move" the map tiles?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 05:57
My bad. I was thinking a certain command did something else.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 22nd Jun 2008 18:00
If I understand you right then you want smooth scrolling tile maps like in the above video? The basic premise behind it is actually alot simpler than you think

two vars to start with:
int nWorldX = 0;
int nWorldY = 0;

These are tile offsets for your tile map. Depending on what type of system you've written then your implementation will be different, but assuming you have a two dimensional array holding tile id's for your entire tile map then your code to render the map would look something like:


obviously you need to do error checking to make sure x + nWorldX isnt bigger than the array etc - thats just a quick knock-up there. But the idea is the map is offset by the values stored in your world co-ordinates. TileRowWidth/TileCollumHeight are just how many tiles you want to draw along the screen and down it.

Anyway, to calculate the world co-ordinates you need to know where the player is in the world. This is a simple case of keeping two variables, like:

int nPlayerWorldX;
int nPlayerWorldY;

to track the players position in the world. If he moves right just increase nPlayerWorld by how far he moved in pixels, etc. Then you can calculate the world offset like this:

nWorldX = nPlayerWorldX / nTileWidth;
nWorldY = nPlayerWorldY / nTileHeight;

dividing the players current position by the width and height of your tiles will return the players position in the world by number of tiles. So if it returned 3 for his X then it means he's stood on top of tile 3! (width-ways at least )

now as the player moves along the map will automatically scroll However! You will notice this scrolls the map one tile at a time which can look jerky and not really what you want. What you want is per-pixel scrolling. This is actually easy and you just need to add a bit of code to the above setup. First you need to calculate the pixel offset of the map which is done like you calculate the tile offset, but this time you use mod instead of divide. so:

nWorldOffsetXpx = nPlayerPositionX % TileWidth;
nWorldOffsetYpx = nPlayerPoisitionY % TileHeight;

then when you draw a tile to the screen just add those offsets to the tiles x/y position on the screen and you will have perfectly smooth scrolling.

One final thing - because you are now scrolling by pixel you will notice black boarders appearing as you move around the edge of your map. The way to fix this is simply draw an extra row and an extra collum than you need

Phew.. maybe a bit much and not explained very well - but it will produce screen movement like in the video you linked us

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 22nd Jun 2008 20:44
Thanks for the explanation. I've implemented most of that already. Here's some of the code:

Tile map class


And some drawing code:


I've gotten a fair start on it. I just haven't worked on it for a few days. Thanks for the suggestions!
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 22nd Jun 2008 20:45
P.S. I know the scroll code is not at all finished. Just a very basic start. Working on a better method.

Login to post a reply

Server time is: 2024-11-20 15:24:07
Your offset time is: 2024-11-20 15:24:07