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

master
GammelJAN 5 years ago
parent a8f453a2f4
commit 4dbc1407c0

@ -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<Actor> 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;
}
}

@ -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

@ -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;
}
}
}
}

@ -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;

@ -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

@ -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<Actor> actors);
abstract boolean finished();
}
Loading…
Cancel
Save