Level Editor Update

http://www.youtube.com/watch?v=l3phEySchjQ

The level editor now supports multiple rooms.

Game Menu

Added a GameMenu class to ResistorKit, since that is a feature that I commonly use on many screens.  The GameMenu class keeps track of the set of menu items and which item is selected.  It handles rotating the selection back to the top when down is pressed on the last item or selects the last item when up is pressed on the first item.  This way I don’t have to rewrite this code on each screen that has a menu.

I expanded the menu system to draw the menu at a given position using a specified font, which are passed as parameters.  The text color and highlight color can be set using the appropriate method calls.  The spacing between menu items can also be set with a method call.  One feature I would like to add is passing the menu item action as a function parameter for each menu item, but the C Sharp way for passing function/method parameters wasn’t clear to me.  I did find some documentation on using Func or delegates, but I don’t want to invest time in figuring those out now.  Therefore, executing the action must be handled on the game screen using the getSelectedItem method that I created to return the index of the currently selected menu item.

The title screen has been updated to use the ResistorKit GameMenu class, and it takes advantage of the text and highlight color setting methods.  Currently, default text is black and highlighted text is green.

Level Editor Modifications

Updated the level editor so it now supports multiple rooms.  When the level editor is started it creates a default room that is the head of the list of rooms.  Pressing A will add a block to the room.  Pressing RB will add a new room to the end of the list.  Pressing start will add all created rooms to the game world.  Currently, a room can’t be edited once it has been added, but that is a feature I plan to add.  I will also need to add a method for navigating through the currently created maps.  Then I will probably make RB create a room to the right and LB create a room to the left of the currently selected room.

A preview of all levels is now displayed at the top of the level editor screen.  This preview expands as new rooms are added.  The room ID is also displayed in the upper right corner for each preview, but I may remove that in the final release.

Enemy and Jumping Updates

http://youtu.be/xm8JFK2N9LE

Jumping now uses acceleration and looks less linear.  Enemies now move across room boundaries.

Library Update

When developing a library, one important thing to remember is to make your classes that should be accessible in the API public.  By default, classes are created with no scoping.  You will not be able to access any classes in your library, until those are declared public.  Tonight, I added some of the methods I used for drawing raised text in Resistor to the ResistorKit library as static methods in a Graphics class.

Jumping

After reading about how others have implemented jumping, I decided to scrap my current linear method which is based on subtracting a constant value for a set number of updates.  That resulted in a constant jump speed and fall, which looks very angular when moving at a constant speed.  To fix this, two float acceleration variables have been added for jump and fall acceleration.  I could have probably used just one acceleration variable, but I thought breaking it out into two makes the code more readable.  When the player jumps, this acceleration value gets set to a constant which is the jump power.  This acceleration value gets subtracted from the player’s Y position on each update, which increases the jump height on each update.  Also on each update, the acceleration value is decreased by a constant value.  Therefore, the player’s jump acceleration decreases until it reaches zero.  At that point, the player’s falling variable gets set to true and a similar process occurs with the falling acceleration.  The only difference is that the falling acceleration continually increases so it relies on collision with a block to stop the fall.  I also added a terminal velocity value, which the acceleration can’t exceed.  Right now that won’t make much of a difference in my game since it doesn’t scroll vertically, but if there was a long fall then not having a terminal velocity would make the player impossible to control while falling.

Enemy Updates

I updated the Enemies collection so that a map can now correctly handle multiple enemies.  I also added a method in the Map class to move an enemy from one map collection to another.  This is used for moving a enemy from the current map to the adjacent map whenever an enemy moves past the room boundary.  Now enemies aren’t restricted to moving in only one map room.  Similar to the player, I had to add checks to ensure that an enemy doesn’t collide with blocks in the first column or last column of blocks in the right and left map rooms.

One interesting problem is that an enemy would get stuck in a block in an adjacent room whenever it was in the angry state from being shot with the wrong gun.  The problem was that the check for changing the room came before the check to change X velocity (direction) on a collision.  Moving the room boundary checking below the block collision call fixed the problem.

Collectibles

http://www.youtube.com/watch?v=eEXTFUYytJg

Each collectible adds 50 to the player’s money.

Collectibles are very similar to enemies.  An array of collectibles are assigned to each room.  Each collectible has an x,y position and a height and width.  Also, each collectible has an animation frame, which I have set to loop from 0 to 30.  I created a simple collectible model in Blender, which rotates in 30 frames.  Actually, it rotates half way every 30 frames, but it should not be noticeable since the collectible is symmetric on the Y-axis (at least I tried to make it that way).  What makes a collectible different is that projectiles don’t collide with collectibles, and collectibles have a value that gets assigned to the player when the player collides with the collectible.  Unlike an enemy, the collectible “dies” when the player collides with it.  For now, my simple collectible will add money to the player when acquired, but my collectible can be extended later to produce various types of effects.

Handling collision detection for collectibles was also very similar to handling collision for enemies.  I created a method in the Player class which takes the room collectibles as a parameter.  It loops through all the collectibles, and if the player collides with one then it adds 50 money (I’m calling FLOPS) and sets the collectibles “alive” flag to false.  I made one change in the structure for a collectible, where the location and size are contained in a Rectangle object.  For enemies I used two Vector2 objects for position and size.  The major difference is that the Rectangle uses all int values and the Vector2 uses floats.  The int values makes coding a little easier, since the floats have to be casted to int values for storing those values in a Rectangle object for calculating a collision.  I could write my own collision method using floats, but the Rectangle “Intersects” method seems to do the job well.  Finally, I had the World call update on all collectibles in the current room and two adjacent rooms, so that the animation frame value increments for each frame.