Equipment Menu

screen066

In the player class, I added instance variables to hold the equipped helmet, chest piece, gloves, and boots.  These start out as null, but I added logic to automatically equip one of those items if the equipment slot for it is null when an item for that slot is collected.  I also decided to go ahead and make separate lists for each item type, which will make looping those those lists much easier for the menu.  The collection code was updated to handle these items in the same way that weapons are collected, which adds each piece of armor to the appropriate list.  A method to calculate the total defense was also added, which is the sum of the defense values for each armor equipped.

I recreated almost all of the equipment menu, so that it now handles armor.  Now, the player must select the weapon or armor to replace it.  When selecting a piece of equipment, it will display a selectable list with all of the items that can replace it.

The Weapon and Armor classes were updated to accept a new parameter in the constructor, which is the number of socket slots for each item.  The player will not be able to equip more sockets than this value.  Unfortunately, since the socket for each item is implemented as List, I can only add the socket to the end of the list.  This means that it works in a stack fashion.  I believe I can insert an item into a list at a specific index, but I can’t insert null into the list.  Null signifies that a socket location is empty.  Alternatively, I could implement the Socket list as an array, but that will limit the maximum number of socketable abilities.  Pressing the action (X) button will bring up the list of socket abilities that can be equipped for the currently selected item.  For now, any socket can be equipped into any item.  I already have constants defined for the body location of each socket ability, so I will just need to modify the code to only display the sockets for the selected body location.  All acquired socket abilities are currently stored in one list, but I may want to make separate lists of sockets for each body location to make generating the menus simpler.

I have updated the ResistorKit menu to accept a texture image as part of a menu item.  Unfortunately, I didn’t have any way to access the texture array from the method where the equipment menu is created.

screen067

The player’s current attack and defense values are displayed below the character model.  When equipping an item, if the new value is greater than the current value, then the text is displayed in blue.  If the new value is lower, then the text is red.  If the value is the same, then the text is white.  Currently, all collected items for the selected slot are displayed, so the player’s equipped item for that slot is also displayed in the list.  Removing the currently equipped item would be a slight improvement for later, but will probably be a headache to keep the menu indexes straight since it is currently parallel with the list of acquired items for that body slot.  Alternatively, I could just remove the equipped item from the acquired list whenever it is equipped, which is probably the simplest solution.

screen068

Gun Model

screen063

Created a gun model in Blender.  The gun was created using three cubes, which have three different textures.  I deleted half of the cube vertices to make a plane, and I moved the remaining vertices to trace around the gun image that I added as the background image.  Additional vertices were added to the plane by selecting two vertices and pressing “W”.  That will subdivide the line, adding a new vertex.  After I had the outline, I extruded the points out in the y direction to give the model depth.  Since this will be used for a small image, I wasn’t concerned with making the depth very detailed.  It just needed to be simple enough to make the gun not appear to be flat like a piece of paper.  For now, the textures are just using different diffuse coloring, which are dark green, light green, and white for the trigger.  I would like to make it so that I can programmtically change these colors to make different weapons, without generating new weapon sprites.  Just like with the player and socket sprites, I added an armature.  In this case, the armature looks like a “T”.  I turned on automatic keyframing (red record button), set the frames to 20, and rotated the model 90 degrees for each 5 frames.  Then I exported the animation to image files, cropped and shrunk those images with Gimp and exported those into new PNG images.  Finally, I added the images as content objects in the Blasting Bits project.  I updated the code to display a CollectibleWeapon to use these image textures instead of the default image.  As with the socket images, I had to set the maximum number of frames to 20, since the default is 30 frames.

screen064

When I tried running the game, the gun sprites would display and rotate, but it seemed to rotate extremely quickly.  Therefore, I updated the Collectible class with two new instance variables which add a frame delay and maximum frame delay.  The frame delay is private, and gets decremented on each update.  When the frame delay reaches zero, then the animation frame is incremented and the frame delay is set to the maximum frame delay.  The maximum frame delay variable is protected, since subclasses will need to set the delay value for its collectible type.  For the CollectibleWeapon, I set the maximum frame dealy to 2, so that there are two frames of delay before the next image is displayed.  This makes the gun rotate much more slowly and looks better.

screen065

Movement Acceleration

Modified the player class, so that now whenever the player moves an acceleration value is added to the player’s velocity.  Previously, I just set the velocity to a constant (8 pixels per frame).  That gave the effect of the player abruptly starting and stopping.  By adding the acceleration value, the player now more smoothly starts and stops.

Unfortunately, this caused the player to start getting stuck in blocks again.  This did not become apparent until velocities with decimals (fractions) were being used.  This was due to the player not being offset when colliding with a block.  Therefore, I added a Vector2 ref parameter to the checkCollision method, which gets set to the number of pixels that the player should get set forward when colliding with the block to align with the block.  If the player is moving right, this will be the block location minus the player location and width.  The calculations are the same for moving left, except the block width is added and player’s width is not used.  This could have been easily fixed by just using whole numbers for acceleration, but I wanted to go ahead and do this the right way because I may want to use factions for acceleration to give an ice floor sliding effect.

 

screen062

I also noticed a problem when trying to socket an ability into a weapon that does not exist.  I added some additional bounds and null checking to resolve this error.

Below is the list of remaining changes I plan to implement in the near future.

  • Make a max speed socket
  • Limit number of shots at a time based on weapon
  • Get defense items working; Additional updates to equipment screen
  • Fix light gradient for dark rooms
  • Create model for weapon
  • Buy items with money
  • Level editor
  • Add rooms above/below, vertical scrolling