Levels

http://www.youtube.com/watch?v=sH-Juho6Kqs

Now with doors and level changes.

The latest build now contains many more improvements.  I created a Door object, which represents a door which will take the player another level.  An array of Doors is contained in the Map object, but I doubt I’ll ever have more than one door on a map.  However, I may have multiple doors in a level, and each door will take the player to a different level.  A World class has also been created to keep track of all the levels and the current level.

 

A method to determine if all of the enemies in a level have been defeated has also been added.  When the level is cleared of enemies, the message “DEFRAGMENTATION COMPLETE” is displayed.  At this time, all doors in the level will be unlocked.  For now, this is visually represented by the door changing from red to black.  At that time, if the player collides with the door then they will be taken to the next level as determined by the World object.

On the player class, I added a method which translates the player’s screen coordinates to the room coordinates, since calculating that value each time when needed became confusing.

In the enemy class, the binary code for each enemy is now randomly generated.  At first, I was getting the same binary code for each enemy, since the Random object was declared as an instance variable for each enemy.  To get random codes for each enemy, I had to make the Random object static so it is shared between all of the instances.

One problem that I need to fix is when the player shoots and moves across the room boundary.  In that case, the projectile isn’t associated to a room, so warps over to the next room.  Additionally, I need to work out the issue with the bock collision when moving across a room boundary, which usually pushes the player back a noticeable amount.

Level Up

Tile Editor Agony

Started using the Tiled tile editor to create levels for the game, because I thought that was the editor I used for Legend of Tux.  I created a simple sprite sheet which contained the tiles on one layer, and the batteries and LEDs on another layer.  I found that I was only able to export my maps in a very limited number of formats.  It’s sad that this tile editor can’t output a simple indexed array of tiles.  I’m really not in the mood to write a parser for any of these formats, so I went back to the Legend of Tux wiki and found that I actually used Mappy last time.  Therefore, I downloaded Mappy and recreated my levels with that tool.

 

Mappyland

Mappy will not load PNG spritesheets unless two DLLs are included, so I had to download those file separately from the Mappy website.  Apparently there is a now bug with the “export all layers” functionality, so each layer has to be exported individually or else you will get an array filled with zeros.  What a pain!  Unfortunately, they don’t provide a binary download for the previous Mappy versions, and it’s not on SourceForge so a previous version isn’t archived for download.  The author even says on the website that 1.4 is a beta, so why can’t the last stable release still be downloaded?

 

Make sure to set the color depth to 16-bit when creating the map, or else the sprite sheet will not load and Mappy will complain.  As shown in the sprite sheet above, batteries start at index 10, and LEDs start at index 20.  I can get the Elex value of the LED or battery by modding (%) by 10, which really isn’t scalable past 10, so this may need to be reworked later.  This sprite sheet is just used for creating the level arrays, so I was sloppy when placing the numbers.  In the actual game, the numbers are programmatically placed on the objects.

I created getter methods in the LevelDefinition class to return the background tile array and object array.  Then I have a method in the GameLevel class which converts the integer arrays to actual objects (GamePieceBattery, GamePieceLight, etc).  Using the Mappy exporter, I was able to acquire the static array data definitions, which I pasted into my LevelDefinition class.  Wrote simple if/else statements to return the correct array for the level, but this could be changed to a switch/case statement (if C Sharp has those… I don’t know, and I didn’t feel like looking it up, since if/else does the job).

Next Level

Added instance variable to the main ResistorGame class to track the current level.  I’ve been trying to keep instance variables out of this class except for the media files.  When the GAMEWIN state is enabled, the current level instance variable is incremented.  If the current level variable is greater than the maximum number of levels (currently hardcoded to 5), then it gets set back to zero.  For the  LevelSelectScreen, the class could return a level index, and the ResistorGame class can use that value to set the current level instance variable.

One problem I’ve noticed is that the cursor defaults to cell 0,0 at the start of each level, which may be off the actual game board, now that the shape of the levels are custom defined.  I may need to add an additional object to the level definition which is the starting position of the cursor.  Additionally, all levels are using the same value thresholds for the ranks, which will need to be fixed later.  The S rank for luminosity should be easy to calculate (the sum of the bust values of all the LEDs).  As for the time and pieces used rank, I’ll probably just play through the levels a few times, and use my best scores for S rank, then use some sort of bell curve function to determine the thresholds for the A, B, and C ranks.

 

Loose Ends (Fix later)

Here’s just a few additional things that need to be fixed.

Currently, there is a display issue if the wires connect to the resistor from the sides.   The wires need to be removed from the resistor sprites, then just simply display a standard wire which will make the proper connections, then display the resistor core on top of it.

I haven’t decided if I should let the player move the cursor off the board cells, and just prevent the user from placing a piece on a non-board space… or should the player only be allowed to move the cursor on game board spaces.  If the player is allowed to move the cursor off of game board spaces,  then the player shouldn’t be allowed to lay pieces on those empty spaces.

I may allow the player to continually lay wires as long as the confirm button is held down, because currently the player has to keep alternating between pressing the direction and the confirm button to lay continuous pieces, which feels jerky.

The LED values can still fall below zero if enough resistors are used.  Need to set the bottom limit to zero for these.

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.