From 60811f12294848159337b009191625a2160547be Mon Sep 17 00:00:00 2001 From: GammelJan Date: Fri, 19 Jun 2020 22:50:18 +0200 Subject: [PATCH] EHRE ALLA SPIEL GLEICH FERTIG --- core/src/controller/Controller.java | 1 - core/src/view/Winscreen.java | 49 ++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/core/src/controller/Controller.java b/core/src/controller/Controller.java index 7555961..6063985 100644 --- a/core/src/controller/Controller.java +++ b/core/src/controller/Controller.java @@ -62,7 +62,6 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ gs = null; ws = null; levelAmount = 9; - currentLevel = -1; batch = new SpriteBatch(); Gdx.input.setInputProcessor(this); diff --git a/core/src/view/Winscreen.java b/core/src/view/Winscreen.java index f3551e5..8d5aea9 100644 --- a/core/src/view/Winscreen.java +++ b/core/src/view/Winscreen.java @@ -6,10 +6,13 @@ package view; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.utils.Timer; /** @@ -32,6 +35,10 @@ public class Winscreen{ float GAME_WORLD_HEIGHT; boolean win; + + float winX; + float winY; + boolean movementWin; int lvl; @@ -43,7 +50,16 @@ public class Winscreen{ this.lvl = lvl; if(win){ - movement = true; + + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); + FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); + parameter.size = 21; + font = generator.generateFont(parameter); // font size 12 pixels + generator.dispose(); // don't forget to dispose to avoid memory leaks! + + font.setColor(Color.BLACK); + + movementWin = true; winSprite = new Sprite(new Texture(Gdx.files.internal("win.png"))); winSprite.setX(GAME_WORLD_WIDTH / 2 - winSprite.getWidth() / 2); winSprite.setY(GAME_WORLD_HEIGHT * 0.7f - winSprite.getHeight() / 2); @@ -63,16 +79,14 @@ public class Winscreen{ t.scheduleTask(new Timer.Task() { @Override public void run() { - if(winSprite.getY() < GAME_WORLD_HEIGHT*0.7){ - movement = true;} - if(winSprite.getY() > GAME_WORLD_HEIGHT * 0.8){ - movement = false;} - if(movement){ - winSprite.setY(winSprite.getY() + 3); - } - else{ - winSprite.setY(winSprite.getY() - 3); - } + if(winY < GAME_WORLD_HEIGHT * 0.7) + movementWin = true; + else if(winY > GAME_WORLD_HEIGHT * 0.8) + movementWin = false; + if(movementWin) + winY = winY + 3; + else + winY = winY - 3; } },0 , 0.035f); } @@ -83,7 +97,12 @@ public class Winscreen{ if(lvl < 9 && win)next.draw(batch); level.draw(batch); reset.draw(batch); - if(win)winSprite.draw(batch); + if(win){ + font.getData().setScale(2); + winX = GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2; + font.draw(batch, "click to start ...", winX, winY); + + } } public void dispose() { @@ -92,4 +111,10 @@ public class Winscreen{ public boolean getWin(){ return win; } + public float getTextWidth(String text){ + GlyphLayout glyphLayout = new GlyphLayout(); + String item = text; + glyphLayout.setText(font,item); + return glyphLayout.width; + } }