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.