-
Notifications
You must be signed in to change notification settings - Fork 4
Currency
The game uses a currency system to enable the user to buy turrets and get upgrades. The Currency makes use of ServiceLocator to enable global access to the currency, this is done with the CurrencyService. CurrencyService is a service where you can get access to any currency that is implemented:
- Scrap (as of Sprint 1).
- Crystal (as of Sprint 2).
The plan is for general mobs to drop the Scrap currency, while mob bosses drop the Crystal currency.
This is the UML for the work completed by Team 5 in sprint 1. (Some components were not expanded and can be found in other areas of the wiki.)
The main usage of currency would be buying an item, you can do this with the following:
public void buyItem(Item item) {
// Get the scrap from the Service Locator
Scrap scrap = ServiceLocator.getCurrencyService().getScrap();
// Check if you can buy price
if (scrap.canBuy(item.price())) {
// Decreases scrap count by price
scrap.modify(-item.price());
} else {
// Handle case cannot buy item
}
}
where in the above you check if you can buy your item with scrap.canBuy()
and modify the currency with scrap.modify()
.
The current currency within the game can be called anywhere within the game using the following function:
ServiceLocator.getCurrencyService().getScrap()
ServiceLocator.getCurrencyService().getCrystal()
A label, currently placed on the left side of the screen, which shows the amount of currency owned. Can be updated using:
Once currency has been updated, using the modify function or similar, this update stats function should be called to update the UI counter
ServiceLocator.getCurrencyService().getCurrencyDisplay().updateScrapsStats()
ServiceLocator.getCurrencyService().getCurrencyDisplay().updateCrystalsStats()
The design of the currency, formally known as scrap, was sourced from a resource pack (https://beast-pixels.itch.io/crafting-materials).
The design of the currency amount display on the screen was created using a combination of the scrap image and a banner sourced from a resource pack (https://mounirtohami.itch.io/pixel-art-gui-elements)
The design of the mining tower was done using a 35 pixel x 35 pixel guideline for the design of towers
The currency generation towers currently generates half of the scrap value per tower every 10 seconds. This is highly subject to change based on balance and scaling.
The currency generation tower inherits the base tower class and is a Tower with health, and an income generation value (this can be changed using the IncomeTowerConfig file.
The tower calls upon the CurrencyTask which is responsible for the generation:
public void updateCurrency() {
//logger.info("Updating currency");
ServiceLocator.getCurrencyService().getScrap().modify(currencyAmount/2);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats(); // update currency display
}
The above function runs periodically due to the task service running based on time.
@Override
public void update() {
if (timeSource.getTime() >= endTime) {
updateCurrency(); // update currency
endTime = timeSource.getTime() + (interval * 1000L); // reset end time
}
}
Enemies are meant to drop "scrap" entities which can be collected using the click of the cursor at the designated location. They currently add the amount worth of the scrap (100) to the entire scrap.
Currently this is hard-coded such that scraps display on screen initially and are not connected to mobs
This class was implemented by creating a DropFactory which has the DropComponent, then using a touchDown function that was defined in DropInputComponent we can collect the object.
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 worldCoordinates = new Vector3((float) screenX , (float) screenY, 0);
getCamera().unproject(worldCoordinates); // translate from screen to world coordinates
Vector2 cursorPosition = new Vector2(worldCoordinates.x, worldCoordinates.y);
Entity clickedEntity = entityService.getEntityAtPosition(cursorPosition.x, cursorPosition.y);
//logger.info("Clicked entity: " + clickedEntity);
if (clickedEntity != null && clickedEntity.getComponent(DropComponent.class) != null) {
ServiceLocator.getCurrencyService().getScrap()
.modify(clickedEntity.getComponent(DropComponent.class).getValue());
// add the value of the drop to the scrap
EntityService.removeEntity(clickedEntity); // remove the entity from the game
//logger.info("Scrap amount: " + ServiceLocator.getCurrencyService().getScrap().getAmount());
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats(); // update the display
return true;
}
return false;
}
This function converts screen coordinates to map coordinates and checks if the entity at that coordinate is a scrap. If it is, the scrap will be destroyed and currency will be added.