CSV and gravity fights

Img found on Heart of the Forces

Last two weeks I’ve been fighting with physics. Generally, it was all about collisions, gravity, velocity, and other stuff that I had to know from school (and I thought I did, how naive of me!)

But to be fair, before that I’ve written a loader for a CSV-based level maps. There were some surprises, too. Who knew that when Corona reads a file — it wants to have Windows-style line break, not Mac’s? So if you want to parse your CSV — you need to actually save it in windows format. I know it now! And it took me only like 3 hours to figure it out!

For now, I have this flow:

  1. After the intro, init the game load.
  2. There’s no saving at this point, so I simply find a game file of act1, and it points to its CSV level map.
  3. Then, parse the file and read it cell by cell. If cell value points to an obstable — load the image of that obstacle, and add the physical object with this image to the level. There is no random level generation in this game — you can memorise the level and pass it for a perfect score (there’s no score yet, though 8))

So that’s when I collided with physics, and we didn’t like each other. The first problem was that if you are moving your level map to some coordinates, but your character stays at 0,0 — the stop stop colliding properly. Ok, I got over this issue by creating a “camera”, and giving my character a velocity to move through the level map.

Then a really pointless work started. I’ll talk about it being pointless later — but at the beginning, I was determined to create a “real” physics with gravity, velocity, jumping-falling-landing and other serious stuff. I put together a simple transition for horizontal velocity, added gravity and vertical velocity for the jump. Surprisingly — it worked. And it looked awful.

Don’t get me wrong, all of my graphics is awful at this point, but I have some ideas about the final “feel” of this game, and that realistic jump trajectory just don’t work for it. With that, after spending several days on adding physics, I had to spend even more on trying to explain to the engine that I need its physics, but not really.

The gravity was mostly removed. The gravitational rotation of objects was removed completely, so that character stopped flipping over. And so on, and so forth. I think I could hear the Corona’s developers screaming in agony — they did so much for all of this to work and I am just throwing these things away.

As a result, I have a collision handling that’s much closer to what I want, but the animation still looks awkward. I need to work more on velocity change, so it would change in line with character movements. Otherwise, the character continues to move forward with both of her feet firmly on the ground. And there’s no video for this week because I just can’t stand this effect, and it blows my brains up.