Player can now have multiple quests, Transition when changing map added

master
GammelJAN 5 years ago
parent 664a4baf71
commit a8559b7420

@ -26,7 +26,7 @@ public class InformationQuest extends Quest{
boolean rightOrderRequired; 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; this.questId = questId;
@ -41,20 +41,20 @@ public class InformationQuest extends Quest{
this.questText = questText; this.questText = questText;
/* TODO: More quest inside on Quest-string }
if(followingQuest.length > 1){ void talk(MovingNpc a){
Quest[] nextQuests = new Quest[followingQuest.length-1]; for(int i = 0; i < talked.length; i++){
for(int i = 1; i < followingQuest.length; i++){ if(informationNpcId[i] == a.id && informationNpcMapId[i] == a.mapId){
nextQuests[i-1] = followingQuest[i]; talked[i] = true;
break;
} }
this.followingQuest = new InformationQuest();
} }
*/
} }
boolean hasSpecialDialogue(int NpcId, int mapId){ boolean hasSpecialDialogue(int NpcId, int mapId){
if(!finished){
if(!rightOrderRequired){ if(!rightOrderRequired){
for(int i = 0; i < talked.length; i++){ for(int i = 0; i < talked.length; i++){
if(informationNpcId[i] == NpcId && informationNpcMapId[i] == mapId && !talked[i]){ if(informationNpcId[i] == NpcId && informationNpcMapId[i] == mapId && !talked[i]){
@ -76,56 +76,23 @@ public class InformationQuest extends Quest{
} }
return false; return false;
} }
else return false;
}
String getDialoguePath(int NpcId, int mapId){ String getDialoguePath(int NpcId, int mapId){
return "quests/informationQuests/"+questId+"/dialogues/map"+mapId+"/npc"+NpcId+"/dialogue.txt"; return "quests/informationQuests/"+questId+"/dialogues/map"+mapId+"/npc"+NpcId+"/dialogue.txt";
} }
@Override @Override
void updateQuest(Array<Actor> actors) { void updateQuest() {
if(!finished){ if(!finished){
if(rightOrderRequired){ finished = true;
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++){ for(int i = 0; i < talked.length; i++){
if(!talked[i]){ if(!talked[i]){
finished = false; finished = false;
break; break;
} }
} }
this.finished = finished;
} }
} }

@ -49,6 +49,8 @@ public class MapContainer {
Door[] doors; Door[] doors;
public Door collidingDoor; public Door collidingDoor;
TransitionScreen t;
final int[] layersBelowPlayer = {0, 1, 2}; final int[] layersBelowPlayer = {0, 1, 2};
final int[] layersAbovePlayer = {3, 4}; final int[] layersAbovePlayer = {3, 4};
@ -61,6 +63,9 @@ public class MapContainer {
stage = new Stage(new FitViewport(CAMERA_WIDTH, CAMERA_HEIGHT, camera)); stage = new Stage(new FitViewport(CAMERA_WIDTH, CAMERA_HEIGHT, camera));
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
//TRANSITION SCREEN
t = new TransitionScreen();
//CREATION OF TILEDMAP //CREATION OF TILEDMAP
maploader = new TmxMapLoader(); maploader = new TmxMapLoader();
@ -206,6 +211,12 @@ public class MapContainer {
break; 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){ public void resize(int width, int height){

@ -12,6 +12,9 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor; 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 // 0: up, 1: left, 2: down, 3: right
int facing = 0; int facing = 0;
InformationQuest quest; ArrayList<Quest> quests;
Rectangle collisionRect; Rectangle collisionRect;
Group questGroup;
public Player(int xPos, int yPos){ public Player(int xPos, int yPos){
setName("player"); setName("player");
t = new Texture(Gdx.files.internal("textureData/sprites/player.png")); t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
@ -41,11 +46,12 @@ public class Player extends Actor{
playerSprite.setRow(0); playerSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16); collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight()); setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
quests = new ArrayList<>();
int[] n = {1, 1}; int[] n = {1, 1};
int[] m = {1, 0}; 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 @Override
@ -59,6 +65,13 @@ public class Player extends Actor{
@Override @Override
public void act(float delta) { public void act(float delta) {
for(Quest quest : quests){
quest.print();
System.out.println();
}
System.out.println();
if(Main.gamestate == 0) { if(Main.gamestate == 0) {
if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){ if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){
speed = 9; speed = 9;
@ -92,14 +105,21 @@ public class Player extends Actor{
if(a != null) { if(a != null) {
if(a instanceof MovingNpc){ if(a instanceof MovingNpc){
Main.gamestate = 1; Main.gamestate = 1;
boolean dialogueStarted = false;
for(Quest quest : quests){
if(quest instanceof InformationQuest){ if(quest instanceof InformationQuest){
if(((InformationQuest)quest).hasSpecialDialogue(((MovingNpc) a).id, ((MovingNpc) a).mapId)){ 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); ((MovingNpc) a).startSpecialDialogue(((InformationQuest)quest).getDialoguePath(((MovingNpc) a).id, ((MovingNpc) a).mapId), getX()+32, getY()+32);
((InformationQuest) quest).talk((MovingNpc)a);
dialogueStarted = true;
break;
} }
else{
((MovingNpc)a).startDialogue(getX()+32, getY()+32);
} }
} }
if(!dialogueStarted){
((MovingNpc)a).startDialogue(getX()+32, getY()+32);
}
movementX = 0; movementX = 0;
movementY = 0; movementY = 0;
} }
@ -159,14 +179,14 @@ public class Player extends Actor{
playerSprite.updateAnimation(delta); playerSprite.updateAnimation(delta);
super.act(delta); //To change body of generated methods, choose Tools | Templates. super.act(delta); //To change body of generated methods, choose Tools | Templates.
/*
System.out.println("--"); System.out.println("--");
System.out.println(quest.questText); for(Quest quest : quests){
quest.updateQuest(getStage().getActors()); quest.updateQuest();
quest.print(); quest.print();
System.out.println(quest.finished);
System.out.println("--"); System.out.println("--");
*/ }
System.out.println("--");
} }

@ -20,6 +20,7 @@ public abstract class Quest {
abstract void updateQuest(Array<Actor> actors); abstract void updateQuest();
abstract boolean finished(); abstract boolean finished();
abstract void print();
} }

@ -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);
}
}
Loading…
Cancel
Save