GammelJan 6 years ago
parent 753cf1084f
commit ee83616b17

@ -162,7 +162,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
if(ts != null) ts.render(batch); if(ts != null) ts.render(batch);
else if(ls != null){ else if(ls != null){
ls.render(batch); ls.render(batch, level[currentLevel]);
currentLevel = ls.getSelectedLevel(); currentLevel = ls.getSelectedLevel();
} }
else if(gs != null){ else if(gs != null){
@ -171,7 +171,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
gs.dispose(); gs.dispose();
stepTimer.stop(); stepTimer.stop();
level[currentLevel].reset(); level[currentLevel].reset();
beatenLevel++; if(currentLevel == beatenLevel)beatenLevel++;
gs = null; gs = null;
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true, currentLevel); ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true, currentLevel);
} }
@ -206,7 +206,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
if(ts != null){ if(ts != null){
ts.dispose(); ts.dispose();
ts = null; ts = null;
ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT); ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
} }
else if(ls != null){ else if(ls != null){
if(x < Gdx.graphics.getWidth() * 0.15){ if(x < Gdx.graphics.getWidth() * 0.15){
@ -230,7 +230,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
} }
else if(ws != null){ else if(ws != null){
if(x < Gdx.graphics.getWidth() * 0.33){ if(x < Gdx.graphics.getWidth() * 0.33){
ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT); ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
ws = null; ws = null;
} }
else if(x < Gdx.graphics.getWidth() * 0.66){ else if(x < Gdx.graphics.getWidth() * 0.66){

@ -17,6 +17,8 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.Timer;
import model.Goal; import model.Goal;
import model.Level; import model.Level;
@ -38,8 +40,14 @@ public class Levelscreen{
int levelAmount; int levelAmount;
float GAME_WORLD_WIDTH; float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT; float GAME_WORLD_HEIGHT;
ShapeRenderer shapeRenderer;
Sprite clicktostart;
boolean movementStart;
float clicktostartX;
float clicktostartY;
public Levelscreen(int levelAmount, float width, float height){
public Levelscreen(int levelAmount, float width, float height, Matrix4 matrix){
GAME_WORLD_WIDTH = width; GAME_WORLD_WIDTH = width;
GAME_WORLD_HEIGHT = height; GAME_WORLD_HEIGHT = height;
levelPreview = new Sprite[levelAmount]; levelPreview = new Sprite[levelAmount];
@ -51,6 +59,9 @@ public class Levelscreen{
buttonLeft.setX(10); buttonLeft.setX(10);
selectedLevel = 0; selectedLevel = 0;
this.levelAmount = levelAmount; this.levelAmount = levelAmount;
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(matrix);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
@ -61,6 +72,10 @@ public class Levelscreen{
font.setColor(Color.BLACK); font.setColor(Color.BLACK);
movementStart = true;
clicktostartX = GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2;
clicktostartY = GAME_WORLD_HEIGHT / 2;
t = new Timer(); t = new Timer();
t.scheduleTask(new Timer.Task() { t.scheduleTask(new Timer.Task() {
@ -80,11 +95,19 @@ public class Levelscreen{
buttonRight.setX(buttonRight.getX() + 2); buttonRight.setX(buttonRight.getX() + 2);
buttonLeft.setX(buttonLeft.getX() - 2); buttonLeft.setX(buttonLeft.getX() - 2);
} }
if(clicktostartY < GAME_WORLD_HEIGHT * 0.4)
movementStart = true;
else if(clicktostartY > GAME_WORLD_HEIGHT * 0.5)
movementStart = false;
if(movementStart)
clicktostartY = clicktostartY + 3;
else
clicktostartY = clicktostartY - 3;
} }
},0 , 0.045f); },0 , 0.035f);
} }
public void render(SpriteBatch batch) { public void render(SpriteBatch batch, Level level) {
if(selectedLevel > 0){ if(selectedLevel > 0){
buttonLeft.draw(batch); buttonLeft.draw(batch);
@ -93,11 +116,13 @@ public class Levelscreen{
buttonRight.draw(batch); buttonRight.draw(batch);
} }
font.getData().setScale(1);
font.draw(batch, "" + selectedLevel, GAME_WORLD_WIDTH / 2, GAME_WORLD_HEIGHT / 2);
font.getData().setScale(6); font.getData().setScale(6);
font.draw(batch,"LEVEL: "+ selectedLevel, GAME_WORLD_WIDTH / 2 - getTextWidth("LEVEL: "+ selectedLevel) / 2, GAME_WORLD_HEIGHT * 0.95f); font.draw(batch,"LEVEL: "+ (selectedLevel + 1), GAME_WORLD_WIDTH / 2 - getTextWidth("LEVEL: "+ selectedLevel) / 2, GAME_WORLD_HEIGHT * 0.95f);
font.getData().setScale(2);
clicktostartX = GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2;
font.draw(batch, "click to start ...", clicktostartX, clicktostartY);
} }

@ -12,8 +12,10 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.Timer;
/** /**
@ -28,27 +30,42 @@ public class Titlescreen{
boolean movement; boolean movement;
float GAME_WORLD_WIDTH; float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT; float GAME_WORLD_HEIGHT;
float clicktostartX;
float clicktostartY;
public Titlescreen(float width, float height){ public Titlescreen(float width, float height){
this.GAME_WORLD_WIDTH = width; this.GAME_WORLD_WIDTH = width;
this.GAME_WORLD_HEIGHT = height; this.GAME_WORLD_HEIGHT = height;
movement = true; movement = true;
clicktostart = new Sprite(new Texture(Gdx.files.internal("clicktostart.png"))); clicktostart = new Sprite(new Texture(Gdx.files.internal("clicktostart.png")));
clicktostart.setX(GAME_WORLD_WIDTH / 2 - clicktostart.getWidth() / 2);
clicktostart.setY(GAME_WORLD_HEIGHT / 2 - clicktostart.getHeight() / 2);
t = new Timer(); t = new Timer();
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!
clicktostartX = GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2;
clicktostartY = GAME_WORLD_HEIGHT / 2 - clicktostart.getHeight() / 2;
font.setColor(Color.BLACK);
t.scheduleTask(new Timer.Task() { t.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
if(clicktostart.getY() < GAME_WORLD_HEIGHT * 0.4) if(clicktostartY < GAME_WORLD_HEIGHT * 0.4)
movement = true; movement = true;
else if(clicktostart.getY() > GAME_WORLD_HEIGHT * 0.5) else if(clicktostartY > GAME_WORLD_HEIGHT * 0.5)
movement = false; movement = false;
if(movement) if(movement)
clicktostart.setY(clicktostart.getY() + 3); clicktostartY = clicktostartY + 3;
else else
clicktostart.setY(clicktostart.getY() - 3); clicktostartY = clicktostartY - 3;
} }
},0 , 0.035f); },0 , 0.035f);
@ -56,9 +73,20 @@ public class Titlescreen{
} }
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
clicktostart.draw(batch); font.getData().setScale(6);
font.draw(batch, "THROWGAME", GAME_WORLD_WIDTH / 2 - getTextWidth("THROWGAME") / 2, GAME_WORLD_HEIGHT * 0.9f);
font.getData().setScale(2);
clicktostartX = GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2;
font.draw(batch, "click to start ...", clicktostartX, clicktostartY);
} }
public void dispose() { public void dispose() {
t.clear(); t.clear();
} }
public float getTextWidth(String text){
GlyphLayout glyphLayout = new GlyphLayout();
String item = text;
glyphLayout.setText(font,item);
return glyphLayout.width;
}
} }

Loading…
Cancel
Save