Skip to content

Commit

Permalink
Added the currency pop up to the currency task, and changed it to app…
Browse files Browse the repository at this point in the history
…ear above the entity
  • Loading branch information
nawal-0 committed Sep 10, 2023
1 parent 25a416b commit 46a3c0a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void create() {
// Types of projectile
spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.HUMANS, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.BURN, true);
spawnXenoGrunts();

spawnScrap();
spawnIncome();
spawnGhosts();
spawnWeaponTower();
spawnEngineer();
Expand Down Expand Up @@ -496,7 +497,7 @@ private void spawnIncome() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < 50; i++) {
for (int i = 0; i < 2; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity towerfactory = TowerFactory.createIncomeTower();
spawnEntityAt(towerfactory, randomPos, true, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
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.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
Expand All @@ -15,6 +17,7 @@
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.entities.Entity;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
Expand All @@ -24,6 +27,7 @@
*/
public class CurrencyDisplay extends UIComponent {
Table table;
private Camera camera;
private TextButton scrapsTb;
private TextButton crystalsTb;

Expand Down Expand Up @@ -108,19 +112,29 @@ public void updateCrystalsStats() {
* A label that appears once currency is gained, to give the player visual feedback
* @param x Screen x coordinate
* @param y Screen y coordinate
* @param amount value to display on the pop up
* @param amount value to display on the pop-up
* @param offset value to offset the height of the label by
*/
public void currencyPopUp(float x , float y, int amount) {
public void currencyPopUp(float x , float y, int amount, int offset) {
Label label = new Label(String.format("+%d", amount), skin);
// remove label after it fades out
label.addAction(new SequenceAction(Actions.fadeOut(1.5f), Actions.removeActor()));

Vector3 worldCoordinates = new Vector3(x , y, 0);
stage.getViewport().unproject(worldCoordinates);
label.setPosition(worldCoordinates.x, worldCoordinates.y);
// get stage coordinates from entity coordinates
Vector3 entityCoordinates = new Vector3(x, y, 0);
Vector3 entityScreenCoordinate = this.camera.project(entityCoordinates);
Vector2 stageCoordinates = stage.screenToStageCoordinates(
new Vector2(entityScreenCoordinate.x, entityScreenCoordinate.y));
stage.getViewport().unproject(stageCoordinates);

label.setPosition(stageCoordinates.x - label.getWidth()/2, stageCoordinates.y + offset);
stage.addActor(label);
}

public void setCamera(Camera camera) {
this.camera = camera;
}

@Override
public void dispose() {
super.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.tasks;

import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.currency.Scrap;
Expand Down Expand Up @@ -65,6 +66,10 @@ public void update() {
public void updateCurrency() {
//logger.info("Updating currency");
ServiceLocator.getCurrencyService().getScrap().modify(currencyAmount/2);

Vector2 coordinates = this.owner.getEntity().getCenterPosition();
ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(coordinates.x, coordinates.y, currencyAmount/2, 25);

ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats(); // update currency display

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public static Entity createIncomeTower() {
income
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(new CostComponent(config.cost))
.addComponent(new TextureRenderComponent(RESOURCE_TOWER))
.addComponent(aiTaskComponent);

.addComponent(aiTaskComponent)
.addComponent(animator)
.addComponent(new EconTowerAnimationController());

return income;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
ServiceLocator.getCurrencyService().getDisplay().updateCrystalsStats();
}

float X = clickedEntity.getCenterPosition().x;
float Y = clickedEntity.getCenterPosition().y;

// remove the entity from the game
EntityService.removeEntity(clickedEntity);
// display a visual indication that currency has been picked up
ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(screenX, screenY, value);
ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(X, Y, value, 10);

//logger.info("Scrap amount: " + ServiceLocator.getCurrencyService().getScrap().getAmount());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public MainGameScreen(GdxGame game) {
InputComponent inputHandler = new DropInputComponent(renderer.getCamera().getCamera());
ServiceLocator.getInputService().register(inputHandler);

ServiceLocator.getCurrencyService().getDisplay().setCamera(renderer.getCamera().getCamera());

loadAssets();
createUI();

Expand Down

0 comments on commit 46a3c0a

Please sign in to comment.