From e8eb44889bce83a543f78401056aa57fc763183b Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Sat, 26 Sep 2020 15:15:48 +0200 Subject: [PATCH] Difficulty --- core/src/com/trs/game/Controller.java | 21 ++++++++++++++----- core/src/com/trs/game/model/Model.java | 4 ++-- core/src/com/trs/game/view/Button.java | 8 +++++++ .../trs/game/view/Screens/MainMenuScreen.java | 12 ++++++++++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index d546a1a..ef5034b 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -1,7 +1,6 @@ package com.trs.game; import com.badlogic.gdx.ApplicationAdapter; -import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.Color; @@ -17,13 +16,11 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Polygon; -import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Timer; import com.trs.game.model.Model; import com.trs.game.model.Projectile; import com.trs.game.model.Wall; import com.trs.game.view.View; -import com.trs.game.view.Button; import com.trs.game.view.Screen; import com.trs.game.view.Screens.EndScreen; import com.trs.game.view.Screens.GameScreen; @@ -36,6 +33,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor { final int WALL_LIFETIME = 75; + int difficulty = 0; + SpriteBatch batch; ShapeRenderer renderer; PolygonSpriteBatch polygonSpriteBatch; @@ -53,7 +52,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { batch = new SpriteBatch(); renderer = new ShapeRenderer(); polygonSpriteBatch = new PolygonSpriteBatch(); - model = new Model(); + model = new Model(difficulty); view = new View(); wallTimer = new Timer(); @@ -204,12 +203,24 @@ public class Controller extends ApplicationAdapter implements InputProcessor { screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT); break; case 1: //GOTO GAMESCREEN - model = new Model(); + model = new Model(difficulty); screen = new GameScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT); break; case 2: //GOTO ENDSCREEN screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT); break; + case 3: + difficulty = 1; + break; + case 4: + difficulty = 2; + break; + case 5: + difficulty = 3; + break; + case 6: + difficulty = 4; + break; } } diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index f5cc67e..ba70544 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -23,8 +23,8 @@ public class Model { private int leftWallLength = 5000; - public Model(){ - difficulty = 0; + public Model(int difficulty){ + this.difficulty = difficulty; monster = new Monster(250,150); walls = new ArrayList<>(); diff --git a/core/src/com/trs/game/view/Button.java b/core/src/com/trs/game/view/Button.java index 92352d1..7348b64 100644 --- a/core/src/com/trs/game/view/Button.java +++ b/core/src/com/trs/game/view/Button.java @@ -59,6 +59,14 @@ public class Button { return new Rectangle(xPos,yPos,width,height); } + public void setButtonColor(Color buttonColor) { + this.buttonColor = buttonColor; + } + + public void setTextColor(Color textColor) { + this.textColor = textColor; + } + public float getTextWidth(BitmapFont font, String text){ GlyphLayout glyphLayout = new GlyphLayout(); glyphLayout.setText(font,text); diff --git a/core/src/com/trs/game/view/Screens/MainMenuScreen.java b/core/src/com/trs/game/view/Screens/MainMenuScreen.java index 397f081..c4fbf5a 100644 --- a/core/src/com/trs/game/view/Screens/MainMenuScreen.java +++ b/core/src/com/trs/game/view/Screens/MainMenuScreen.java @@ -17,6 +17,11 @@ public class MainMenuScreen extends Screen { texts.add(new Text(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, "Protect the Monster", Color.BLACK, 3, GAME_WORLD_HEIGHT/2 - 50,GAME_WORLD_HEIGHT/2 + 50)); + buttons.add(new Button(-1,250,100,240,50,"Difficulty",Color.BLACK,Color.WHITE)); + buttons.add(new Button(3,500,100,210,50,"Easy",Color.DARK_GRAY,Color.WHITE)); + buttons.add(new Button(4,710,100,210,50,"Medium",Color.GRAY,Color.WHITE)); + buttons.add(new Button(5,920,100,210,50,"Hard",Color.DARK_GRAY,Color.WHITE)); + buttons.add(new Button(6,1130,100,210,50,"Impossible",Color.GRAY,Color.WHITE)); } @Override @@ -42,7 +47,12 @@ public class MainMenuScreen extends Screen { Rectangle r = new Rectangle(x,y,1,1); for(Button button : buttons){ if(Intersector.overlaps(r, button.getRect())){ - System.out.println(button.getId()); + if(button.getId() == 3 || button.getId() == 4 || button.getId() == 5 || button.getId() == 6 ){ + for(Button button2 : buttons){ + button2.setTextColor(Color.WHITE); + } + button.setTextColor(Color.BLUE); + } return button.getId(); } }