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

@ -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()){

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

@ -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<Quest> 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("--");
}

@ -20,6 +20,7 @@ public abstract class Quest {
abstract void updateQuest(Array<Actor> actors);
abstract void updateQuest();
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