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

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.