From 048d51773c39476a908619b32146eb969335a65c Mon Sep 17 00:00:00 2001 From: sindrimt <sindrimt@gmail.com> Date: Fri, 21 Apr 2023 14:11:43 +0200 Subject: [PATCH 1/2] Added money system TO Board class --- core/src/com/mygdx/game/Board.java | 81 ++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/core/src/com/mygdx/game/Board.java b/core/src/com/mygdx/game/Board.java index 924835a..402d7d3 100644 --- a/core/src/com/mygdx/game/Board.java +++ b/core/src/com/mygdx/game/Board.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; 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.graphics.glutils.ShapeRenderer; @@ -17,6 +18,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; 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.ClickListener; @@ -44,10 +46,9 @@ public class Board extends Actor { private int cellHeight; private SpriteBatch batch; - private int xOffset = 315; // Add xOffset for moving textures right + private int xOffset = 225; // Add xOffset for moving textures right (previously 315) + private int dashOffset = 225; // Add dashOffset for moving dashed lines right (previously 315) private int yOffset = 0; // Add yOffset for moving textures up or down - private int dashOffset = 315; // Add dashOffset for moving dashed lines right - private Texture[] buttonTextures; private Texture[] displayTextures; private int displayTexturesCount = 5; @@ -70,6 +71,11 @@ public class Board extends Actor { private InputMultiplexer multiplexer; private int gridWidth, gridHeight, startX, startY; private boolean gridDrawn; + private Texture counterIcon; + private int counterValue; + + private MoneySystem moneySystem = new MoneySystem(8000); + public Board(int rows, int cols) { @@ -81,6 +87,8 @@ public class Board extends Actor { startX = (screenWidth - gridWidth) / 2; startY = (screenHeight - gridHeight) / 2; gridDrawn = false; + counterIcon = new Texture("coin.png"); + cellWidth = Gdx.graphics.getWidth() / (rows + 6); cellHeight = Gdx.graphics.getHeight() / (rows ); @@ -103,6 +111,22 @@ public class Board extends Actor { Gdx.input.setInputProcessor(multiplexer); } + private void drawCounter() { + float iconSize = Gdx.graphics.getHeight() / 15; + float iconX = screenWidth - iconSize * 2 - 160; // Move 200 pixels to the left + float iconY = screenHeight - iconSize - 50; + + BitmapFont font = new BitmapFont(); + font.getData().setScale(3.5f); + font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); + + this.batch.begin(); + font.draw(batch, String.valueOf(moneySystem.getMoney()), iconX + iconSize * 1.5f, iconY + iconSize * 0.75f); + + batch.draw(counterIcon, iconX, iconY, iconSize, iconSize); + this.batch.end(); + } + public int getRows() { return rows; } @@ -150,6 +174,8 @@ public class Board extends Actor { drawDisplayHeroButtons(); this.stage.act(); this.stage.draw(); + drawCounter(); + } @@ -173,9 +199,11 @@ public class Board extends Actor { } protected void onCellClicked(int row, int col) { // Add your logic here for when a cell is clicked + Texture texture = new Texture("characterIcon5.png"); setTexture(row, col, texture); System.out.println("Cell clicked: row " + row + ", col " + col); + moneySystem.removeMoney(450); } @@ -242,24 +270,30 @@ public class Board extends Actor { public void drawDisplayHeroButtons() { float circleRadius = Gdx.graphics.getHeight() / 15; - int diameter = (int) (circleRadius * 2); + int diameter = (int) ((circleRadius * 2) + 5); Texture circleTexture = createWhiteCircle(circleRadius); + BitmapFont font = new BitmapFont(); // Create a BitmapFont instance + font.getData().setScale(2); // Increase the font size + Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); // Set the font and color (white) for the label style + + for (final DisplayHeroButton button : displayHeroButtons) { - //Group for the DisplayHero-button Group buttonGroup = new Group(); - //Button background + // Group for the DisplayHero-button + + // Button background Image circle = new Image(circleTexture); circle.setPosition(button.getPosition().x - button.getPosition().x / 2, button.getPosition().y); circle.setSize(diameter, diameter); buttonGroup.addActor(circle); - //Button with hero-texture + // Button with hero-texture final Button buttonClickable = new Button(new TextureRegionDrawable(new TextureRegion(button.getTexture()))); buttonClickable.setPosition(button.getPosition().x, button.getPosition().y); - buttonClickable.setSize(button.getWidth(), button.getHeight()); + buttonClickable.setSize(button.getWidth() - 30, button.getHeight() - 40); - //Event listener + // Event listener buttonClickable.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { @@ -267,19 +301,22 @@ public class Board extends Actor { setChosenHeroType(button.getHeroType()); } }); + buttonGroup.addActor(buttonClickable); - stage.addActor(buttonGroup); - } - } - /* Tegner heroesene og den hvite sirkelen bak. - for (DisplayHeroButton button : displayHeroButtons) { - //draw circles - batch.draw(circle, button.getPosition().x, button.getPosition().y, diameter, diameter); - //draw display hero - batch.draw(button.getTexture(), button.getPosition().x, button.getPosition().y, button.getWidth(), button.getHeight()); + // Create the label for the button number + Label buttonNumber = new Label(Integer.toString(button.getPrice()), labelStyle); + + // Adjust the label's position to be centered horizontally and vertically below the button + float labelX = button.getPosition().x + (button.getWidth() / 2) - (buttonNumber.getWidth() / 2); + float labelY = button.getPosition().y - (buttonNumber.getHeight() * 1.5f); + buttonNumber.setPosition(labelX, labelY); + + buttonGroup.addActor(buttonNumber); // Add the label to the buttonGroup + stage.addActor(buttonGroup); // Add the buttonGroup to the stage + } - */ + } private void setChosenHeroType(HeroType heroType) { this.chosenHeroType = heroType; @@ -309,9 +346,11 @@ public class Board extends Actor { shapeRenderer.setColor(leftRightPaneColor); shapeRenderer.rect(0, 0, Gdx.graphics.getWidth() / 8, Gdx.graphics.getHeight()); - // Draw right pane background + // Draw right pane background with increased padding + float padding = 80; + float rightPaneWidth = Gdx.graphics.getWidth() / 8; shapeRenderer.setColor(leftRightPaneColor); - shapeRenderer.rect(Gdx.graphics.getWidth() * 7 / 8, 0, Gdx.graphics.getWidth() / 8, Gdx.graphics.getHeight()); + shapeRenderer.rect(Gdx.graphics.getWidth() - rightPaneWidth - padding, 0, rightPaneWidth + padding, Gdx.graphics.getHeight()); shapeRenderer.end(); } -- GitLab From 3d8dace8feff19decd9ad4ea0da307b2792856d2 Mon Sep 17 00:00:00 2001 From: sindrimt <sindrimt@gmail.com> Date: Fri, 21 Apr 2023 14:11:57 +0200 Subject: [PATCH 2/2] Added price field to DisplayHeroButton --- core/src/com/mygdx/game/utils/DisplayHeroButton.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/com/mygdx/game/utils/DisplayHeroButton.java b/core/src/com/mygdx/game/utils/DisplayHeroButton.java index 9aeaeeb..8799d70 100644 --- a/core/src/com/mygdx/game/utils/DisplayHeroButton.java +++ b/core/src/com/mygdx/game/utils/DisplayHeroButton.java @@ -12,6 +12,17 @@ public class DisplayHeroButton { float height; Texture texture; HeroType heroType; + int price; + + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + public float getWidth() { return width; @@ -43,6 +54,7 @@ public class DisplayHeroButton { this.heroType = displayHero.getHeroComponent().getHeroType(); this.height = displayHero.getSpriteComponent().getSprite().getHeight() * 4; this.width = displayHero.getSpriteComponent().getSprite().getWidth() * 4; + this.price = displayHero.getPriceComponent().getPrice(); } public Vector2 getPosition() { -- GitLab