Part One - It begins
Part Two - Technical Foundation
Part Three - Game Design
Part Four - Input and Physics
Part Five - More Physics Things
Part Six - Even More Physics
Part Seven - User Interface
Part Eight - UI and the Editor
Part Nine - Editor Progress
Part Ten - Progress, and videos
Part Eleven - Fixing the Physics
Part Twelve - Unproductive
Part Thirteen - Context menu + enemies
Part Fourteen - Enemies and Problems
Part Fifteen - Play testing
Part Sixteen - Editor and Art
Part Two - Technical Foundation
Part Three - Game Design
Part Four - Input and Physics
Part Five - More Physics Things
Part Six - Even More Physics
Part Seven - User Interface
Part Eight - UI and the Editor
Part Nine - Editor Progress
Part Ten - Progress, and videos
Part Eleven - Fixing the Physics
Part Twelve - Unproductive
Part Thirteen - Context menu + enemies
Part Fourteen - Enemies and Problems
Part Fifteen - Play testing
Part Sixteen - Editor and Art
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. Last week I talked about fixing a couple of smaller issues, working on the editor a bit more, and had some early art of the main character. This week I'll be talking about getting moving platforms to work properly, and have a new video. This video also includes a little bit of actual art!
Moving Platforms
The moving platforms in Sam the Pirate have a very simple design. They move in one direction until they hit a stationary tile, then they turn around and go in the other direction until they hit something else, etc. I had previously implemented this behaviour into the game, although that was before I started work on the editor, so the positioning and size of the platform had been handwritten into the level file, now I was looking to add them to levels through the editor.
This turned out to not be too difficult. Positioning the sprites that make up the moving platform was easy, as it was pretty much the same as what I had already done with positioning regular tiles. Correctly calculating the size of the physics object that would be loaded into the game was not particularly difficult either. Making sure that the position of this physics object matched up with turned out to be a bit trickier, mostly because I forgot parentheses.
As the moving platforms are made up of a set of regular tile sprites, each with their own position, the correct position of the physics object needed to be in the centre. So I had to find the position on the left edge, the position on the right edge, and find the middle. Initially I did it like this:
position = right - left * 0.5 + left
Can you see the problem? Lets enter 100 for right, and 50 for left. The expected answer would be 75, yet you would get 125, because I totally forgot about the order of operations, PEDMAS, or BEDMAS, or however else you may have been taught. Either way, I forgot that any multiplication/division would be done before addition/subtraction, and so the position of the physics object was not matching the location of the sprite, which was were I wanted it to be.
To get the correct result, it needed to look like this:
position = (right - left) * 0.5 + left
I had a bit of a laugh at myself afterwards for forgetting something that should be so simple.
What that fixed, moving platforms placed into the editor loaded correctly, and started going back and forth when I played the game. The player was able to jump on and off the moving platform, however they couldn't run on them. This puzzled me for a while, as all the code for ensuring that the player was moving in tandem with the platform appeared to be working correctly, without preventing the player from moving left or right. Their position even seemed to lag behind the platform slightly, as eventually they would fall off completely.
Finally, I noticed that the game was attempting to make sure the player was moving in tandem with the platform twice, at two different points each frame! The second instance was late enough in the frame to override any player movement, making it look like they couldn't move at all. That piece of code came from when I had first implemented the moving platforms, so once I took that out everything worked just fine, as you can see in the below video!
Video
Can you spot the moon walking zombie pirate?
What's next?
Parallax scrolling is the next big item to implement. Still not entirely sure how I'm going to implement this, or what I'm going to put in there, but I've got some time over the weekend to think about it before I get stuck into it next week.
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! You can also check out the blog, previous posts, screenshots and videos over at my site.