Friday, July 27, 2012

Vacation

I've been on vacation since July 20th and will continue to be away until August 13th. The programming will resume then.

Tuesday, July 17, 2012

Day 12 - More Mushroom Collisions

Today I added collision detection between objects so now everything on screen can play nicely with each other. I of course ran into some snags along the way which always seems to happen when I move code around. I also spend a good bit of time modifying my spritesheet to include big Mario and fire Mario. I finally got everything working but when I ran the game the mushroom didn't appear. I debug and see that it spawns properly, slowly rising out of the question mark brick, but nothing appears on screen. I didn't modify the code which draws items on the screen but threw in some breakpoints just to be check. Sure enough it is drawing properly.

This issue has to wait until tomorrow because I can't stay up any longer messing with it. Tiredness is not helping me program successfully.

Thursday, July 12, 2012

Day 11 - The Mushroom

It's great when things just come together.

I moved all the collision detection stuff into the moving game objects so now any object I create will automatically respond properly to gravity and tiles! Getting the mushroom to move and bounce off objects was a simple task.

The next not-so-simple task is to have the mushroom disappear and power up Mario when it touches him. For this I need to slightly modify my OnHit() classes so everything plays together nicely. As it stands now, if I implement a jumping enemy it will also be able to break blocks. I started the changes but haven't finished them yet.

Here's a video of the mushroom in action. Nothing too exciting.


Monday, July 9, 2012

Day 10 - Refactoring

My goal today was to have a block spawn a mushroom. I completed that goal, but it took much longer than I originally anticipated.

My code needed refactored (read better organized) rather badly. I had references being passed around to so many objects that it was hard to keep track. For example, if a block needed a texture it first needed to be created by my game class, passed to the tile manager class, and finally given to the block itself. The same could be said about sounds and animations. It was a big headache dealing with all the references and creating variables to store said references. Instead I simply created a few static methods so that these things could be accessed by any object! This made my code much clearer and easier to understand. I don't think I'm done with this change, but it works for now.

Before, when I wanted the block to create a mushroom I would need to pass a reference to the game object list through a bunch of classes to the block. Then the block could add the mushroom to the list.

Now, since the list is static, any object can create a new object just by saying World.AddNewObject(new object)!

No video today because the mushroom doesn't have any collision detection implemented. Tomorrow I'll create some generic algorithms for any object that needs to worry about collisions.

Friday, July 6, 2012

Day 9 - The Camera

I got the camera working today. To do this I needed to add everything on screen to a new class I called World. The camera camera class takes an object to follow (in my case Mario) and moves across the world as Mario moves. I had some issues with the collision detection going bonkers after I implemented it, but soon figured out that my algorithm to find solid tiles on the screen was messed up with the addition of the camera. With everything sorted out, I built the rest of level 1-1 so Mario can run though it!

Today I learned the limitations of my tile manager class because I'm having trouble spawning objects like mushrooms and stars from blocks when they are hit. Each block needs to be able to spawn a new game object... To top it off, when I create an entire level my framerate drops from 6000 to 1500. It gives me new respect for the programmers that did this on hardware over 25 years ago.

 My code is currently torn apart and unplayable at the moment, but here's a video from earlier today.


Thursday, July 5, 2012

Day 8 - Bump

I realized today that small Mario can't break brick blocks, but instead they bounce up a few pixels and return to their original positions. I quickly implemented this and also applied the changes to the question mark block. While I was at it I added the coin popping out of the question mark block when it is hit. Finally, I edited my level file to reflect the first level in Mario Bros up until the halfway point. Next time I'll work on getting the camera working so Mario can run through the level!

Unfortunately I only had a small bit of time today to work.

Wednesday, July 4, 2012

Day 7 - Breakable and Unbreakable Bricks

I had a ton of extra time today so I got a lot accomplished. I feel like it's taking me longer than it should to implement each feature, but I guess that's just from lack of experience.

I finally got around to creating a sound manager. This holds 2 different types of sounds: sound effects and music. Sound effects are triggered once and play until they finish while music supports pausing, stopping, and repeating.

Next I finished up the brick class so it explodes into pieces when Mario hits it. I then implemented the question mark block which simply turns into an empty block when hit. I need to figure out how to load it with an item and have that pop out. I also squashed a bug in my animation class. I was calculating how long until the next animation frame but when one animation moved to the next frame it reset the time value. This caused the other animations to never advance frames! Now each animation holds a value for the time since it last changed frames.


Tuesday, July 3, 2012

Day 6 - Headbutt

Today I only had about 1 hour to myself. I got a little bit of reorganization and one new feature implemented.

First I fixed the drawing order of sprites so now Mario appears in front of all other objects like clouds and bushes. Next I added 3 methods to my tile class and Mario class: OnHeadbutt(), onStomp(), onSideCollision(). Eventually I will make a generic GameEntity class which holds these 3 methods, but for now they are simply copied into each class that needs them. When Mario hits a block from below, the OnHeadbutt() method is called and the block can respond accordingly. To test this I created a brick block which disappears when Mario hits it from below. Next I'll add some animation to it so we can see the pieces of the block fly away after it is destroyed.

The OnStomp() method will mostly be used by enemies since that is Mario's only way of killing them. It will trigger the death animation and also give the player points. Likewise the onSideCollision() will be used when a shell hits an enemy or when two enemies run into each other. I think implementing enemies is still a ways off yet, but the framework will be available.


Monday, July 2, 2012

Subversion Time

Let me rephrase my original statement about this blog. I will update every day except weekends. This is because I spend most of my weekends away from technology and my PC. For instance, yesterday you could find me sleeping in a small cabin on top of a mountain 200 miles away from here.

Today I played around with collision detection between Mario and the tiles that make up the level. First I needed an indicator to show whether each tile was solid. Next I implemented an algorithm to return the tile from any point on screen. Finally, I looked at where Mario was located and if he was colliding with a tile or not.

This took a lot of experimenting to get it right but I think I implemented a good solution. In previous games I would take every object on screen and compare it to every other object on screen to find collisions. This algorithm becomes very slow as the number of objects increases so I decided to find a better solution. I check each corner of Mario and if that point happens to fall on a solid tile then figure out what to do with Mario. This gives me a constant speed of 4 instead of n^2.

I'm still having a few issues with Mario's movement, but progress is coming along nicely.

If you want to view my source code, check it out on GitHub at https://github.com/Exor/SuperMarimoBros