diff --git a/core/src/com/mygdx/game/Board.java b/core/src/com/mygdx/game/Board.java index ba45fd33811b9b20fd51c75379e4225279556154..44b2de6ef8c9b48e1454f6ae7a3c88fc803e4566 100644 --- a/core/src/com/mygdx/game/Board.java +++ b/core/src/com/mygdx/game/Board.java @@ -1,14 +1,12 @@ package com.mygdx.game; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.Family; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputAdapter; 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; @@ -20,12 +18,12 @@ 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; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.Array; -import com.mygdx.game.components.HeroComponent; import com.mygdx.game.entities.DisplayHero; import com.mygdx.game.entities.HeroFactory; import com.mygdx.game.types.HeroType; @@ -48,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,17 +67,19 @@ public class Board extends Actor { private Array<DisplayHeroButton> displayHeroButtons; private boolean placeHero = false; - private HeroType chosenHeroType; private InputMultiplexer multiplexer; private int gridWidth, gridHeight, startX, startY; private boolean gridDrawn; - private boolean isInputProcessorAdded; - private Engine engine; + private Texture counterIcon; + private int counterValue; + + private MoneySystem moneySystem = new MoneySystem(8000); + - public Board(int rows, int cols, Engine engine) { - this.engine = engine; + public Board(int rows, int cols) { + this.rows = rows; this.cols = cols; gridWidth = cols * cellWidth; @@ -88,7 +87,7 @@ public class Board extends Actor { startX = (screenWidth - gridWidth) / 2; startY = (screenHeight - gridHeight) / 2; gridDrawn = false; - isInputProcessorAdded = false; + boolean isInputProcessorAdded = false; cellWidth = Gdx.graphics.getWidth() / (rows + 6); cellHeight = Gdx.graphics.getHeight() / (rows ); @@ -111,6 +110,23 @@ 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); + counterIcon = new Texture("coin.png"); + + 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; } @@ -146,10 +162,7 @@ public class Board extends Actor { drawLaneDividers(); drawPaneBackgrounds(); loadDisplayTextures(); - if (!isInputProcessorAdded) { - setupInputProcessor(); - isInputProcessorAdded = true; - } + setupInputProcessor(); //createRightTable(); //drawDisplayPanel(batch); @@ -161,6 +174,8 @@ public class Board extends Actor { drawDisplayHeroButtons(); this.stage.act(); this.stage.draw(); + drawCounter(); + } @@ -184,16 +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); - int displayPanelWidth = Gdx.graphics.getWidth() / 8; - int middleOfCellX = (int) (((col + 0.5) * cellWidth)) + displayPanelWidth ; - int middleOfCellY = (int) ((row + 0.5) * cellHeight); - - System.out.print(" x: " + middleOfCellX + " y: " + middleOfCellY); - Vector2 heroPlacement = new Vector2(middleOfCellX, middleOfCellY); - //Creates new hero entity and sets its position to the middle of the clicked cell - getChosenHeroType(); - placeHero(heroPlacement); + moneySystem.removeMoney(450); } @@ -226,11 +236,10 @@ public class Board extends Actor { shapeRenderer.end(); if (!gridDrawn) { gridDrawn = true; - //setGridInputAdapter(); + setGridInputAdapter(); } } - private void setGridInputAdapter() { // add click listener to each cell multiplexer.addProcessor(new InputAdapter() { @@ -261,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) { @@ -286,39 +301,30 @@ 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; this.placeHero = !this.placeHero; } - public HeroType getChosenHeroType() { - return chosenHeroType; - } + private void placeHero() { - private void placeHero(Vector2 placementPosition) { - if (chosenHeroType != null) { - Entity hero = HeroFactory.createHero(getChosenHeroType(), placementPosition); - engine.addEntity(hero); - System.out.println("Created new hero entity and added to game engine"); - System.out.println("all heroes: :)"); - for (Entity e : engine.getEntitiesFor(Family.all(HeroComponent.class).get())) { - System.out.println(e.getComponent(HeroComponent.class).getHeroType()); - } - } } private Texture createWhiteCircle(float circleRadius) { @@ -340,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(); } diff --git a/core/src/com/mygdx/game/states/PlayState.java b/core/src/com/mygdx/game/states/PlayState.java index beb617e19f29ce01f6caa1244418993c8a6b9139..76aee024eca74ab2d99ed345bbdd63e6bdedad78 100644 --- a/core/src/com/mygdx/game/states/PlayState.java +++ b/core/src/com/mygdx/game/states/PlayState.java @@ -44,19 +44,21 @@ public class PlayState extends State{ private Board board; private TextButton counterText1; + + public PlayState() { //super(gsm); initialize(); } private void initialize() { - initializeGameEngine(); batch = new SpriteBatch(); moneySystem = new MoneySystem(4000); initFontStageAndRenderer(); createBoard(); soundManager.playSequence(); //Game engine & systems + //initializeGameEngine(); } private void initializeGameEngine() { @@ -70,10 +72,10 @@ public class PlayState extends State{ engine.addSystem(heroSystem); engine.addSystem(projectileMovementSystem); - /*Entity spiderman = HeroFactory.createHero(HeroType.SPIDERMAN, new Vector2(50, 50)); + Entity spiderman = HeroFactory.createHero(HeroType.SPIDERMAN, new Vector2(50, 50)); Entity captain = HeroFactory.createHero(HeroType.CAPTAIN_AMERICA, new Vector2(50, 50)); engine.addEntity(spiderman); - engine.addEntity(captain);*/ + engine.addEntity(captain); } private void initFontStageAndRenderer() { @@ -84,14 +86,14 @@ public class PlayState extends State{ } private void createBoard() { - board = new Board(6,9, engine); + board = new Board(6,9); board.render(batch); } @Override public void update(float dt) { stage.draw(); - engine.update(dt); + //engine.update(dt); } public void calculateMoney() { diff --git a/core/src/com/mygdx/game/states/StartState.java b/core/src/com/mygdx/game/states/StartState.java index 6a24ab9d150a17b21d3e0303d174741796662ca7..2f51bf75cca74d288ac9d0da1562593dc14ec687 100644 --- a/core/src/com/mygdx/game/states/StartState.java +++ b/core/src/com/mygdx/game/states/StartState.java @@ -18,7 +18,7 @@ public class StartState extends State implements InputProcessor { public void initialize() { batch = new SpriteBatch(); - //board = new Board(6, 9, engine); + board = new Board(6, 9); Texture texture = new Texture("characterIcon1.png"); Texture texture1 = new Texture("characterIcon2.png"); diff --git a/core/src/com/mygdx/game/systems/ProjectileMovementSystem.java b/core/src/com/mygdx/game/systems/ProjectileMovementSystem.java index 72116a940191f66351193ae33c153f99aa9a1cd6..c503f779f231ce9cab591f4fbfe50f85739d3443 100644 --- a/core/src/com/mygdx/game/systems/ProjectileMovementSystem.java +++ b/core/src/com/mygdx/game/systems/ProjectileMovementSystem.java @@ -5,7 +5,6 @@ import com.badlogic.ashley.core.Engine; import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Family; import com.badlogic.ashley.systems.IteratingSystem; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.mygdx.game.components.CollisionComponent; import com.mygdx.game.components.PositionComponent; @@ -34,7 +33,7 @@ public class ProjectileMovementSystem extends IteratingSystem { PositionComponent positionComponent = positionMapper.get(entity); //If a projectile is out of bounds, remove it from the engine - if (positionComponent.getPosition().x > Gdx.graphics.getWidth()) { + if (positionComponent.getPosition().x > 500) { engine.removeEntity(entity); System.out.println("Projectile out of bounds. Removed projectile."); } diff --git a/core/src/com/mygdx/game/utils/DisplayHeroButton.java b/core/src/com/mygdx/game/utils/DisplayHeroButton.java index 9aeaeeb9e566296cc9a5fbad2d372d1776ec2958..8799d70296e15d98aaf16fd38106792d7591fac6 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() {