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

Sliding Socket

Updated ResistorKit to detect LT and RT presses.  These triggers are different than other buttons, because they return a value representing how far the trigger is pulled, instead of an pressed/not pressed value like the other buttons.  It functions similarly to one axis of the thumbstick, by returning a float between 0.0 and 1.0.  Methods for trigger pressed and trigger released for both triggers were added to the RessitorKit screen class.  Therefore, I had to update all of the classes in the game to implement those four methods.  I also added a property in the ResistorKit menu to draw the text with a small drop shadow.

With the LT and RT now implemented, I was able to update the gun shoot code to allow the player to aim up and aim down.  When aiming up, the player will shoot their gun at a 45 degree angle upward in the direction that they are facing.  The same goes for aiming down, except that they are shooting at a 45 degree angle downward.  Holding both LT and RT will cause the player to shoot directly upward.  One issue that I’ve noticed is that if the player is standing next to a block  on the right and shoots upward, then the projectile will immediately collide with the block.  So to fix this I moved the starting position of the projectile to the center of the player horizontally.  Now shooting upward will not collide with blocks to the left or right.

For the Health sockets, I noticed that it was only using the lowest equipped health socket.    This is because the lowest health socket was being checked first in the if/else/elseif statement.  I reversed the order of the health socket check so now it looks for the highest socket first.  This also prevents stacking of the health sockets, but stacking could be implemented by keeping a counter of the sum of the values of the health sockets.  Ideally, there will be a  warning message that will prevent the player from equipping more than one health socket.  It would warn the player that any other health socket will be removed if a health socket is already equipped.

screen061

Added new sockets to the game, which are the sliding sockets.  The player can no longer slide by default, so they now have to equip one of the sliding sockets to get into areas only one block high.  The higher level sliding sockets will allow the player to slide longer.  There may be obstacles such as overhead spikes which will require the player to slide longer to pass.  The text next to the “A” display has also been update to not display if the player can not slide.

Noticed a few issues with some of the sockets.  The level 3 fire socket didn’t work properly, which was due to an incorrect socket ID used in the shoot gun code.  The radiant plus 4 socket didn’t work, because I had not added that level yet.  Also, the weapon list would not populate the first the the player goes to the equipment menu.  This is because the setPlayer method was being set after the activeScreen method is called on the Equipment screen.  Moving the setPlayer before fixed this problem, which ensures that the EquipmentScreen has a reference to the Player to access the Player’s weapons.

 

Socketable Weapons

Today, I created a new model in Blender which will represent a collectible socket.  The model is basically a sphere with objects rotating around it.  The rotating objects were created with a circle, which was extruded out.  Then the edges for every other segment were removed.  Then I added four bones that point outwards from the center.  Next, I set the animation to 20 frames, and I rotated the armature half way at the end of the animation.  Since the model is symmetrical, I didn’t need to do a full 360 degree rotation.  Like the other models, I exported the animation frames and then used Gimp to touch up the images.

43 

Similar to the Weapon and Armor collectibles, I created a CollectableSocket class.  Also in the same way, I added a List of sockets that the player has collected in the Player class.  I added all of the Sockets to the EquipmentCatalog, and added methods for returning a socket and generating a random socket.  On the equipment screen, I now display the list of all sockets the player has collected.

I realized that my existing collectibles had 30 frames in the animation.  This value was set as a constant in my collectible class, so I removed the const declaration and changed the variable to protected.  In the constructor of the CollectibleSocket class, I set the number of frames in the animation to 20.  This was a fairly simplistic change, which would had been much more painful if I hadn’t used good object oriented programming style.

screen058 

The Armor and Weapon classes have been updated to include a List of Sockets and an integer which represents the maximum number of sockets for that item.  To equip a socket, for now I have made it so that pressing the action button (X) will set a boolean to go into select socket mode.  This may need to be extracted into another screen later.  This sets the select socket menu to active.  Pressing the confirm button while in select socket mode will add the selected socket to the socket list of the currently selected weapon.  Currently, no checking is done to determine if the socket is of the right type (body location or gun).

When in socket selection mode, pressing the confirm (A) button will add the socket at the index of the socket menu to the player’s weapon at the index of the weapon menu.  Again as with the weapon menu, I am assuming that the socket menu is aligned with the player’s acquired sockets.  I went ahead and added another property to the Socket class, which is a code string.  This code will used when displaying the socket on a weapon or armor, since printing the name for each socket on the weapon would take up too much space.  For now, I am just listing the socket codes to the right of each weapon, or “X” if the socket location is empty.  Pressing the cancel button (B) will switch the sockect selection flag back to false, otherwise the player will always be in socket selection mode.

screen060

In the player class, I wrote a method that returns if a socket is active.  It takes a socket ID as a parameter, and returns true if it is equipped on a weapon.  In the near future, I will expand this to armor as well.  I also updated all of the code in the Player class which checks for sockets in the EquppedSocket class to use the socket active method.  Now the EquippedSocket class is obsolete, so I went ahead and removed it from the game.

One additional change is that I changed the initial amount of health the player receives to 60 points, which is the same as three bars.  I found that the original amount was way too much, so lowering it should make the game more of a challenge.