From a8559b74206b16886a617668879c91e04f9cf45f Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Fri, 1 Jan 2021 20:32:38 +0100 Subject: [PATCH] Player can now have multiple quests, Transition when changing map added --- .../1/dialogues/map1/npc0/dialogue.txt | 3 + .../1/dialogues/map1/npc1/dialogue.txt | 3 + core/src/com/trs/main/InformationQuest.java | 89 ++++++------------- core/src/com/trs/main/Main.java | 2 +- core/src/com/trs/main/MapContainer.java | 21 +++-- core/src/com/trs/main/Player.java | 50 +++++++---- core/src/com/trs/main/Quest.java | 3 +- core/src/com/trs/main/TransitionScreen.java | 50 +++++++++++ 8 files changed, 138 insertions(+), 83 deletions(-) create mode 100644 core/assets/quests/informationQuests/1/dialogues/map1/npc0/dialogue.txt create mode 100644 core/assets/quests/informationQuests/1/dialogues/map1/npc1/dialogue.txt create mode 100644 core/src/com/trs/main/TransitionScreen.java diff --git a/core/assets/quests/informationQuests/1/dialogues/map1/npc0/dialogue.txt b/core/assets/quests/informationQuests/1/dialogues/map1/npc0/dialogue.txt new file mode 100644 index 0000000..a86f7f4 --- /dev/null +++ b/core/assets/quests/informationQuests/1/dialogues/map1/npc0/dialogue.txt @@ -0,0 +1,3 @@ +nicenice +lol#-1 +lolol#-1 \ No newline at end of file diff --git a/core/assets/quests/informationQuests/1/dialogues/map1/npc1/dialogue.txt b/core/assets/quests/informationQuests/1/dialogues/map1/npc1/dialogue.txt new file mode 100644 index 0000000..e13d7a1 --- /dev/null +++ b/core/assets/quests/informationQuests/1/dialogues/map1/npc1/dialogue.txt @@ -0,0 +1,3 @@ +nivwenuveruivre +lol#-1 +lolol#-1 \ No newline at end of file diff --git a/core/src/com/trs/main/InformationQuest.java b/core/src/com/trs/main/InformationQuest.java index b1e4ac4..1135403 100644 --- a/core/src/com/trs/main/InformationQuest.java +++ b/core/src/com/trs/main/InformationQuest.java @@ -26,7 +26,7 @@ public class InformationQuest extends Quest{ boolean rightOrderRequired; - InformationQuest(int questId, String questText/*, Quest[] followingQuest*/, int[] informationNpcId, int[] informationNpcMapId, boolean rightOrderRequired){ + InformationQuest(int questId, String questText, int[] informationNpcId, int[] informationNpcMapId, boolean rightOrderRequired){ this.questId = questId; @@ -41,40 +41,42 @@ public class InformationQuest extends Quest{ this.questText = questText; - /* TODO: More quest inside on Quest-string - - if(followingQuest.length > 1){ - Quest[] nextQuests = new Quest[followingQuest.length-1]; - for(int i = 1; i < followingQuest.length; i++){ - nextQuests[i-1] = followingQuest[i]; + } + + void talk(MovingNpc a){ + for(int i = 0; i < talked.length; i++){ + if(informationNpcId[i] == a.id && informationNpcMapId[i] == a.mapId){ + talked[i] = true; + break; } - this.followingQuest = new InformationQuest(); } - */ } boolean hasSpecialDialogue(int NpcId, int mapId){ - if(!rightOrderRequired){ - for(int i = 0; i < talked.length; i++){ - if(informationNpcId[i] == NpcId && informationNpcMapId[i] == mapId && !talked[i]){ - return true; + if(!finished){ + if(!rightOrderRequired){ + for(int i = 0; i < talked.length; i++){ + if(informationNpcId[i] == NpcId && informationNpcMapId[i] == mapId && !talked[i]){ + return true; + } } } - } - else{ - int nextToTalk = 0; - for(int i = 0; i < talked.length; i++){ - if(!talked[i]){ - nextToTalk = i; - break; + else{ + int nextToTalk = 0; + for(int i = 0; i < talked.length; i++){ + if(!talked[i]){ + nextToTalk = i; + break; + } } + if(informationNpcId[nextToTalk] == NpcId && informationNpcMapId[nextToTalk] == mapId){ + return true; + } } - if(informationNpcId[nextToTalk] == NpcId && informationNpcMapId[nextToTalk] == mapId){ - return true; - } + return false; } - return false; + else return false; } String getDialoguePath(int NpcId, int mapId){ @@ -82,50 +84,15 @@ public class InformationQuest extends Quest{ } @Override - void updateQuest(Array actors) { + void updateQuest() { if(!finished){ - if(rightOrderRequired){ - int nextToTalk = 0; - for(int i = 0; i < talked.length; i++){ - if(!talked[i]){ - nextToTalk = i; - break; - } - } - for(Actor a : actors){ - if(a instanceof MovingNpc){ - if(((MovingNpc)a).id == informationNpcId[nextToTalk] && ((MovingNpc)a).mapId == informationNpcMapId[nextToTalk]){ - if(((MovingNpc)a).currentlyTalking){ - talked[nextToTalk] = true; - break; - } - } - } - } - } - else{ - for(Actor a : actors){ - if(a instanceof MovingNpc){ - for(int i = 0; i < informationNpcId.length; i++){ - if(((MovingNpc)a).id == informationNpcId[i] && ((MovingNpc)a).mapId == informationNpcMapId[i]){ - if(((MovingNpc)a).currentlyTalking){ - talked[i] = true; - break; - } - } - } - } - } - } - - boolean finished = true; + finished = true; for(int i = 0; i < talked.length; i++){ if(!talked[i]){ finished = false; break; } } - this.finished = finished; } } diff --git a/core/src/com/trs/main/Main.java b/core/src/com/trs/main/Main.java index 6ddbb10..20ab33b 100644 --- a/core/src/com/trs/main/Main.java +++ b/core/src/com/trs/main/Main.java @@ -51,7 +51,7 @@ public class Main extends Game{ } Gdx.gl.glClearColor(0f, (0), (0), 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - + switch(gamestate){ case 7: if(menuScreen.getPaused()){ diff --git a/core/src/com/trs/main/MapContainer.java b/core/src/com/trs/main/MapContainer.java index c863fe9..c6e27b0 100644 --- a/core/src/com/trs/main/MapContainer.java +++ b/core/src/com/trs/main/MapContainer.java @@ -41,13 +41,15 @@ import com.badlogic.gdx.utils.viewport.FitViewport; public class MapContainer { - Stage stage; - OrthographicCamera camera; - TmxMapLoader maploader; + Stage stage; + OrthographicCamera camera; + TmxMapLoader maploader; TiledMap map; OrthogonalTiledMapRenderer renderer; - Door[] doors; - public Door collidingDoor; + Door[] doors; + public Door collidingDoor; + + TransitionScreen t; final int[] layersBelowPlayer = {0, 1, 2}; final int[] layersAbovePlayer = {3, 4}; @@ -61,6 +63,9 @@ public class MapContainer { stage = new Stage(new FitViewport(CAMERA_WIDTH, CAMERA_HEIGHT, camera)); Gdx.input.setInputProcessor(stage); + //TRANSITION SCREEN + t = new TransitionScreen(); + //CREATION OF TILEDMAP maploader = new TmxMapLoader(); @@ -206,6 +211,12 @@ public class MapContainer { break; } } + if(t != null){ + t.draw(stage.getBatch(), stage.getCamera().position.x, stage.getCamera().position.y, stage.getCamera().combined); + if(t.opacity == 0){ + t = null; + } + } } public void resize(int width, int height){ diff --git a/core/src/com/trs/main/Player.java b/core/src/com/trs/main/Player.java index f7e4cfd..81cc7f4 100644 --- a/core/src/com/trs/main/Player.java +++ b/core/src/com/trs/main/Player.java @@ -12,6 +12,9 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.Group; +import com.badlogic.gdx.utils.Array; +import java.util.ArrayList; /** * * @@ -30,10 +33,12 @@ public class Player extends Actor{ // 0: up, 1: left, 2: down, 3: right int facing = 0; - InformationQuest quest; + ArrayList quests; Rectangle collisionRect; + Group questGroup; + public Player(int xPos, int yPos){ setName("player"); t = new Texture(Gdx.files.internal("textureData/sprites/player.png")); @@ -41,11 +46,12 @@ public class Player extends Actor{ playerSprite.setRow(0); collisionRect = new Rectangle(xPos + 16, yPos, 32, 16); setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight()); - + quests = new ArrayList<>(); int[] n = {1, 1}; int[] m = {1, 0}; - quest = new InformationQuest(0, "Sprich mit Folgenden NPCs: (Id, mapId, schonGereded?) !Reihenfolge wichtig!", m, n, true); + quests.add(new InformationQuest(0, "Sprich mit Folgenden NPCs: (Id, mapId, schonGereded?) !Reihenfolge wichtig!", m, n, true)); + quests.add(new InformationQuest(1, "jajajaj nicenicenice", m, n, true)); } @Override @@ -59,6 +65,13 @@ public class Player extends Actor{ @Override public void act(float delta) { + + for(Quest quest : quests){ + quest.print(); + System.out.println(); + } + System.out.println(); + if(Main.gamestate == 0) { if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){ speed = 9; @@ -92,14 +105,21 @@ public class Player extends Actor{ if(a != null) { if(a instanceof MovingNpc){ Main.gamestate = 1; - if(quest instanceof InformationQuest){ - if(((InformationQuest)quest).hasSpecialDialogue(((MovingNpc) a).id, ((MovingNpc) a).mapId)){ - ((MovingNpc) a).startSpecialDialogue(((InformationQuest)quest).getDialoguePath(((MovingNpc) a).id, ((MovingNpc) a).mapId), getX()+32, getY()+32); - } - else{ - ((MovingNpc)a).startDialogue(getX()+32, getY()+32); + boolean dialogueStarted = false; + for(Quest quest : quests){ + if(quest instanceof InformationQuest){ + if(((InformationQuest)quest).hasSpecialDialogue(((MovingNpc) a).id, ((MovingNpc) a).mapId)){ + ((MovingNpc) a).startSpecialDialogue(((InformationQuest)quest).getDialoguePath(((MovingNpc) a).id, ((MovingNpc) a).mapId), getX()+32, getY()+32); + ((InformationQuest) quest).talk((MovingNpc)a); + dialogueStarted = true; + break; + } + } } + if(!dialogueStarted){ + ((MovingNpc)a).startDialogue(getX()+32, getY()+32); } + movementX = 0; movementY = 0; } @@ -159,14 +179,14 @@ public class Player extends Actor{ playerSprite.updateAnimation(delta); super.act(delta); //To change body of generated methods, choose Tools | Templates. - /* System.out.println("--"); - System.out.println(quest.questText); - quest.updateQuest(getStage().getActors()); - quest.print(); - System.out.println(quest.finished); + for(Quest quest : quests){ + quest.updateQuest(); + quest.print(); System.out.println("--"); - */ + } + System.out.println("--"); + } diff --git a/core/src/com/trs/main/Quest.java b/core/src/com/trs/main/Quest.java index 14b4df8..7cbb448 100644 --- a/core/src/com/trs/main/Quest.java +++ b/core/src/com/trs/main/Quest.java @@ -20,6 +20,7 @@ public abstract class Quest { - abstract void updateQuest(Array actors); + abstract void updateQuest(); abstract boolean finished(); + abstract void print(); } diff --git a/core/src/com/trs/main/TransitionScreen.java b/core/src/com/trs/main/TransitionScreen.java new file mode 100644 index 0000000..1d88888 --- /dev/null +++ b/core/src/com/trs/main/TransitionScreen.java @@ -0,0 +1,50 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.trs.main; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.scenes.scene2d.Actor; + +/** + * + * @author janeh + */ +public class TransitionScreen{ + + ShapeRenderer renderer; + float opacity = 1f; + + public TransitionScreen() { + super(); + renderer = new ShapeRenderer(); + } + + + public void draw(Batch batch, float x, float y, Matrix4 m) { + renderer.setProjectionMatrix(m); + if(opacity - 0.05f > 0){ + opacity -= 0.05f; + } + else opacity = 0; + renderer.setColor(0, 0, 0, opacity); + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.rect(x - Main.CAMERA_WIDTH/2, y- Main.CAMERA_HEIGHT/2, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT); + renderer.end(); + Gdx.gl.glDisable(GL20.GL_BLEND); + + } + + +}