-
Notifications
You must be signed in to change notification settings - Fork 4
Inventory Code (Team 6)
An inventory is a TreeMap of resources mapped to their quantities. Inventories are used in many areas in the game, for example each player has an inventory representing all of the items they are able to collect and have collected in the game. Inventories may be used to also hold the items that a resource tree has available to harvest or an enemy squirrel has to drop when killed.
The inventory class has broad functionality to enable integration with other features. Methods include:
-
getInventoryResources()
- returns the set of resources stored -
addInventoryResource()
- adds a resource to the inventory -
removeInventoryResource()
- removes a resource to the inventory -
getMap()
- returns the mapping of resources stored and the quantity of each -
getQuantity(Resource resource)
- returns the mapped quantity of a given resource -
updateQuantity(Resource resource, int amount)
- adds amount to the current quantity of a given resource and updates the inventory GUI -
updateInventory(Inventory extraItems)
- adds an entire inventory of items to the current inventory -
toString()
- returns a String representation of the inventory
At any time the inventory count is displayed in the top right-hand corner of the screen. This visual representation shows a list of images representing the resources the player has collected and, to the right of each image, the number of resources a player has already collected.
It is obviously vital that the inventory class integrates with the game's resources. A player may collect any resources that they find in the various worlds. Each world has three native resources which can be collected to plant the trees native to that world. As soon as a player first picks up one of these items, it will be added to their inventory.
Items are used to plant trees which will help the player. To plant a tree, a player must click on a surrounding tile and make their tree selection. If they do not have enough resources or they are attempting to plant a tree too far away, they will not be able to make the purchase.
Currently, when gameplay starts the player is initialised with an inventory count of 0 for the three resources in the first world level. This is done using the following code:
/** * Initialises the inventory with all the resources in the game. */ private void addResources() { HashSet<Resource> startingResources = new HashSet<Resource>(); this.inventory = new Inventory(startingResources); }
Havesting resources from trees for example is then done by calling:
otherInventory.updateInventory(this.getInventory());
where otherInventory
is the inventory of the player and this.getInventory()
is the inventory of the tree.
- Home
- How To Play
- Keybindings
- Inventory and Resources
- Trees
- Portals and Worlds
- Projectiles
- Enemies
- Waves & Spawning
- Graphical assets progress overview
- Audio Files
- Design Templates
- Blender Intro
- Converting 3D models to Sprites
- Scripting in Blender
- Creating a Model in Sketchup
- Colouring and Animating in Blender
- Animation using Dope Sheet, Keyframes and Scale Transformation in Blender
- Template
- Testing
- Terrain
- Terrain Generation
- Resource Trees
- Main Menu, Chat, options
- Main Menu V2, Options V2, Sound
- Damage Trees
- Projectiles
- Enemy User Testing
- Tree planting, inventory GUI, resources, portals
- Caveman Character
- Debug Mode Menu
- Tree learning, Attack Trees, Main Menu Tutorial Resources Styling
- Revamped Resource Trees
- Squirrel User Testing
- Final evaluation
- Project Structure
- Git Workflow
- GUI
- Worlds
- Entity Directions
- Resources
- Inventory
- AbstractEntities
- BasicProperties
- MortalEntity
- ProgressBarEntity
- Multiplayer
- Trees
- TimeEvent
- Game Time
- Animations
- Enemies
- Waves
- Player
- Projectiles
- Effect
- Particles
- Path Manager
- Sounds
- Debug 'God' Mode
- 2D Collision
- Box3D {depreciated}
- Render3D
- Cheat Codes