Skip to content

Commit

Permalink
Added some important comments to files
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Oct 3, 2023
1 parent 4b582f6 commit a49a4fa
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,33 @@ public Camera getCamera() {
return camera;
}

/**
* Getter for the stage
* @return the stage
*/
public Stage getStage() {
return stage;
}

/**
* Method to handle the touch down event
* @param screenX the x coordinate of the touch
* @param screenY the y coordinate of the touch
* @param pointer the pointer
* @param button the button
*/
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 worldCoordinates = new Vector3((float) screenX, (float) screenY, 0);
getCamera().unproject(worldCoordinates);
Vector2 cursorPosition = new Vector2(worldCoordinates.x, worldCoordinates.y);
Entity clickedEntity = entityService.getEntityAtPosition(cursorPosition.x, cursorPosition.y);

if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null && clickedEntity.getComponent(TNTDamageComponent.class) == null) {
// // Clear all existing upgrade tables
// If the clicked position contains a turret, and the turret is upgradable and not a TNT tower
if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null
&& clickedEntity.getComponent(TNTDamageComponent.class) == null) {
// TNT TowerUpgraderComponent can be removed later, but possibly useful for future sprint.
// Clear all existing upgrade tables
logger.info("clickedEntity: " + clickedEntity);
clearUpgradeTables();
// Check if there is an existing upgrade table for this turret entity
Expand Down Expand Up @@ -112,28 +126,43 @@ private void clearUpgradeTables() {
upgradeTables.clear();
}

/**
* Creates the upgrade table for the associated turret entity
* <p>
* Each button has a listener that will upgrade the turret entity when clicked
* if the player has enough scrap. Additionally when the player hovers over a button
* the cost of the upgrade will be displayed in the cost display
* </p>
*
* Currently, the cost of each upgrade is hardcoded to 10 scrap, this can be changed to global
* variables to make balancing easier (contact @Hasakev (Kevin) if confused)
*
* @param turretEntity the turret entity to create the upgrade table for (the entity that was clicked)
* @return the upgrade table for the turret entity
*/
private Table createUpgradeTable(Entity turretEntity) {
// This is the overarching table that contains the close button, the inner table, and the cost display
Table upgradeTable = new Table();
upgradeTable.top();
upgradeTable.defaults().pad(0).space(0);
upgradeTable.setSize(60, 60);

// The inner table contains the upgrade buttons and the stats display
Table innerUpgradeTable = new Table();
innerUpgradeTable.top();
innerUpgradeTable.defaults().pad(10).space(0).padBottom(1);
innerUpgradeTable.setSize(60, 60);
// set table background
String imageFilePath = "images/ui/Sprites/UI_Glass_Frame_Standard_01a.png";
String upgradeButtonFilePath = "images/economy/scrapBanner.png";
Drawable drawableBackground = new TextureRegionDrawable(new TextureRegion(new Texture(imageFilePath)));
innerUpgradeTable.setBackground(drawableBackground);

// Stying for all the buttons
Drawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Small_Lock_01a2.png")));
Drawable econDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(upgradeButtonFilePath)));
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(
drawable, drawable, drawable, new BitmapFont());
TextButton.TextButtonStyle econStyle = new TextButton.TextButtonStyle(
econDrawable, econDrawable, econDrawable, new BitmapFont());
// create button

// Default values for the stats
int maxHealth = turretEntity.getComponent(CombatStatsComponent.class).getMaxHealth();
int currentHealth = turretEntity.getComponent(CombatStatsComponent.class).getHealth();
turretEntity.getComponent(CombatStatsComponent.class).setHealth(5); // for testing
Expand Down Expand Up @@ -173,9 +202,12 @@ public void clicked(InputEvent event, float x, float y) {
Drawable fireRateDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/hourglass.png")));
Image fireRateImage = new Image(fireRateDrawable);


Drawable healthStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/heart_upgrade.png")));
ImageButton upgradeHealth = new ImageButton(healthStyle);

//// UPGRADE BUTTONS ////

// Health upgrade button
upgradeHealth.setScale(0.8f);
upgradeHealth.addListener(new ClickListener() {
@Override
Expand Down Expand Up @@ -204,6 +236,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
}
});

// Attack upgrade button
Drawable attackStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/damage_upgrade.png")));
ImageButton upgradeAttack = new ImageButton(attackStyle);
upgradeAttack.addListener(new ClickListener() {
Expand Down Expand Up @@ -232,7 +265,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
});



// Fire rate upgrade button
Drawable asStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/hourglass_upgrade.png")));
ImageButton upgradeFireRate = new ImageButton(asStyle);
upgradeFireRate.addListener(new ClickListener() {
Expand Down Expand Up @@ -265,6 +298,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
}
});

// Repair button
Drawable repair = new TextureRegionDrawable(new TextureRegion(new Texture("images/hammer.png")));
ImageButton repairButton = new ImageButton(repair);
repairButton.addListener(new ClickListener() {
Expand Down Expand Up @@ -299,7 +333,10 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
innerUpgradeTable.add(healthLabel).expandX().left();
innerUpgradeTable.row();
TextButton upgradeIncome = null;
// if the turret has an income upgrade component, add the income upgrade button
if (turretEntity.getComponent(IncomeUpgradeComponent.class) != null) {

// Income label and upgrade button
Drawable incomeDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/economy/scrap.png")));
Image incomeImage = new Image(incomeDrawable);
Label incomeLabel = new Label(String.format("%.2f", turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate()), createLabelStyle());
Expand Down Expand Up @@ -365,6 +402,10 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
return upgradeTable;
}

/**
* Creates a label style for the upgrade table
* @return the label style
*/
private LabelStyle createLabelStyle() {
LabelStyle style = new LabelStyle();
style.font = new BitmapFont();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class TurretSelectionScreen extends ScreenAdapter {

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

/**
* Constructor for the TurretSelectionScreen
* @param game The game object
*/
public TurretSelectionScreen(GdxGame game) {
this.game = game;
stage = new Stage(new ScreenViewport());
Expand Down Expand Up @@ -219,10 +223,23 @@ public void render(float delta) {
stage.draw(); // Draw the stage
}

/**
* Returns the list of selected turrets
* @return The list of selected turrets
*/
public List<TowerType> getTurretList() {
return turretList;
}

/**
* Creates a button with the specified images and text
* @param defaultImageFilePath The file path to the default image
* @param alternateImageFilePath The file path to the alternate image
* @param cost The cost of the turret
* @param towerName The name of the turret
* @param turretDesc The description of the turret
* @return The created button
*/
private TextButton createButton(String defaultImageFilePath, String alternateImageFilePath, String cost,
String towerName, String turretDesc) {
Drawable defaultDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(defaultImageFilePath)));
Expand Down Expand Up @@ -280,14 +297,23 @@ public void exit(InputEvent event, float x, float y, int pointer, com.badlogic.g
return tb;
}

/**
* Updates the description label
*/
private void updateDescriptionLabel() {
descriptionLabel.setText("Description: " + turretDescription);
}

/**
* Updates the description text
*/
private void updateDescriptionText() {
descText.setText(turretDescriptionText);
}

/**
* Disposes of the stage
*/
@Override
public void dispose() {
stage.dispose();
Expand Down

0 comments on commit a49a4fa

Please sign in to comment.