Part Two - Technical Foundation
Part Three - Game Design
Part Four - Input and Physics
This Week
Hello again TeamLiquid!
Welcome back to my blog about the development of The Adventures of Sam the Pirate, the 2D platformer I'm creating as the final game project for my Bachelor of Software Engineering degree. Apologies for the lack of a blog last week, I came down with the flu and didn't get much done, which has put me a bit behind! Last week I covered how I was handling input, and some of the work I started on doing the games physics. This week I'll be going over where I'm now at with the physics.
Movement
Since the last blog, basic left and right movement is in and working, complete with acceleration and deceleration. Jumping is in, as is some basic collision detection/response. You cannot control left/right directional movement while in the air, but that's next on the list. The intent is definitely that you'll be able to change direction at will while jumping. Jumping itself feels slow and wrong at the moment, but hopefully that just requires tweaking the numbers over the next couple of months until it feels better and looks more natural when compared to the rest of the movement.
At its simplest, the movement is calculated, using 2D vectors, like this:
velocity += acceleration * deltaTime;
position += velocity * deltaTime;
With deltaTime being the time taken to process a frame, and there are a bunch of other considerations like capping velocity to certain values to prevent craziness, and checking if the character has come to a halt or not. Acceleration is calculated whenever a force is applied to the physics actor, sort of using the trusty old f=ma equation that you may recognise if you ever studied physics at all.
acceleration += force / mass;
There are checks in here as well, to cap the acceleration to predefined values. Now this all looks really simple, and if you're better at physics than I am (the more advanced stuff especially has never been my strong point), you might be kind of horrified at how I'm doing things! In fact just now I realised I've got a plus equals in my acceleration, so I'm probably doing it all wrong, but it works, and that's the most important thing. It doesn't matter too much how it works, just that it does, and allows me to move on with production.
Collision Detection
Collision detection is also pretty simplistic. Everything in the game is represented in my physics code as a rectangle, or an Axis Aligned Bounding Box, AABB. Luckily for me SDL comes with a function for testing whether or not two rectangles are intersecting, so I don't even have to do any maths. The downside to this, is that it purely uses integers, rather than floats, which makes it kind of inaccurate. However I don't need accurate, so it's probably alright.
Using this method, there's some clear intersection going on when my player character falls onto the ground from a jump, rather than simply standing on top of it, but I was kind of expecting that. The SDL function does give me the position and dimensions of the intersecting rectangle, so I should be able to use that to detect what direction the collision is coming from, and adjust the moving character appropriately. Right now all I'm doing is halting the vertical velocity of the moving object, and ensuring that stays zero for as long as the player is on the ground.
If doing things so simply comes back to bite me in the ass in the future, well, I'll just have to deal with it.
What's next?
I have a milestone due next week, to meet it all I need to do is add some more platforms and make sure the movement and physics is all fine and hopefully not buggy. So over the next week I'll add some more platforms to test with, add a moving platform, and then potentially look at adding a swinging vine, as that is a game play element I want to have in the game. I've done some basic physics code with springs before, so I'm going to look at using that to do swinging vines with.
So next week I'll cover my progress with that, and possibly look at doing a super early pre alpha game play video to go with the milestone. Also spoke to one of my artists today, and hopefully I should also have some new art to show off next week as well.
Keep up to date!
Be sure to follow me on Twitter, and like the Facebook page to stay up to date on future content and blog posts when they happen. If you have any questions don't hesitate to ask, either through Twitter or Facebook!