Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 5 Economy #67

Merged
merged 47 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
415ee57
Added currency folder for economy-related classes.
ryandmcneilly Aug 16, 2023
5ff59ed
Added methods to the currency class. The currency class can now modif…
ryandmcneilly Aug 16, 2023
f810018
Implemented basis of DropFactory
Hasakev Aug 16, 2023
303190e
Implemented some getters and setters for the Currency class. Currency…
ryandmcneilly Aug 18, 2023
f05c3e8
Merge branch 'Team-5--Economy' of https://github.com/UQcsse3200/2023-…
ryandmcneilly Aug 18, 2023
722a72e
Implemented a subclass of currency called "Scrap" which will be the m…
ryandmcneilly Aug 21, 2023
3ccc705
Implemented the Currency Service, so that other teams can interact wi…
ryandmcneilly Aug 21, 2023
242f172
Base DropComponent and DropFactory implemented.
Hasakev Aug 22, 2023
0c25957
Added CurrencyDisplay.java for displaying the UI Currency Component
nawal-0 Aug 25, 2023
e6c89ed
Initialises and registers the currency service
nawal-0 Aug 26, 2023
9a3e1d0
Modified UI to get currency values from the Currency Service. Also ad…
nawal-0 Aug 26, 2023
c9966dd
Added some testfiles
Hasakev Aug 27, 2023
55300f4
Merge branch 'Team-5--Economy' of https://github.com/UQcsse3200/2023-…
Hasakev Aug 27, 2023
0b2ca00
Changed drop size and removed createScrapDrop() parameters
nawal-0 Aug 27, 2023
e16bdc4
Added scrap.png
nawal-0 Aug 27, 2023
f446827
Began Implementing scrap collection feature
Hasakev Aug 27, 2023
fc7aa24
Added currency folder for economy-related classes.
ryandmcneilly Aug 16, 2023
8fb6f5f
Added methods to the currency class. The currency class can now modif…
ryandmcneilly Aug 16, 2023
47014c8
Implemented some getters and setters for the Currency class. Currency…
ryandmcneilly Aug 18, 2023
0a3a2e8
Implemented basis of DropFactory
Hasakev Aug 16, 2023
e05758e
Implemented a subclass of currency called "Scrap" which will be the m…
ryandmcneilly Aug 21, 2023
5e5626e
Implemented the Currency Service, so that other teams can interact wi…
ryandmcneilly Aug 21, 2023
d03c56d
Base DropComponent and DropFactory implemented.
Hasakev Aug 22, 2023
a313ac5
Added some testfiles
Hasakev Aug 27, 2023
90d80eb
Added CurrencyDisplay.java for displaying the UI Currency Component
nawal-0 Aug 25, 2023
b3f7648
Initialises and registers the currency service
nawal-0 Aug 26, 2023
f563a33
Modified UI to get currency values from the Currency Service. Also ad…
nawal-0 Aug 26, 2023
71ba7b2
Changed drop size and removed createScrapDrop() parameters
nawal-0 Aug 27, 2023
edec7d7
Added scrap.png
nawal-0 Aug 27, 2023
fe20181
Began Implementing scrap collection feature
Hasakev Aug 27, 2023
f33b621
Merge branch 'Team-5--Economy' of https://github.com/UQcsse3200/2023-…
Hasakev Aug 28, 2023
fe5411a
Reimplemented ghost king
nawal-0 Aug 28, 2023
cf6955a
Added currencyDisplay to the CurrencyService for easier access. Creat…
nawal-0 Aug 28, 2023
1f1f79b
Added tests for Currency and CurrencyService classes
nawal-0 Aug 28, 2023
7d11161
Extended TowerFactory with createIncomeTower() method which spawns sc…
fattyhope Aug 28, 2023
dce37de
Added mine tower image and additional test case
nawal-0 Aug 28, 2023
bc1ba22
Implemented Drop Collection
Hasakev Aug 28, 2023
6669c8a
Scrap Collection successfully updates UI.
Hasakev Aug 28, 2023
8ccfd94
Update CurrencyTest.java
Hasakev Aug 29, 2023
c050b2e
Fixed DropComponent to correctly grab scrap value
Hasakev Aug 29, 2023
0d86766
Created class CurrencyTask which updates scrap for IncomeTowers perio…
fattyhope Aug 29, 2023
0b11410
Merge branch 'Team-5--Economy' of https://github.com/UQcsse3200/2023-…
fattyhope Aug 29, 2023
1f277e8
Updated the dummy image to mine tower
fattyhope Aug 29, 2023
d983461
UI correctly updates when income turret generates.
Hasakev Aug 29, 2023
43f4ba3
Merge branch 'main' into Team-5--Economy
Hasakev Aug 29, 2023
a49eaff
Fixed problem merging main to current branch
Hasakev Aug 29, 2023
e6fd894
Removed unneccesary component in walltower (unintentional)
Hasakev Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/core/assets/configs/tower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"health": 20,
"baseAttack": 0,
"cost": 5
},
"income": {
"health": 20,
"baseAttack": 0,
"cost": 1
}
}
Binary file added source/core/assets/images/mine_tower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/scrap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/core/assets/images/scrapsUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 34 additions & 5 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.input.DropInputComponent;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType;
import com.csse3200.game.entities.Entity;
Expand Down Expand Up @@ -80,7 +81,9 @@ public class ForestGameArea extends GameArea {
"images/rangeBossRight.png",
"images/wallTower.png",
"images/building2.png",
"images/iso_grass_3.png"
"images/iso_grass_3.png",
"images/scrap.png",
"images/mine_tower.png"
};
private static final String[] forestTextureAtlases = {
"images/terrain_iso_grass.atlas",
Expand Down Expand Up @@ -132,6 +135,8 @@ public void create() {

spawnGhosts();
spawnWeaponTower();
spawnIncome();
spawnScrap();

bossKing1 = spawnBossKing1();
bossKing2 = spawnBossKing2();
Expand All @@ -146,6 +151,7 @@ public void create() {
private void displayUI() {
Entity ui = new Entity();
ui.addComponent(new GameAreaDisplay("Box Forest"));
ui.addComponent(ServiceLocator.getCurrencyService().getDisplay());
spawnEntity(ui);
}

Expand Down Expand Up @@ -178,7 +184,7 @@ private void spawnTerrain() {
spawnEntityAt(
ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH), GridPoint2Utils.ZERO, false, false);
}
private void spawnBuilding1() {
private void spawnBuilding1() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

Expand Down Expand Up @@ -231,7 +237,7 @@ private void spawnGhosts() {
spawnEntityAt(ghost, randomPos, true, true);
}
}

private Entity spawnBossKing1() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);
Expand All @@ -246,7 +252,7 @@ private Entity spawnBossKing1() {
true,
false);
}
return bossKing1;
return bossKing1;
}

private Entity spawnBossKing2() {
Expand All @@ -264,7 +270,7 @@ private Entity spawnBossKing2() {
false);
}
return bossKing2;
}
}

/**
* Spawns a projectile currently just in the center of the game
Expand Down Expand Up @@ -340,4 +346,27 @@ public void dispose() {
this.unloadAssets();
}

private void spawnScrap() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < 50; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity scrap = DropFactory.createScrapDrop();
spawnEntityAt(scrap, randomPos, true, false);
}
}

private void spawnIncome() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < 5; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity towerfactory = TowerFactory.createIncomeTower();
spawnEntityAt(towerfactory, randomPos, true, true);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;

/**
* A UI component for displaying the currency owned
*/
public class CurrencyDisplay extends UIComponent {
Table table;
private TextButton scrapsTb;

/**
* Adds actors to stage
*/
@Override
public void create() {
super.create();
addActors();
entity.getEvents().addListener("updateCurrency", this::updateScrapsStats);
}

/**
* Initialises the currency label
* Positions it on the stage using a table
*/
private void addActors() {
table = new Table();
table.top().left();
table.setFillParent(true);
table.padTop(50f).padLeft(20f);

// create text button style
Drawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/scrapsUI.png")));
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(
drawable, drawable, drawable, new BitmapFont());

// create scraps button
int value = ServiceLocator.getCurrencyService().getScrap().getAmount();
String text = String.format("%d", value);
scrapsTb = new TextButton(text, textButtonStyle);
scrapsTb.setDisabled(true);
scrapsTb.getLabel().setAlignment(Align.right);
scrapsTb.getLabel().setFontScale(2, 2); // font size
scrapsTb.pad(0, 0, 0, 70);
scrapsTb.setTransform(true);
scrapsTb.setScale(0.5f); // button size

table.add(scrapsTb);
stage.addActor(table);
}

@Override
public void draw(SpriteBatch batch) {
// handled by stage
}

/**
* Updates the currency (Scraps) value on the UI component
*/
public void updateScrapsStats() {
int value = ServiceLocator.getCurrencyService().getScrap().getAmount();
CharSequence text = String.format("%d", value);
scrapsTb.getLabel().setText(text);
}

@Override
public void dispose() {
super.dispose();
scrapsTb.remove();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.csse3200.game.components.npc;
import com.csse3200.game.components.Component;
import com.csse3200.game.currency.Currency;
public class DropComponent extends Component {
private int value = 0;
protected Currency currency;

public DropComponent(Currency currency) {
this.value = currency.getAmount();
this.currency = currency;
}

public int getValue() {
return this.value;
}

public Currency getCurrency() {
return this.currency;
}
@Override
public void dispose() {
this.currency.setAmount(currency.getAmount() + this.value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.csse3200.game.components.tasks;

import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.currency.Scrap;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The CurrencyTask updates the in-game currency based on time intervals.
*/
public class CurrencyTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(CurrencyTask.class);
private final int priority; // The active priority this task will have
private final int INTERVAL = 10; // time interval to update currency in seconds
private final GameTime timeSource;
private long endTime;
private int interval;
private final Scrap scrap = new Scrap(); // currency to update
private final int currencyAmount = scrap.getAmount(); // amount of currency to update

/**
* @param priority Task priority for currency updates. Must be a positive integer.
*/
public CurrencyTask(int priority, int interval) {
this.priority = priority;
this.interval = interval;
this.timeSource = ServiceLocator.getTimeSource();
}


/**
* Starts the Task running and initializes currency-related variables.
*/
@Override
public void start() {
super.start();
endTime = timeSource.getTime() + (INTERVAL * 1000);
}

/**
* The update method is what is run every time the TaskRunner in the AiTaskComponent calls update().
* Updates the currency based on time intervals.
*/

@Override
public void update() {
if (timeSource.getTime() >= endTime) {
updateCurrency(); // update currency
endTime = timeSource.getTime() + (interval * 1000L); // reset end time
}
}


/**
* Updates the currency based on time intervals.
*/
public void updateCurrency() {
//logger.info("Updating currency");
ServiceLocator.getCurrencyService().getScrap().modify(currencyAmount/2);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats(); // update currency display

}

/**
* For stopping the running task
*/
@Override
public void stop() {
super.stop();
}

/**
* Returns the current priority of the task.
* @return active priority value
*/
@Override
public int getPriority() {
return priority;
}

public void setInterval(int interval) {
this.interval = interval;
}
}
75 changes: 75 additions & 0 deletions source/core/src/main/com/csse3200/game/currency/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.csse3200.game.currency;

import com.csse3200.game.entities.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Currency {

private static final Logger logger = LoggerFactory.getLogger(Currency.class);

// The logo of the currency
private final String logoFilePath;

// Stores the amount of currency there is
private int amount;

private final String name;

/**
* Constructor for the currency object.
* @param logoFilePath the file path of the logo
*/
public Currency(String logoFilePath, String name) {
this.logoFilePath = logoFilePath;
this.name = name;
}

public String getName() {
return this.name;
}

public int getAmount() {
return this.amount;
}

public void setAmount(int amount) {
this.amount = amount;
}

/**
* Getter for the logo of the currency.
*
* @return the logo of the currency in a Texture format.
*/
public String getTexture() {
return this.logoFilePath;
}

/**
* This method increments the currency amount by a given amount.
* Added amount is assumed to be larger than negative the currency's amount.
*
* @requires addedAmount >= -this.amount
* @param addedAmount The amount the currency will be incremented by.
*/
public void modify(int addedAmount) {
logger.debug("Modifying " + this.getClass().getSimpleName() + "by " + addedAmount);
this.amount += addedAmount;
}

/**
* Checks if you can buy some item with a given cost.
*
* @param cost the cost of the item.
* @return boolean representing if you can buy that object or not.
*/
public boolean canBuy(int cost) {
return this.getAmount() >= cost;
}

@Override
public String toString() {
return this.getClass().getSimpleName() + ": " + this.getAmount();
}
}
Loading