Skip to content
Snippets Groups Projects
Commit 2ffe3c86 authored by Marcus Christopher Wildish's avatar Marcus Christopher Wildish
Browse files

Merge branch 'make-leaderboard' into 'main'

Finished "Leaderboard" view, controller and state. needs extra logic when firebase is added

See merge request !8
parents 4a51a146 03c22b46
No related branches found
No related tags found
1 merge request!8Finished "Leaderboard" view, controller and state. needs extra logic when firebase is added
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(){
}
}
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(){
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment