From b1a8ee552212032ee96a0ebda59ab606bbfcc172 Mon Sep 17 00:00:00 2001 From: Jan Ehehalt Date: Tue, 23 Jun 2020 11:14:44 +0200 Subject: [PATCH] lol --- core/src/controller/Controller.java | 75 +++++++++------------- core/src/view/Chapterscreen.java | 4 +- core/src/view/Leveleditor.java | 24 ++++--- core/src/view/Levelscreen.java | 97 ++++++++++++++++++++++++----- 4 files changed, 129 insertions(+), 71 deletions(-) diff --git a/core/src/controller/Controller.java b/core/src/controller/Controller.java index 858a279..f14e20b 100644 --- a/core/src/controller/Controller.java +++ b/core/src/controller/Controller.java @@ -17,6 +17,8 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.viewport.ExtendViewport; +import com.badlogic.gdx.utils.viewport.FitViewport; +import com.badlogic.gdx.utils.viewport.StretchViewport; import com.badlogic.gdx.utils.viewport.Viewport; import java.io.File; @@ -80,7 +82,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ float aspectRatio = (float)Gdx.graphics.getHeight() / (float)Gdx.graphics.getWidth(); camera = new OrthographicCamera(); - viewport = new ExtendViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT * aspectRatio, camera); + viewport = new StretchViewport(GAME_WORLD_WIDTH/* *aspectRatio*/, GAME_WORLD_HEIGHT, camera); viewport.apply(); camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0); @@ -267,8 +269,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ @Override public boolean touchDown(int x, int y, int i2, int i3) { + x = (int)((float)x / (float)Gdx.graphics.getWidth() * (float)GAME_WORLD_WIDTH); + y = (int)GAME_WORLD_HEIGHT-(int)((float)y / Gdx.graphics.getHeight() * GAME_WORLD_HEIGHT); if(ts != null){ - if(x > 0.05 * Gdx.graphics.getWidth()){ + if(x > 0.05 * GAME_WORLD_WIDTH){ ts.dispose(); ts = null; //ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); @@ -281,18 +285,26 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } else if(ls != null){ - if(x < Gdx.graphics.getWidth() * 0.15){ - if(ls.getSelectedLevel() > 0)ls.setSelectedLevel(ls.getSelectedLevel()-1); - } - else if(x > Gdx.graphics.getWidth() * 0.85){ - if(ls.getSelectedLevel() < beatenLevel && beatenLevel <= levelAmount) - ls.setSelectedLevel(ls.getSelectedLevel()+1); - } - else{ - ls.dispose(); - ls = null; - gs = new Gamescreen(level.get(currentChapter).get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - stepTimer.start(); + int n = ls.touchDown(x,y); + switch(n){ + case 0: + ls.dispose(); + ls = null; + cs = new Chapterscreen(5,GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT,camera.combined); + break; + case 1: + if(ls.getSelectedLevel() > 0)ls.setSelectedLevel(ls.getSelectedLevel()-1); + break; + case 2: + if(ls.getSelectedLevel() < beatenLevel && beatenLevel <= levelAmount) + ls.setSelectedLevel(ls.getSelectedLevel()+1); + break; + case 3: + ls.dispose(); + ls = null; + gs = new Gamescreen(level.get(currentChapter).get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); + stepTimer.start(); + break; } } else if(gs != null){ @@ -301,11 +313,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } else if(ws != null){ - if(x < Gdx.graphics.getWidth() * 0.33){ + if(x < GAME_WORLD_WIDTH * 0.33){ ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); ws = null; } - else if(x < Gdx.graphics.getWidth() * 0.66){ + else if(x < GAME_WORLD_WIDTH * 0.66){ gs = new Gamescreen(level.get(currentChapter).get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); stepTimer.start(); ws = null; @@ -325,35 +337,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ if(cs.touchDown(x,y) == -1){ } - else if (cs.touchDown(x,y) == 0){ - currentChapter = 0; - cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - } - else if (cs.touchDown(x,y) == 1){ - currentChapter = 1; - cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - } - else if (cs.touchDown(x,y) == 2){ - currentChapter = 2; - cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - } - else if (cs.touchDown(x,y) == 3){ - currentChapter = 3; - cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - } - else if (cs.touchDown(x,y) == 4){ - currentChapter = 4; - cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); - } - else if (cs.touchDown(x,y) == 5){ - currentChapter = 5; + else if (cs.touchDown(x,y) >= 0 && cs.touchDown(x,y) <= 5){ + currentChapter = cs.touchDown(x,y); cs = null; - ls = new Levelscreen(level.get(currentChapter).size(), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); + ls = new Levelscreen(level.get(currentChapter).size()-1, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); } else if(cs.touchDown(x,y) == 6){ cs.dispose(); diff --git a/core/src/view/Chapterscreen.java b/core/src/view/Chapterscreen.java index 955ff0f..f410f01 100644 --- a/core/src/view/Chapterscreen.java +++ b/core/src/view/Chapterscreen.java @@ -58,7 +58,7 @@ public class Chapterscreen{ buttons.add(new Button("Chapter 4", (int)(0.05 * GAME_WORLD_WIDTH - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 4)); buttons.add(new Button("Chapter 5", (int)(0.1 * GAME_WORLD_WIDTH + buttons.get(0).getWidth() - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 5)); buttons.add(new Button("User Level",(int)(0.15 * GAME_WORLD_WIDTH + buttons.get(0).getWidth()*2 - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 0)); - buttons.add(new Button("back", (int)(0.05 * GAME_WORLD_WIDTH), (int)(0.02 * GAME_WORLD_HEIGHT), (int)(0.2 * GAME_WORLD_WIDTH), (int)(0.1 * GAME_WORLD_HEIGHT), 6)); + buttons.add(new Button("< back", 20,10,200,80,6)); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); @@ -100,7 +100,7 @@ public class Chapterscreen{ public int touchDown(int x, int y){ - Rectangle mouse = new Rectangle(x, GAME_WORLD_HEIGHT - y, 1, 1); + Rectangle mouse = new Rectangle(x, y, 1, 1); for(Button button : buttons){ if(Intersector.overlaps(mouse, button.getRectangle())){ return button.getId(); diff --git a/core/src/view/Leveleditor.java b/core/src/view/Leveleditor.java index 24e6439..3d3b4b5 100644 --- a/core/src/view/Leveleditor.java +++ b/core/src/view/Leveleditor.java @@ -75,10 +75,10 @@ public class Leveleditor{ // CREATE DEFAULT BUTTONS buttons = new ArrayList(); - buttons.add(new Button("Pivot", (int)(GAME_WORLD_WIDTH * 0.02),(int) (GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.07 * GAME_WORLD_HEIGHT), 200, 50, 0)); - buttons.add(new Button("Goal", (int)(GAME_WORLD_WIDTH * 0.02), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.07 * GAME_WORLD_HEIGHT), 200, 50, 1)); - buttons.add(new Button("new Obstacle", (int)(GAME_WORLD_WIDTH * 0.02), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.07 * GAME_WORLD_HEIGHT), 200, 50, 2)); - buttons.add(new Button("SAVE", (int)(GAME_WORLD_WIDTH * 0.8), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.07 * GAME_WORLD_HEIGHT), 200, 50, 4)); + buttons.add(new Button("Pivot", (int)(GAME_WORLD_WIDTH * 0.02),(int) (GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.1 * GAME_WORLD_HEIGHT), 250, 80, 0)); + buttons.add(new Button("Goal", (int)(GAME_WORLD_WIDTH * 0.02), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.1 * GAME_WORLD_HEIGHT), 250, 80, 1)); + buttons.add(new Button("new Obstacle", (int)(GAME_WORLD_WIDTH * 0.02), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.1 * GAME_WORLD_HEIGHT), 250, 80, 2)); + buttons.add(new Button("SAVE", (int)(GAME_WORLD_WIDTH * 0.8), (int)(GAME_WORLD_HEIGHT - (buttons.size()+1) * 0.1 * GAME_WORLD_HEIGHT), 250, 80, 4)); // CREATE BITMAP FONT font = new BitmapFont(); @@ -100,6 +100,9 @@ public class Leveleditor{ shapeRenderer.setColor(Color.BLACK); // DRAW PIVOT if(pivotSet) { + shapeRenderer.setColor(Color.LIGHT_GRAY); + shapeRenderer.circle(level.getPivotX(), level.getPivotY(), 150); + shapeRenderer.setColor(Color.BLACK); shapeRenderer.rectLine((float) level.getPivotX(), (float) level.getPivotY(), (float) level.getProjectile().getxPos(), (float) level.getProjectile().getyPos(), 3); shapeRenderer.setColor(Color.GRAY); shapeRenderer.circle(level.getPivotX(), level.getPivotY(), 5); @@ -120,8 +123,9 @@ public class Leveleditor{ shapeRenderer.rectLine(button.getxPos() + button.getWidth(), button.getyPos(),button.getxPos() + button.getWidth(), button.getyPos() + button.getHeight(), 4); shapeRenderer.end(); batch.begin(); - font.getData().setScale(1.5f); + font.getData().setScale(1.6f); font.draw(batch, button.getText(),button.getxPos() + button.getWidth()/2 - getTextWidth(button.getText())/2, button.getyPos() + button.getHeight()/2 + getTextHeight(button.getText())/2); + batch.end(); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); } @@ -158,7 +162,7 @@ public class Leveleditor{ public void touchDown(int x, int y){ switch(state){ case -1: // NO BUTTON SELECTED - Rectangle mouse = new Rectangle(x, (int)GAME_WORLD_HEIGHT -y, 1, 1); + Rectangle mouse = new Rectangle(x, y, 1, 1); for(Button button : buttons){ if(Intersector.overlaps(mouse, button.getRectangle())){ if(button.getId() == 4 && (!goalSet || !pivotSet)){ // DONT SAVE WHEN GOAL OR PIVOT NOT SET @@ -180,19 +184,19 @@ public class Leveleditor{ } break; case 0: // SET PIVOT - level.setPivot(x, (int)GAME_WORLD_HEIGHT - y); + level.setPivot(x, y); level.getProjectile().setxPos(x); - level.getProjectile().setyPos((int) GAME_WORLD_HEIGHT - y + 150); + level.getProjectile().setyPos(y + 150); pivotSet = true; state = -1; break; case 1: // SET GOAL - level.setGoal(x, (int)GAME_WORLD_HEIGHT-y); + level.setGoal(x, y); state = -1; goalSet = true; break; case 2: // NEW OBSTACLE - level.addRectangle(x,(int)GAME_WORLD_HEIGHT-y,200,100); + level.addRectangle(x - 100,y - 50,200,100); state = -1; break; default: diff --git a/core/src/view/Levelscreen.java b/core/src/view/Levelscreen.java index 1b29177..60ddcda 100644 --- a/core/src/view/Levelscreen.java +++ b/core/src/view/Levelscreen.java @@ -18,9 +18,14 @@ 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.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Timer; + +import java.util.ArrayList; + +import model.Button; import model.Goal; import model.Level; import model.Projectile; @@ -31,44 +36,65 @@ import model.Projectile; */ public class Levelscreen{ + float GAME_WORLD_WIDTH; + float GAME_WORLD_HEIGHT; + // SPRITES LEFT-RIGHT Sprite buttonRight; Sprite buttonLeft; - int selectedLevel; - BitmapFont font; - Timer t; boolean movement; + + // VARIABLES + int selectedLevel; int levelAmount; - float GAME_WORLD_WIDTH; - float GAME_WORLD_HEIGHT; + + // SHAPE RENDERER ShapeRenderer shapeRenderer; - + + // BUTTONS + ArrayList