From d0b41f7343d5f97521ee1dd79cb0496ff16cc020 Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Sat, 26 Sep 2020 16:20:46 +0200 Subject: [PATCH] You can die now --- core/src/com/trs/game/Controller.java | 13 ++++++++++--- core/src/com/trs/game/model/Model.java | 19 +++++++++++++++---- core/src/com/trs/game/model/Monster.java | 2 +- .../com/trs/game/view/Screens/EndScreen.java | 13 +++++++++++-- .../com/trs/game/view/Screens/GameScreen.java | 5 ----- .../trs/game/view/Screens/MainMenuScreen.java | 2 +- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index 3e90b36..041b9d2 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -33,7 +33,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { final int WALL_LIFETIME = 75; - int difficulty = 0; + int difficulty = 1; SpriteBatch batch; ShapeRenderer renderer; @@ -62,6 +62,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor { screen.timer(); if(screen.getId() == 1) { model.timerStep(); + if(model.isToReset()){ + screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT,model.getEnding()); + } } } }, 0, 0.05f); @@ -131,7 +134,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor { // write left Length batch.begin(); font.setColor(Color.BLACK); - font.draw(batch, ""+model.getLeftWallLength(), 1500f,800f); + font.getData().setScale(2); + font.draw(batch, "Wall pieces: "+model.getLeftWallLength(), 1170f,875f); + font.getData().setScale(1); batch.end(); // DRAW MONSTER model.getMonster().drawMonster(renderer,polygonSpriteBatch); @@ -201,13 +206,15 @@ public class Controller extends ApplicationAdapter implements InputProcessor { switch(keycode){ case 0: //GOTO MAINMENU screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT); + difficulty = 1; break; case 1: //NEW GAMESCREEN 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); + screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, true); + difficulty = 1; break; case 3: difficulty = 1; diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index d33b249..6ee6345 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -19,6 +19,9 @@ public class Model { private boolean drawing = false; private int currentLength; + private boolean toReset; + private boolean ending; + private int difficulty; private int leftWallLength = 5000; @@ -47,10 +50,10 @@ public class Model { walls.remove(i); i--; } - - if (monster.getIsDead()) { - // TODO: Tod implementieren - } + } + if (monster.getIsDead()) { + toReset = true; + ending = true; // Monster win - Player lost } // Generation of new projectiles @@ -160,4 +163,12 @@ public class Model { public int getCurrentLength() { return currentLength; } + + public boolean isToReset() { + return toReset; + } + + public boolean getEnding() { + return ending; + } } diff --git a/core/src/com/trs/game/model/Monster.java b/core/src/com/trs/game/model/Monster.java index ade3663..e8e5441 100644 --- a/core/src/com/trs/game/model/Monster.java +++ b/core/src/com/trs/game/model/Monster.java @@ -102,7 +102,7 @@ public class Monster { private void hit(){ hp--; - if(hp == 0){ + if(hp <= 0){ die(); } } diff --git a/core/src/com/trs/game/view/Screens/EndScreen.java b/core/src/com/trs/game/view/Screens/EndScreen.java index f5cc8de..5de5487 100644 --- a/core/src/com/trs/game/view/Screens/EndScreen.java +++ b/core/src/com/trs/game/view/Screens/EndScreen.java @@ -12,13 +12,22 @@ import com.trs.game.view.Text; public class EndScreen extends Screen { - public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ + boolean lost; + + public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT, boolean lost){ super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2); + this.lost = lost; + + if(lost) + texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "The monster ate too many doods!", Color.BLACK, 3, 0,0)); + else + texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "You successfully starved the Monster!", Color.BLACK, 3, 0,0)); + texts.add(new Text(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, "click to restart...", Color.BLACK, 2, GAME_WORLD_HEIGHT/2 - 30,GAME_WORLD_HEIGHT/2 + 30)); 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(4,710,100,210,50,"Medium",Color.GRAY,Color.BLUE)); 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)); } diff --git a/core/src/com/trs/game/view/Screens/GameScreen.java b/core/src/com/trs/game/view/Screens/GameScreen.java index 1854d76..f81b4f8 100644 --- a/core/src/com/trs/game/view/Screens/GameScreen.java +++ b/core/src/com/trs/game/view/Screens/GameScreen.java @@ -14,11 +14,6 @@ public class GameScreen extends Screen { public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1); - //buttons.add(new Button(-1,0,0,200,80,"GameScreen", Color.BLACK,Color.WHITE)); - - buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE)); - buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE)); - buttons.add(new Button(2,400,800,200,100, "EndScreen", Color.BLACK,Color.WHITE)); } @Override diff --git a/core/src/com/trs/game/view/Screens/MainMenuScreen.java b/core/src/com/trs/game/view/Screens/MainMenuScreen.java index f290d93..ca839b6 100644 --- a/core/src/com/trs/game/view/Screens/MainMenuScreen.java +++ b/core/src/com/trs/game/view/Screens/MainMenuScreen.java @@ -20,7 +20,7 @@ public class MainMenuScreen extends Screen { 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(4,710,100,210,50,"Medium",Color.GRAY,Color.BLUE)); 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)); }