-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.csse3200.game.input; | ||
|
||
import com.badlogic.gdx.graphics.Camera; | ||
import com.badlogic.gdx.math.Vector2; | ||
import com.badlogic.gdx.math.Vector3; | ||
import com.csse3200.game.areas.ForestGameArea; | ||
import com.csse3200.game.components.tower.TowerUpgraderComponent; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.EntityService; | ||
import com.csse3200.game.services.ServiceLocator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class UpgradeUIComponent extends InputComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class); | ||
private final EntityService entityService; | ||
private final Camera camera; | ||
int value; | ||
|
||
/** | ||
* Constructor for the UpgradeUIComponent | ||
* @param camera the camera to be used, this is the camera that the game is rendered with | ||
*/ | ||
public UpgradeUIComponent(Camera camera) { | ||
this.value = ServiceLocator.getCurrencyService().getScrap().getAmount(); | ||
this.entityService = ServiceLocator.getEntityService(); | ||
this.camera = camera; | ||
} | ||
|
||
/** | ||
* Getter for the camera | ||
* @return the camera | ||
*/ | ||
public Camera getCamera() { | ||
return camera; | ||
} | ||
|
||
/** | ||
* When the mouse is clicked, this method is called. | ||
* | ||
* @param screenX The x coordinate, origin is in the upper left corner | ||
* @param screenY The y coordinate, origin is in the upper left corner | ||
* @param pointer the pointer for the event. | ||
* @param button the button | ||
* @return | ||
*/ | ||
@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); | ||
|
||
if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null) { | ||
logger.info("clicked a turret that is upgradable!"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters