diff --git a/core/src/com/wordbattle/game/controller/FinalLeaderBoardController.java b/core/src/com/wordbattle/game/controller/FinalLeaderBoardController.java new file mode 100644 index 0000000000000000000000000000000000000000..f69703556abf6a2dc390667c95a441493285d16e --- /dev/null +++ b/core/src/com/wordbattle/game/controller/FinalLeaderBoardController.java @@ -0,0 +1,85 @@ +package com.wordbattle.game.controller; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; +import com.wordbattle.game.WordBattle; +import com.wordbattle.game.states.CreateGameState; +import com.wordbattle.game.states.FinalLeaderboardState; +import com.wordbattle.game.view.FinalLeaderBoardView; + +public class FinalLeaderBoardController { + + private FinalLeaderboardState state; + + private FinalLeaderBoardView finalLeaderBoardView; + + private int lenLeaderBordPage; + + + + public FinalLeaderBoardController(FinalLeaderboardState state) { + this.state=state; + finalLeaderBoardView = new FinalLeaderBoardView(state.getCam()); + lenLeaderBordPage=2400; //testing variable until firebase is implemented + finalLeaderBoardView.setNumBackgroundRenders(calculateBackgroundRenders()); //Tells view how many backgroundTextures to load + + + + + + } + + + int mouseYCoordinate; + + public void handleInput(){ + + + + if (Gdx.input.justTouched()){ + mouseYCoordinate =Gdx.input.getY(); + Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); + state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates + if (finalLeaderBoardView.getBackToStartBounds().contains(touchPos.x, touchPos.y)){ + state.getStateManager().setState(new CreateGameState(state.getStateManager())); //midlertidlig + } + + + } + if (Gdx.input.isTouched()){ + int scrollDistance=mouseYCoordinate-Gdx.input.getY(); + + mouseYCoordinate=Gdx.input.getY(); + if( (finalLeaderBoardView.getCam().viewportHeight/2 + finalLeaderBoardView.getCam().position.y) -scrollDistance < WordBattle.HEIGHT && ( (-finalLeaderBoardView.getCam().viewportHeight/2) + finalLeaderBoardView.getCam().position.y) -scrollDistance > WordBattle.HEIGHT-lenLeaderBordPage ){ + finalLeaderBoardView.getCam().translate(0,-scrollDistance); + + } + + + } + + + + + } + + public void render(SpriteBatch sb){ + finalLeaderBoardView.render(sb); + + } + + public void update(float dt){ + handleInput(); + + } + + public int calculateBackgroundRenders(){ + return 1 +lenLeaderBordPage / WordBattle.HEIGHT; + } + + public void dispose(){ + + } + +} diff --git a/core/src/com/wordbattle/game/controller/LeaderBoardController.java b/core/src/com/wordbattle/game/controller/LeaderBoardController.java new file mode 100644 index 0000000000000000000000000000000000000000..6ef4f4ac2e6aeb013e7d57b450b68882f2b8cc14 --- /dev/null +++ b/core/src/com/wordbattle/game/controller/LeaderBoardController.java @@ -0,0 +1,85 @@ +package com.wordbattle.game.controller; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; +import com.wordbattle.game.WordBattle; +import com.wordbattle.game.states.CreateGameState; +import com.wordbattle.game.states.LeaderBoardState; +import com.wordbattle.game.view.LeaderBoardView; + +public class LeaderBoardController { + + private LeaderBoardState state; + + private LeaderBoardView leaderBoardView; + + private int lenLeaderBordPage; + + + + public LeaderBoardController(LeaderBoardState state) { + this.state=state; + leaderBoardView = new LeaderBoardView(state.getCam()); + lenLeaderBordPage=2400; //testing variable until firebase is implemented + leaderBoardView.setNumBackgroundRenders(calculateBackgroundRenders()); //Tells view how many backgroundTextures to load + + + + + + } + + + int mouseYCoordinate; + + public void handleInput(){ + + + + if (Gdx.input.justTouched()){ + mouseYCoordinate =Gdx.input.getY(); + Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); + state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates + if (leaderBoardView.getNextRoundBounds().contains(touchPos.x, touchPos.y)){ + state.getStateManager().setState(new CreateGameState(state.getStateManager())); //midlertidlig + } + + + } + if (Gdx.input.isTouched()){ + int scrollDistance=mouseYCoordinate-Gdx.input.getY(); + + mouseYCoordinate=Gdx.input.getY(); + if( (leaderBoardView.getCam().viewportHeight/2 + leaderBoardView.getCam().position.y) -scrollDistance < WordBattle.HEIGHT && ( (-leaderBoardView.getCam().viewportHeight/2) + leaderBoardView.getCam().position.y) -scrollDistance > WordBattle.HEIGHT-lenLeaderBordPage ){ + leaderBoardView.getCam().translate(0,-scrollDistance); + + } + + + } + + + + + } + + public void render(SpriteBatch sb){ + leaderBoardView.render(sb); + + } + + public void update(float dt){ + handleInput(); + + } + + public int calculateBackgroundRenders(){ + return 1+ lenLeaderBordPage / WordBattle.HEIGHT; + } + + public void dispose(){ + + } +} diff --git a/core/src/com/wordbattle/game/states/FinalLeaderboardState.java b/core/src/com/wordbattle/game/states/FinalLeaderboardState.java new file mode 100644 index 0000000000000000000000000000000000000000..9fa26af98dcf5d36c5f0bfa88304a3f350400243 --- /dev/null +++ b/core/src/com/wordbattle/game/states/FinalLeaderboardState.java @@ -0,0 +1,56 @@ +package com.wordbattle.game.states; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.wordbattle.game.WordBattle; +import com.wordbattle.game.controller.FinalLeaderBoardController; + +public class FinalLeaderboardState extends BaseState { + + FinalLeaderBoardController controller; + public FinalLeaderboardState(StateManager gsm) { + super(gsm); + this.controller = new FinalLeaderBoardController(this); // 'this' provides context + cam.setToOrtho(false, WordBattle.WIDTH, WordBattle.HEIGHT); + } + + + + @Override + public void handleInput() { + + } + + @Override + public void update(float dt) { + controller.update(dt); + cam.update(); + + } + + @Override + public void render(SpriteBatch sb) { + controller.render(sb); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } + + public StateManager getStateManager() { + return gsm; + } + + + + + @Override + public void dispose() { + controller.dispose(); + } +} diff --git a/core/src/com/wordbattle/game/states/LeaderBoardState.java b/core/src/com/wordbattle/game/states/LeaderBoardState.java new file mode 100644 index 0000000000000000000000000000000000000000..7f3cbce4ebda7b540dfb3a7acc0d870624d2835e --- /dev/null +++ b/core/src/com/wordbattle/game/states/LeaderBoardState.java @@ -0,0 +1,51 @@ +package com.wordbattle.game.states; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.wordbattle.game.WordBattle; +import com.wordbattle.game.controller.LeaderBoardController; +import com.wordbattle.game.controller.MainMenuController; + +public class LeaderBoardState extends BaseState { + + LeaderBoardController controller; + public LeaderBoardState(StateManager gsm) { + super(gsm); + this.controller = new LeaderBoardController(this); // 'this' provides context + cam.setToOrtho(false, WordBattle.WIDTH, WordBattle.HEIGHT); + } + + public StateManager getStateManager() { + return gsm; + } + + @Override + public void handleInput() { + + } + + @Override + public void update(float dt) { + controller.update(dt); + cam.update(); + } + + @Override + public void render(SpriteBatch sb) { + controller.render(sb); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } + + @Override + public void dispose() { + controller.dispose(); + } +} diff --git a/core/src/com/wordbattle/game/view/FinalLeaderBoardView.java b/core/src/com/wordbattle/game/view/FinalLeaderBoardView.java new file mode 100644 index 0000000000000000000000000000000000000000..f328e1649013c8f256ccbaee45b9b93890c5d5d8 --- /dev/null +++ b/core/src/com/wordbattle/game/view/FinalLeaderBoardView.java @@ -0,0 +1,140 @@ +package com.wordbattle.game.view; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +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.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.math.Rectangle; +import com.wordbattle.game.WordBattle; + +public class FinalLeaderBoardView { + private OrthographicCamera cam; + + private Texture background; + + private Texture pinkBubble; + private Texture goldenBubble; + + private Texture firstPlaceTex; + + private Texture secondPlaceTex; + + private Texture thirdPlaceTex; + + private Texture BackToStartTex; + + + private Rectangle backToStartBounds; + + private BitmapFont playerFont; + + private BitmapFont titleFont; + + + + private int numBackgroundRenders; + + public FinalLeaderBoardView(OrthographicCamera cam) { + this.cam = cam; + + + backToStartBounds= new Rectangle(30,690, 400,80); + + background= new Texture("bg2.png"); + pinkBubble = new Texture("pink_long-01.png"); + goldenBubble = new Texture("Golden_long-01.png"); + + firstPlaceTex=new Texture("Nr1Emoji.png"); + secondPlaceTex = new Texture("Nr2Emoji.png"); + thirdPlaceTex = new Texture("Nr3Emoji.png"); + + BackToStartTex = new Texture("BackToStartButton.png"); + + + + + + + + // Load and set up font + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("Knewave-Regular.ttf")); + FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); + parameter.size = 34; + playerFont = generator.generateFont(parameter); + playerFont.setColor(Color.BLACK); + + + parameter.size=70; + titleFont=generator.generateFont(parameter); + titleFont.setColor(Color.PINK); + generator.dispose(); + + } + + public void render(SpriteBatch spriteBatch) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + cam.update(); + spriteBatch.setProjectionMatrix(cam.combined); + spriteBatch.begin(); + + for (int i = 0; i < numBackgroundRenders ; i++) { + spriteBatch.draw(background,0,0-(i* WordBattle.HEIGHT), WordBattle.WIDTH,WordBattle.HEIGHT); + } + + + //spriteBatch.draw(purpleRectangle,10,- + spriteBatch.draw(BackToStartTex,backToStartBounds.x,backToStartBounds.y-10, backToStartBounds.getWidth(),backToStartBounds.getHeight()+20); + + + + + titleFont.draw(spriteBatch,"Final Result", 40, 660); + + spriteBatch.draw(pinkBubble,45,490,400,100); + spriteBatch.draw(firstPlaceTex,80,520,35,35); + playerFont.draw(spriteBatch,"Marcus",120,560); + + + spriteBatch.draw(goldenBubble,45,410,400,100); + spriteBatch.draw(secondPlaceTex,80,440,35,35); + + playerFont.draw(spriteBatch,"Askh",120,480); + + + + + + + spriteBatch.end(); + + } + + public OrthographicCamera getCam() { + return cam; + } + + public Rectangle getBackToStartBounds() { + return backToStartBounds; + } + + public void setNumBackgroundRenders(int backgroundRenders){ + this.numBackgroundRenders=backgroundRenders; + } + + public void dispose(){ + background.dispose(); + pinkBubble.dispose(); + goldenBubble.dispose(); + firstPlaceTex.dispose(); + secondPlaceTex.dispose(); + thirdPlaceTex.dispose(); + BackToStartTex.dispose(); + + } + +} diff --git a/core/src/com/wordbattle/game/view/LeaderBoardView.java b/core/src/com/wordbattle/game/view/LeaderBoardView.java new file mode 100644 index 0000000000000000000000000000000000000000..2946585a3f92cffb6f325c2aeb32c00a1aa8079b --- /dev/null +++ b/core/src/com/wordbattle/game/view/LeaderBoardView.java @@ -0,0 +1,142 @@ +package com.wordbattle.game.view; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +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.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.math.Rectangle; +import com.wordbattle.game.WordBattle; + +import org.w3c.dom.Text; + +public class LeaderBoardView { + + private OrthographicCamera cam; + + private Texture background; + + private Texture pinkBubble; + private Texture goldenBubble; + + private Texture firstPlaceTex; + + private Texture secondPlaceTex; + + private Texture thirdPlaceTex; + + private Texture nextRoundTex; + + private Texture ArrowTex; + + + private Rectangle NextRoundBounds; + + private BitmapFont playerFont; + + private BitmapFont titleFont; + + + + private int numBackgroundRenders; + + public LeaderBoardView(OrthographicCamera cam) { + this.cam = cam; + + NextRoundBounds= new Rectangle(30,690, 400,80); + + background= new Texture("bg2.png"); + pinkBubble = new Texture("pink_long-01.png"); + goldenBubble = new Texture("Golden_long-01.png"); + + firstPlaceTex=new Texture("Nr1Emoji.png"); + secondPlaceTex = new Texture("Nr2Emoji.png"); + thirdPlaceTex = new Texture("Nr3Emoji.png"); + + nextRoundTex = new Texture("NextRoundButton.png"); + ArrowTex= new Texture("RightArrow.png"); + + + + + // Load and set up font + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("Knewave-Regular.ttf")); + FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); + parameter.size = 34; + playerFont = generator.generateFont(parameter); + playerFont.setColor(Color.BLACK); + + + parameter.size=70; + titleFont=generator.generateFont(parameter); + titleFont.setColor(Color.PINK); + generator.dispose(); + + } + + public void render(SpriteBatch spriteBatch) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + cam.update(); + spriteBatch.setProjectionMatrix(cam.combined); + spriteBatch.begin(); + + for (int i = 0; i < numBackgroundRenders ; i++) { + spriteBatch.draw(background,0,0-(i*WordBattle.HEIGHT), WordBattle.WIDTH,WordBattle.HEIGHT); + } + + + //spriteBatch.draw(purpleRectangle,10,- + spriteBatch.draw(nextRoundTex,getNextRoundBounds().x,getNextRoundBounds().y-10, getNextRoundBounds().getWidth(),getNextRoundBounds().getHeight()+20); + spriteBatch.draw(ArrowTex,350,715,50,25); + + + + titleFont.draw(spriteBatch,"LeaderBoard", 40, 660); + + spriteBatch.draw(pinkBubble,45,490,400,100); + spriteBatch.draw(firstPlaceTex,80,520,35,35); + playerFont.draw(spriteBatch,"Marcus",120,560); + + + spriteBatch.draw(goldenBubble,45,410,400,100); + spriteBatch.draw(secondPlaceTex,80,440,35,35); + + playerFont.draw(spriteBatch,"Askh",120,480); + + + + + + + spriteBatch.end(); + + } + + public OrthographicCamera getCam() { + return cam; + } + + public Rectangle getNextRoundBounds() { + return NextRoundBounds; + } + + public void setNumBackgroundRenders(int backgroundRenders){ + this.numBackgroundRenders=backgroundRenders; + } + + public void dispose(){ + background.dispose(); + pinkBubble.dispose(); + goldenBubble.dispose(); + firstPlaceTex.dispose(); + secondPlaceTex.dispose(); + thirdPlaceTex.dispose(); + nextRoundTex.dispose(); + ArrowTex.dispose(); + } + +}