From 4dbc1407c07a9c5fdf7736da85952c7ca2a6af01 Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Mon, 28 Dec 2020 11:25:55 +0100 Subject: [PATCH] first quest added -> You have to get Information by talking to certain npcs - Interaction objects can go without extra Sprite now by naming the Texture of the InteractionObject '-' inside Tiled --- core/src/com/trs/main/InformationQuest.java | 118 ++++++++++++++++++++ core/src/com/trs/main/Main.java | 18 +-- core/src/com/trs/main/MapContainer.java | 16 +-- core/src/com/trs/main/MovingNpc.java | 5 +- core/src/com/trs/main/Player.java | 14 +++ core/src/com/trs/main/Quest.java | 25 +++++ 6 files changed, 178 insertions(+), 18 deletions(-) create mode 100644 core/src/com/trs/main/InformationQuest.java create mode 100644 core/src/com/trs/main/Quest.java diff --git a/core/src/com/trs/main/InformationQuest.java b/core/src/com/trs/main/InformationQuest.java new file mode 100644 index 0000000..d58e047 --- /dev/null +++ b/core/src/com/trs/main/InformationQuest.java @@ -0,0 +1,118 @@ +/* + * 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.scenes.scene2d.Actor; +import com.badlogic.gdx.utils.Array; + +/** + * + * What is this Quest? + * + * This quest is simply about talking. For tesing purposes this Quest only safes one certain Npc. + * As soon as you are talking to him this quest is counting as finished + * + */ +public class InformationQuest extends Quest{ + + int[] informationNpcId; + int[] informationNpcMapId; + boolean[] talked; + + int questId; + + boolean rightOrderRequired; + + InformationQuest(int questId, String questText/*, Quest[] followingQuest*/, int[] informationNpcId, int[] informationNpcMapId, boolean rightOrderRequired){ + + this.questId = questId; + + this.informationNpcId = informationNpcId; + this.informationNpcMapId = informationNpcMapId; + + talked = new boolean[informationNpcId.length]; + for(int i = 0; i < informationNpcId.length; i++){ + talked[i] = false; + } + this.rightOrderRequired = rightOrderRequired; + + 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]; + } + this.followingQuest = new InformationQuest(); + } + */ + } + + @Override + void updateQuest(Array actors) { + 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; + for(int i = 0; i < talked.length; i++){ + if(!talked[i]){ + finished = false; + break; + } + } + this.finished = finished; + } + } + + public void print(){ + for(int i = 0; i < informationNpcId.length; i++){ + System.out.print(informationNpcId[i] + " "); + System.out.print(informationNpcMapId[i] + " "); + System.out.print(talked[i] + " "); + System.out.println(); + } + } + + @Override + boolean finished() { + return finished; + } + +} diff --git a/core/src/com/trs/main/Main.java b/core/src/com/trs/main/Main.java index 2041941..f8ea88f 100644 --- a/core/src/com/trs/main/Main.java +++ b/core/src/com/trs/main/Main.java @@ -10,19 +10,19 @@ import com.trs.main.view.screens.MenuScreen; public class Main extends Game{ /** - * TODO: set final Value for World + * TODO: set final Value for World */ // TEST // 0: normal game world, 1: dialogue, 2: fight // 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen - public static int gamestate = 0; - public static float CAMERA_WIDTH = 1280; - public static float CAMERA_HEIGHT = 720; - - MenuScreen menuScreen; - GameScreen gameScreen; - InventoryScreen inventoryScreen; + public static int gamestate = 0; + public static float CAMERA_WIDTH = 854; + public static float CAMERA_HEIGHT = 480; + + MenuScreen menuScreen; + GameScreen gameScreen; + InventoryScreen inventoryScreen; @@ -32,7 +32,7 @@ public class Main extends Game{ gameScreen = new GameScreen(this, CAMERA_WIDTH, CAMERA_HEIGHT); inventoryScreen = new InventoryScreen(this, CAMERA_WIDTH, CAMERA_HEIGHT); - screen = gameScreen; + screen = gameScreen; } @Override diff --git a/core/src/com/trs/main/MapContainer.java b/core/src/com/trs/main/MapContainer.java index 43ce50b..93ca9ea 100644 --- a/core/src/com/trs/main/MapContainer.java +++ b/core/src/com/trs/main/MapContainer.java @@ -124,7 +124,7 @@ public class MapContainer { doors[i] = tempDoors.get(i); if(i == inDoor) { int facing = doors[i].exit; - + System.out.println(i + " " + inDoor); switch(facing) { case 0: p.setPosition(doors[i].rect.x, doors[i].rect.y + doors[i].rect.height); @@ -160,13 +160,13 @@ public class MapContainer { } for(Actor a : stage.getActors()) { if(a instanceof Player) { - Rectangle rect = ((Player) a).collisionRect; - - for(Door d : doors) { - if(Intersector.overlaps(rect, d.rect)) { - collidingDoor = d; - break; - } + Rectangle rect = ((Player) a).collisionRect; + + for(Door d : doors) { + if(Intersector.overlaps(rect, d.rect)) { + collidingDoor = d; + break; + } } } } diff --git a/core/src/com/trs/main/MovingNpc.java b/core/src/com/trs/main/MovingNpc.java index 1b0b946..55d96ae 100644 --- a/core/src/com/trs/main/MovingNpc.java +++ b/core/src/com/trs/main/MovingNpc.java @@ -19,6 +19,9 @@ import com.badlogic.gdx.scenes.scene2d.Actor; */ public class MovingNpc extends Actor{ + public final int mapId; + public final int id; + public static final float SQRT2 = 1.414f; Textbox t; Rectangle area; @@ -35,12 +38,12 @@ public class MovingNpc extends Actor{ Vector2 POI; - int id; String dialoguePath; public MovingNpc(Rectangle area, float xPos, float yPos, int id, int mapId, String texture){ setName("npc"); this.id = id; + this.mapId = mapId; Texture t = new Texture(Gdx.files.internal("textureData/sprites/"+texture)); currentlyTalking = false; diff --git a/core/src/com/trs/main/Player.java b/core/src/com/trs/main/Player.java index c8d4854..63fedce 100644 --- a/core/src/com/trs/main/Player.java +++ b/core/src/com/trs/main/Player.java @@ -30,6 +30,8 @@ public class Player extends Actor{ // 0: up, 1: left, 2: down, 3: right int facing = 0; + InformationQuest quest; + Rectangle collisionRect; public Player(int xPos, int yPos){ @@ -39,6 +41,11 @@ 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()); + + + int[] n = {1, 1}; + int[] m = {1, 0}; + quest = new InformationQuest(0, "Sprich mit Folgenden NPCs: (Id, mapId, schonGereded?) !Reihenfolge wichtig!", m, n, true); } @Override @@ -145,6 +152,13 @@ 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); + System.out.println("--"); + } @Override diff --git a/core/src/com/trs/main/Quest.java b/core/src/com/trs/main/Quest.java new file mode 100644 index 0000000..14b4df8 --- /dev/null +++ b/core/src/com/trs/main/Quest.java @@ -0,0 +1,25 @@ +/* + * 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.scenes.scene2d.Actor; +import com.badlogic.gdx.utils.Array; + +/** + * + * @author janeh + */ +public abstract class Quest { + + String questText; + boolean finished; + Quest followingQuest; + + + + abstract void updateQuest(Array actors); + abstract boolean finished(); +}