LevelManager,Collision & Time

Okay, this week have been a slow week for programming and it’s because I am reading Serious Game Design at the side. O well so today I will tell you my assignment I got this week and what I have done.

Last week the comment mentioned that they did not quite get what the LevelManager did and so I am here to tell you.

The level manager uses the library  a library that allow you to read a row or individual characters if you know what you are doing.

So this is how the process of our code works.

First I open the map1.txt file that we have saved by using a
std::ifsteam stream(”../data/Assets/map1.txt”)
Though ours look a little different with a INT added so that we can change easily between several maps.

After that I read in the tile map’s location through the .txt and then look at how many tile coordinates it will read in like the following.

../data/Maps/Floor_SpriteSheet.png  – This is the Tile map
12 128 128 – here we have it showing that we will read in 12 rows of tiles Then these tiles are 128 x 128 in size.

Down here we see the following being read in.

Symbol for the map, were on the sprite sheet the tile is, and if it’s walk-able or not.
0 387 258 1
1 0 0 0
2 129 0 0
3 258 0 0
4 0 129 0
5 129 129 0
6 0 258 0
7 129 258 0
8 258 129 0
9 258 258 0
t 387 0 2
b 387 129 0

Then we read in the map that is

000000000000001010
000001000000001t10
001111111000001310
001111111111111310
001113333333333310
001113111111111110
000003100000000000
000001100000000000
000000000000000000

were the numbers are the tiles as you can see above and only the 0 with a 1 at the end are not walk-able.

That is how we do the map.

NOW when we read in the map we create a std::vector collision_box.
it does just that read in a FloatRect that is the size of the sprite. This was done so it would be more easy to cause a collision.

Now come the part were I complain about my time. I have had a hard time to get into the programming mindset this week. As I have had an other course in the afternoons it disturbs the rhythm that I work in.

So this week I am suppose to have made a collision manager that works. It does not as of right now and I hate it. I hate making the collision manager. It requires a lot of math and it’s not that I am bad at math. I just can’t see how I make the math I want in the code and this kind of math that I am suppose to do is harder than I thought.

I am stalling here a little but okay so here is a quick thing I can tell you about how the hit box work.Collision_squares

 

 

 

 

 

 

 

 

 

As you can see when we read in the 0 in the map on a row and the 0 is next to an other we create a longer hit box. This we do to ensure that we have fewer hit boxes to check if you collide with them every update. This is a real time saver.

Now here is how you can tell if a collision occurs easy. Use the SFML librarys own checker. That is the m_floatrect.intersects(m_other_floatrect); That checks if 2 rectangles overlap.

Now that that is done I will tell you what I am working on this moment and trying to make it work.

Collision_expl

 

First I have to take one of the hit boxes and learn as you see with the arrows there matrix so that I can ensure that the player when he tries to walk into that circle either do the following.

First check if the next move the player tries to move into the square ensures that he can’t walk path it.

OR

The one I am trying to create at the moment. Make it so the character can’t walk in at all. This method is called pixel perfect collision and I might be a little over my head. But I am not sure yet. Since I am testing the code out.

I can’t really tell you the exact math that happens here. Because I am not half sure myself. What about that eh? Now you might ask yourself if he doesn’t know how can he make it work? Trial and error my friends trial and error, I’m looking at others code and from that I try to figure out how it works and implement it to my code. I am right now at my 10th or something persons blog or something else and looking for the answers.

I will update you how it goes next week but now you know what I am doing and what I have done 😛 hold thumbs that I manage to make the collision work tomorrow because I have the entire day for coding!

Thank you for reading have a nice day.!