Friday, November 30, 2012

Game Update 4: A New Mapping Solution?

Mappy Fail
Mappy Fail?
I have spent many long hours staring at the code I've written for my Ultima Style cRPG. As I mentioned back in my last up date I'd run into a few snags. One was a crashing problem where I was trying to de-allocate memory for an object I created twice. That fix came pretty quickly once I looked at what I was doing.  The next problem has not been so easy to fix.

The problem I'm having (and I'll see if I can explain it) is I have a tile based map (using Mappy) and I have a little animated guy running around the map. Now, every time the little guy moves he moves an arbitrary amount of pixels. This represents his speed and needs to remain constant through out the game. Since the map is bigger than the window that contains it the map needs to scroll. The part of the map that is shown while scrolling is represented by a rectangle and it has a coordinate system that is an offset from the coordinates of the little guy.  The problem is when I'm on the upper and left side of the map the guy moves the correct amount of pixels and the offset moves the correct amount of pixels. But when the little guy hits a certain point going left or going down he begins to double the amount of pixels he moves each time but the offset moves the correct amount of pixels. Eventually the little guy outruns the offset and goes off screen. I have no idea what is going on behind the scenes to make the little guy suddenly double his movement amount but not the offset. Arrgh!

I hope anyone reading understands.

Now, I'm using Mappy to draw and represent my maps for two reasons. One: I wanted to try and link it successfully to my project and be able to use it. To an extent this has been successful. I created a map, was able to load the map into my "game" and move around with my assigned keys. Two: I wanted to use an easy to use editor to make maps. The alternatives being finding a different mapping system to use (and there are alternatives out there), creating the maps via text files (this isn't ideal because it could take a loooooooooong time to make large maps by hand, roll my own map editor and system. If I decide to change to one of the alternatives it will be a bit time consuming as I have to rip out all the old Mappy stuff I've put in and replace it with what ever other alternative there is. Some may take more time than others.

Changing out mapping systems might be premature right now as I'm not 100% confident that "that" is even the problem. The map scrolls fine but the sprite I have is acting up. The scrolling of the map is pretty much handled internally by Mappy but the moving of the sprite is my own C++ voodoo. There could be a translation problem from Mappy to my own code.

What I'm thinking about doing is creating a copy of my project and in that project I'd rip out all the Mappy code and put in my own map using an Array of integers being sure to make it large enough to scroll. That way I'll be able to see if I'm still having the same problems regardless of what tile based mapping solution I use. If I'm able to fix my problem then I think I'll have to go with the option of making my own mapping based solution and writing my own tools to map the world. This isn't something I've been to happy thinking about as it will represent a lot of work. Hell, the very thought of ripping out the Mappy stuff and writing my own map handler hasn't sounded too fun to me. But, I think it's something that I'll have to do. Solving this problem is bugging me. I need to find out answers.

So, a quick update to let those who are interested in this project know how things are going.

5 comments:

  1. I'd be happy to go over the code if you want to send it my way, a second pair of eyes never hurts.

    ReplyDelete
  2. Replies
    1. I'll try and upload it to your server in the next day or so.

      Delete