master
parent
72ce42edc8
commit
f0ceece9aa
@ -1,6 +1,6 @@
|
||||
package com.trs.main;
|
||||
|
||||
public class Dialogue {
|
||||
String question;
|
||||
String[] ans;
|
||||
public String question;
|
||||
public String[] ans;
|
||||
}
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
package com.trs.main;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
public abstract class FightObject {
|
||||
protected AnimatedSprite sprite;
|
||||
protected Stats stats;
|
||||
protected int id;
|
||||
protected float x;
|
||||
protected float y;
|
||||
protected Vector2 POI;
|
||||
protected int moves;
|
||||
protected int maxMoves;
|
||||
|
||||
// 0: waiting 1: doing action 2: finished action
|
||||
protected int state = 0;
|
||||
|
||||
public FightObject(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
|
||||
this.sprite = sprite;
|
||||
this.stats = stats;
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
maxMoves = 2;
|
||||
moves = maxMoves;
|
||||
}
|
||||
|
||||
void setX(float x) {
|
||||
this.x = x;
|
||||
this.sprite.setSpritePosition((int)this.x, (int)this.y);
|
||||
}
|
||||
|
||||
void setY(float y) {
|
||||
this.y = y;
|
||||
this.sprite.setSpritePosition((int)this.x, (int)this.y);
|
||||
}
|
||||
|
||||
void attack(FightObject o) {
|
||||
if(o != null) {
|
||||
o.stats.setHp(o.stats.getHp() - stats.getAtk());
|
||||
}
|
||||
}
|
||||
|
||||
public void startAction() {
|
||||
state = 1;
|
||||
moves = maxMoves;
|
||||
}
|
||||
}
|
||||
@ -1,125 +0,0 @@
|
||||
package com.trs.main;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Circle;
|
||||
import com.badlogic.gdx.math.Intersector;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
public class Hostile extends Actor {
|
||||
|
||||
int id;
|
||||
Stats stats;
|
||||
AnimatedSprite sprite;
|
||||
Rectangle collisionRect;
|
||||
Circle attackCircle;
|
||||
Circle attentionCircle;
|
||||
boolean isMelee;
|
||||
|
||||
// 0: normal movement, 1: locked onto Player, 2: attacking
|
||||
int movementState;
|
||||
|
||||
public Hostile(float xPos, float yPos, int id, Stats stats, String texture, boolean isMelee) {
|
||||
|
||||
this.id = id;
|
||||
this.stats = stats;
|
||||
this.isMelee = isMelee;
|
||||
|
||||
Texture tx = new Texture(Gdx.files.internal("textureData/sprites/" + texture));
|
||||
sprite = new AnimatedSprite(tx, 64, 64, true);
|
||||
|
||||
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
|
||||
attackCircle = new Circle(xPos + 16, yPos, 100f);
|
||||
attentionCircle = new Circle(xPos + 16, yPos, 300f);
|
||||
|
||||
movementState = 0;
|
||||
|
||||
setX(xPos);
|
||||
setY(yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float deltatime) {
|
||||
sprite.updateAnimation(deltatime);
|
||||
|
||||
if(movementState == 0) {
|
||||
for(Actor a : getStage().getActors()) {
|
||||
if(a instanceof Player) {
|
||||
if(Intersector.overlaps(attentionCircle, ((Player) a).collisionRect)) {
|
||||
movementState = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(movementState == 1) {
|
||||
for(Actor a : getStage().getActors()) {
|
||||
if(a instanceof Player) {
|
||||
if(Intersector.overlaps(attackCircle, ((Player) a).collisionRect)) {
|
||||
movementState = 2;
|
||||
}
|
||||
if(!Intersector.overlaps(attentionCircle, ((Player) a).collisionRect)) {
|
||||
movementState = 0;
|
||||
}
|
||||
|
||||
|
||||
Vector2 POI = new Vector2(a.getX(), a.getY());
|
||||
float speed = 2;
|
||||
|
||||
Vector2 movement = new Vector2(speed,0);
|
||||
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
|
||||
int facing;
|
||||
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
|
||||
facing = 0;
|
||||
}
|
||||
else if(movement.angleDeg() >= 135 && movement.angleDeg() < 225) {
|
||||
facing = 1;
|
||||
}
|
||||
else if(movement.angleDeg() >= 225 && movement.angleDeg() < 315) {
|
||||
facing = 2;
|
||||
}
|
||||
else {
|
||||
facing = 3;
|
||||
}
|
||||
|
||||
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y) < 1f) {
|
||||
movement.x = 0;
|
||||
movement.y = 0;
|
||||
}
|
||||
|
||||
setX(getX() + movement.x);
|
||||
setY(getY() + movement.y);
|
||||
|
||||
int animationRow = 0;
|
||||
if(movement.x != 0 || movement.y != 0) {
|
||||
animationRow = 8;
|
||||
}
|
||||
|
||||
sprite.setRow(animationRow + facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(movementState == 2) {
|
||||
Main.gamestate = 2;
|
||||
//System.out.println("Kämpfe mit mir du Spast!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float deltatime) {
|
||||
sprite.draw(batch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void positionChanged() {
|
||||
sprite.setSpritePosition((int)getX(), (int)getY());
|
||||
collisionRect = new Rectangle(getX() + 16, getY(), 32, 16);
|
||||
attackCircle = new Circle(getX() + 16, getY(), 100f);
|
||||
attentionCircle = new Circle(getX() + 16, getY(), 300f);
|
||||
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
@ -1,263 +0,0 @@
|
||||
/*
|
||||
* 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.Input;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
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;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Jan
|
||||
*/
|
||||
public class Player extends Actor{
|
||||
|
||||
public static final float SQRT2 = 1.414f;
|
||||
|
||||
Texture t;
|
||||
AnimatedSprite playerSprite;
|
||||
float movementX = 0;
|
||||
float movementY = 0;
|
||||
float speed = 3f;
|
||||
float velocity = 0.5f;
|
||||
// 0: up, 1: left, 2: down, 3: right
|
||||
int facing = 0;
|
||||
|
||||
ArrayList<Quest> quests;
|
||||
|
||||
Rectangle collisionRect;
|
||||
|
||||
Group questGroup;
|
||||
|
||||
Stats stats;
|
||||
|
||||
public Player(int xPos, int yPos){
|
||||
setName("player");
|
||||
t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
|
||||
playerSprite = new AnimatedSprite(t, 64, 64, true);
|
||||
playerSprite.setRow(0);
|
||||
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
|
||||
setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
|
||||
quests = new ArrayList<>();
|
||||
|
||||
stats = new Stats();
|
||||
|
||||
//TEST QUESTS
|
||||
int[] n = {1, 1};
|
||||
int[] m = {1, 0};
|
||||
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, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void positionChanged() {
|
||||
playerSprite.setSpritePosition((int)getX(), (int)getY());
|
||||
collisionRect = new Rectangle(getX() + 16, getY(), 32, 16);
|
||||
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
|
||||
// TEST QUESTS
|
||||
for(Quest quest : quests){
|
||||
//quest.print();
|
||||
//System.out.println();
|
||||
}
|
||||
//System.out.println();
|
||||
|
||||
// QUEST HANDLING
|
||||
for(Quest quest : quests){
|
||||
quest.updateQuest();
|
||||
}
|
||||
|
||||
// PLAYER ACTING
|
||||
if(Main.gamestate == 0) {
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){
|
||||
speed = 9;
|
||||
}
|
||||
else speed = 3;
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.D)){
|
||||
movementX = speed;
|
||||
facing = 3;
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.A)){
|
||||
movementX = -speed;
|
||||
facing = 1;
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.W)){
|
||||
movementY = speed;
|
||||
facing = 0;
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.S)){
|
||||
movementY = -speed;
|
||||
facing = 2;
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.NUM_1)){
|
||||
movementY = -8;
|
||||
}
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
|
||||
Main.gamestate = 9;
|
||||
}
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.E)) {
|
||||
Actor a = collidingActor();
|
||||
if(a != null) {
|
||||
if(a instanceof MovingNpc){
|
||||
Main.gamestate = 1;
|
||||
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;
|
||||
}
|
||||
else if(a instanceof InteractionObject) {
|
||||
Main.gamestate = 1;
|
||||
((InteractionObject)a).startDialogue(getX()+32, getY()+32);
|
||||
movementX = 0;
|
||||
movementY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Main.gamestate == 1) {
|
||||
// Input handled by invoked textbox
|
||||
}
|
||||
|
||||
// MOVEMENT HANDLING
|
||||
if(movementX == 0 && movementY == 0){
|
||||
|
||||
}
|
||||
else if(movementX == 0 && movementY != 0){
|
||||
setY(getY()+movementY);
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setY(getY()-movementY);
|
||||
}
|
||||
}
|
||||
else if(movementY == 0 && movementX != 0){
|
||||
setX(getX()+movementX);
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setX(getX()-movementX);
|
||||
}
|
||||
}
|
||||
else if(movementX != 0 && movementY != 0){
|
||||
setX(getX()+ (movementX / SQRT2));
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setX(getX() - (movementX / SQRT2));
|
||||
}
|
||||
|
||||
setY(getY() + (movementY / SQRT2));
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setY(getY()- (movementY / SQRT2));
|
||||
}
|
||||
}
|
||||
velocity(velocity);
|
||||
|
||||
// ANIMATION HANDLING
|
||||
int animationRow = 0;
|
||||
if(movementX != 0 || movementY != 0) {
|
||||
animationRow = 8;
|
||||
}
|
||||
playerSprite.setRow(animationRow + facing);
|
||||
playerSprite.updateAnimation(delta);
|
||||
|
||||
super.act(delta); //To change body of generated methods, choose Tools | Templates.
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
playerSprite.draw(batch);
|
||||
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
return super.remove(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public boolean collidingWithMapCollisionObject(){
|
||||
for(Actor a : getStage().getActors()){
|
||||
if(a instanceof MapCollisionObject){
|
||||
Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
|
||||
if(Intersector.overlaps(collisionRect, o)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(a instanceof MovingNpc){
|
||||
if(Intersector.overlaps(collisionRect, ((MovingNpc)a).collisionRect)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Slowing the players movement by velocity
|
||||
public void velocity(float velocity){
|
||||
if(movementX > 0){
|
||||
movementX -= velocity;
|
||||
if(movementX < 0){
|
||||
movementX = 0;
|
||||
}
|
||||
}
|
||||
else if(movementX < 0){
|
||||
movementX += velocity;
|
||||
if(movementX > 0){
|
||||
movementX = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(movementY > 0){
|
||||
movementY -= velocity;
|
||||
if(movementY < 0){
|
||||
movementY = 0;
|
||||
}
|
||||
}
|
||||
else if(movementY < 0){
|
||||
movementY += velocity;
|
||||
if(movementY > 0){
|
||||
movementY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Actor collidingActor(){
|
||||
for(Actor a : getStage().getActors()){
|
||||
if(a instanceof InteractionObject || a instanceof MovingNpc){
|
||||
Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight());
|
||||
Rectangle npc = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
|
||||
if(Intersector.overlaps(p, npc)){
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
package com.trs.main.fightscreen;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.trs.main.worldobjects.AnimatedSprite;
|
||||
import com.trs.main.Stats;
|
||||
|
||||
public abstract class FightObject {
|
||||
private AnimatedSprite sprite;
|
||||
private Stats stats;
|
||||
private int id;
|
||||
private float x;
|
||||
private float y;
|
||||
private Vector2 POI;
|
||||
private int moves;
|
||||
private int maxMoves;
|
||||
|
||||
// 0: waiting 1: doing action 2: finished action
|
||||
private int state = 0;
|
||||
|
||||
public FightObject(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
|
||||
this.sprite = sprite;
|
||||
this.stats = stats;
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
maxMoves = 2;
|
||||
moves = maxMoves;
|
||||
}
|
||||
|
||||
void setX(float x) {
|
||||
this.x = x;
|
||||
this.getSprite().setSpritePosition((int)this.x, (int)this.getY());
|
||||
}
|
||||
|
||||
void setY(float y) {
|
||||
this.y = y;
|
||||
this.getSprite().setSpritePosition((int)this.getX(), (int)this.y);
|
||||
}
|
||||
|
||||
void attack(FightObject o) {
|
||||
if(o != null) {
|
||||
o.getStats().setHp(o.getStats().getHp() - getStats().getAtk());
|
||||
}
|
||||
}
|
||||
|
||||
public float getX(){
|
||||
return x;
|
||||
}
|
||||
public float getY(){
|
||||
return y;
|
||||
}
|
||||
|
||||
public Stats getStats(){
|
||||
return stats;
|
||||
}
|
||||
public void setStats(Stats stats){
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
public void startAction() {
|
||||
setState(1);
|
||||
setMoves(getMaxMoves());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sprite
|
||||
*/
|
||||
public AnimatedSprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sprite the sprite to set
|
||||
*/
|
||||
public void setSprite(AnimatedSprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the POI
|
||||
*/
|
||||
public Vector2 getPOI() {
|
||||
return POI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param POI the POI to set
|
||||
*/
|
||||
public void setPOI(Vector2 POI) {
|
||||
this.POI = POI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the moves
|
||||
*/
|
||||
public int getMoves() {
|
||||
return moves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param moves the moves to set
|
||||
*/
|
||||
public void setMoves(int moves) {
|
||||
this.moves = moves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxMoves
|
||||
*/
|
||||
public int getMaxMoves() {
|
||||
return maxMoves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxMoves the maxMoves to set
|
||||
*/
|
||||
public void setMaxMoves(int maxMoves) {
|
||||
this.maxMoves = maxMoves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state
|
||||
*/
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state the state to set
|
||||
*/
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
package com.trs.main;
|
||||
package com.trs.main.fightscreen;
|
||||
|
||||
import com.trs.main.worldobjects.AnimatedSprite;
|
||||
import com.trs.main.Stats;
|
||||
|
||||
public class FightPlayer extends FightObject{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.trs.main;
|
||||
package com.trs.main.worldobjects;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
@ -0,0 +1,242 @@
|
||||
package com.trs.main.worldobjects;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Circle;
|
||||
import com.badlogic.gdx.math.Intersector;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.trs.main.Main;
|
||||
import com.trs.main.StaticMath;
|
||||
import com.trs.main.Stats;
|
||||
|
||||
public class Hostile extends Actor {
|
||||
|
||||
private int id;
|
||||
private Stats stats;
|
||||
private AnimatedSprite sprite;
|
||||
private Rectangle collisionRect;
|
||||
private Circle attackCircle;
|
||||
private Circle attentionCircle;
|
||||
private boolean isMelee;
|
||||
|
||||
// 0: normal movement, 1: locked onto Player, 2: attacking
|
||||
private int movementState;
|
||||
|
||||
public Hostile(float xPos, float yPos, int id, Stats stats, String texture, boolean isMelee) {
|
||||
|
||||
this.id = id;
|
||||
this.stats = stats;
|
||||
this.isMelee = isMelee;
|
||||
|
||||
Texture tx = new Texture(Gdx.files.internal("textureData/sprites/" + texture));
|
||||
sprite = new AnimatedSprite(tx, 64, 64, true);
|
||||
|
||||
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
|
||||
attackCircle = new Circle(xPos + 16, yPos, 100f);
|
||||
attentionCircle = new Circle(xPos + 16, yPos, 300f);
|
||||
|
||||
movementState = 0;
|
||||
|
||||
setX(xPos);
|
||||
setY(yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float deltatime) {
|
||||
getSprite().updateAnimation(deltatime);
|
||||
|
||||
if(getMovementState() == 0) {
|
||||
for(Actor a : getStage().getActors()) {
|
||||
if(a instanceof Player) {
|
||||
if(Intersector.overlaps(getAttentionCircle(), ((Player) a).getCollisionRect())) {
|
||||
setMovementState(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(getMovementState() == 1) {
|
||||
for(Actor a : getStage().getActors()) {
|
||||
if(a instanceof Player) {
|
||||
if(Intersector.overlaps(getAttackCircle(), ((Player) a).getCollisionRect())) {
|
||||
setMovementState(2);
|
||||
}
|
||||
if(!Intersector.overlaps(attentionCircle, ((Player) a).getCollisionRect())) {
|
||||
setMovementState(0);
|
||||
}
|
||||
|
||||
|
||||
Vector2 POI = new Vector2(a.getX(), a.getY());
|
||||
float speed = 2;
|
||||
|
||||
Vector2 movement = new Vector2(speed,0);
|
||||
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
|
||||
int facing;
|
||||
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
|
||||
facing = 0;
|
||||
}
|
||||
else if(movement.angleDeg() >= 135 && movement.angleDeg() < 225) {
|
||||
facing = 1;
|
||||
}
|
||||
else if(movement.angleDeg() >= 225 && movement.angleDeg() < 315) {
|
||||
facing = 2;
|
||||
}
|
||||
else {
|
||||
facing = 3;
|
||||
}
|
||||
|
||||
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y) < 1f) {
|
||||
movement.x = 0;
|
||||
movement.y = 0;
|
||||
}
|
||||
|
||||
setX(getX() + movement.x);
|
||||
setY(getY() + movement.y);
|
||||
|
||||
int animationRow = 0;
|
||||
if(movement.x != 0 || movement.y != 0) {
|
||||
animationRow = 8;
|
||||
}
|
||||
|
||||
getSprite().setRow(animationRow + facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(getMovementState() == 2) {
|
||||
Main.gamestate = 2;
|
||||
//System.out.println("Kämpfe mit mir du Spast!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float deltatime) {
|
||||
getSprite().draw(batch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void positionChanged() {
|
||||
getSprite().setSpritePosition((int)getX(), (int)getY());
|
||||
setCollisionRect(new Rectangle(getX() + 16, getY(), 32, 16));
|
||||
setAttackCircle(new Circle(getX() + 16, getY(), 100f));
|
||||
setAttentionCircle(new Circle(getX() + 16, getY(), 300f));
|
||||
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stats
|
||||
*/
|
||||
public Stats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stats the stats to set
|
||||
*/
|
||||
public void setStats(Stats stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sprite
|
||||
*/
|
||||
public AnimatedSprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sprite the sprite to set
|
||||
*/
|
||||
public void setSprite(AnimatedSprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the collisionRect
|
||||
*/
|
||||
public Rectangle getCollisionRect() {
|
||||
return collisionRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param collisionRect the collisionRect to set
|
||||
*/
|
||||
public void setCollisionRect(Rectangle collisionRect) {
|
||||
this.collisionRect = collisionRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the attackCircle
|
||||
*/
|
||||
public Circle getAttackCircle() {
|
||||
return attackCircle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attackCircle the attackCircle to set
|
||||
*/
|
||||
public void setAttackCircle(Circle attackCircle) {
|
||||
this.attackCircle = attackCircle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the attentionCircle
|
||||
*/
|
||||
public Circle getAttentionCircle() {
|
||||
return attentionCircle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attentionCircle the attentionCircle to set
|
||||
*/
|
||||
public void setAttentionCircle(Circle attentionCircle) {
|
||||
this.attentionCircle = attentionCircle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isMelee
|
||||
*/
|
||||
public boolean isIsMelee() {
|
||||
return isMelee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isMelee the isMelee to set
|
||||
*/
|
||||
public void setIsMelee(boolean isMelee) {
|
||||
this.isMelee = isMelee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the movementState
|
||||
*/
|
||||
public int getMovementState() {
|
||||
return movementState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param movementState the movementState to set
|
||||
*/
|
||||
public void setMovementState(int movementState) {
|
||||
this.movementState = movementState;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,437 @@
|
||||
/*
|
||||
* 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.worldobjects;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
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 com.trs.main.InformationQuest;
|
||||
import com.trs.main.Main;
|
||||
import com.trs.main.Quest;
|
||||
import com.trs.main.Stats;
|
||||
import java.util.ArrayList;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Jan
|
||||
*/
|
||||
public class Player extends Actor{
|
||||
|
||||
private static float SQRT2 = 1.414f;
|
||||
|
||||
private Texture t;
|
||||
private AnimatedSprite playerSprite;
|
||||
private float movementX = 0;
|
||||
private float movementY = 0;
|
||||
private float speed = 3f;
|
||||
private float velocity = 0.5f;
|
||||
// 0: up, 1: left, 2: down, 3: right
|
||||
private int facing = 0;
|
||||
|
||||
private ArrayList<Quest> quests;
|
||||
|
||||
private Rectangle collisionRect;
|
||||
|
||||
private Group questGroup;
|
||||
|
||||
private Stats stats;
|
||||
|
||||
public Player(int xPos, int yPos){
|
||||
setName("player");
|
||||
t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
|
||||
playerSprite = new AnimatedSprite(getT(), 64, 64, true);
|
||||
playerSprite.setRow(0);
|
||||
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
|
||||
setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
|
||||
quests = new ArrayList<>();
|
||||
|
||||
stats = new Stats();
|
||||
|
||||
//TEST QUESTS
|
||||
int[] n = {1, 1};
|
||||
int[] m = {1, 0};
|
||||
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, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void positionChanged() {
|
||||
getPlayerSprite().setSpritePosition((int)getX(), (int)getY());
|
||||
setCollisionRect(new Rectangle(getX() + 16, getY(), 32, 16));
|
||||
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
|
||||
// TEST QUESTS
|
||||
for(Quest quest : getQuests()){
|
||||
//quest.print();
|
||||
//System.out.println();
|
||||
}
|
||||
//System.out.println();
|
||||
|
||||
// QUEST HANDLING
|
||||
for(Quest quest : getQuests()){
|
||||
quest.updateQuest();
|
||||
}
|
||||
|
||||
// PLAYER ACTING
|
||||
if(Main.gamestate == 0) {
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){
|
||||
setSpeed(9);
|
||||
}
|
||||
else setSpeed(3);
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.D)){
|
||||
setMovementX(getSpeed());
|
||||
setFacing(3);
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.A)){
|
||||
setMovementX(-getSpeed());
|
||||
setFacing(1);
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.W)){
|
||||
setMovementY(getSpeed());
|
||||
setFacing(0);
|
||||
}
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.S)){
|
||||
setMovementY(-getSpeed());
|
||||
setFacing(2);
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.NUM_1)){
|
||||
setMovementY(-8);
|
||||
}
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)){
|
||||
Main.gamestate = 9;
|
||||
}
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.E)) {
|
||||
Actor a = collidingActor();
|
||||
if(a != null) {
|
||||
if(a instanceof MovingNpc){
|
||||
Main.gamestate = 1;
|
||||
boolean dialogueStarted = false;
|
||||
for(Quest quest : getQuests()){
|
||||
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);
|
||||
}
|
||||
|
||||
setMovementX(0);
|
||||
setMovementY(0);
|
||||
}
|
||||
else if(a instanceof InteractionObject) {
|
||||
Main.gamestate = 1;
|
||||
((InteractionObject)a).startDialogue(getX()+32, getY()+32);
|
||||
setMovementX(0);
|
||||
setMovementY(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Main.gamestate == 1) {
|
||||
// Input handled by invoked textbox
|
||||
}
|
||||
|
||||
// MOVEMENT HANDLING
|
||||
if(getMovementX() == 0 && getMovementY() == 0){
|
||||
|
||||
}
|
||||
else if(getMovementX() == 0 && getMovementY() != 0){
|
||||
setY(getY()+getMovementY());
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setY(getY()-getMovementY());
|
||||
}
|
||||
}
|
||||
else if(getMovementY() == 0 && getMovementX() != 0){
|
||||
setX(getX()+getMovementX());
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setX(getX()-getMovementX());
|
||||
}
|
||||
}
|
||||
else if(getMovementX() != 0 && getMovementY() != 0){
|
||||
setX(getX()+ (getMovementX() / getSQRT2()));
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setX(getX() - (getMovementX() / getSQRT2()));
|
||||
}
|
||||
|
||||
setY(getY() + (getMovementY() / getSQRT2()));
|
||||
if(collidingWithMapCollisionObject()){
|
||||
setY(getY()- (getMovementY() / getSQRT2()));
|
||||
}
|
||||
}
|
||||
velocity(getVelocity());
|
||||
|
||||
// ANIMATION HANDLING
|
||||
int animationRow = 0;
|
||||
if(getMovementX() != 0 || getMovementY() != 0) {
|
||||
animationRow = 8;
|
||||
}
|
||||
getPlayerSprite().setRow(animationRow + getFacing());
|
||||
getPlayerSprite().updateAnimation(delta);
|
||||
|
||||
super.act(delta); //To change body of generated methods, choose Tools | Templates.
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
getPlayerSprite().draw(batch);
|
||||
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
return super.remove(); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public boolean collidingWithMapCollisionObject(){
|
||||
for(Actor a : getStage().getActors()){
|
||||
if(a instanceof MapCollisionObject){
|
||||
Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
|
||||
if(Intersector.overlaps(getCollisionRect(), o)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(a instanceof MovingNpc){
|
||||
if(Intersector.overlaps(getCollisionRect(), ((MovingNpc)a).collisionRect)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Slowing the players movement by velocity
|
||||
public void velocity(float velocity){
|
||||
if(getMovementX() > 0){
|
||||
setMovementX(getMovementX() - velocity);
|
||||
if(getMovementX() < 0){
|
||||
setMovementX(0);
|
||||
}
|
||||
}
|
||||
else if(getMovementX() < 0){
|
||||
setMovementX(getMovementX() + velocity);
|
||||
if(getMovementX() > 0){
|
||||
setMovementX(0);
|
||||
}
|
||||
}
|
||||
|
||||
if(getMovementY() > 0){
|
||||
setMovementY(getMovementY() - velocity);
|
||||
if(getMovementY() < 0){
|
||||
setMovementY(0);
|
||||
}
|
||||
}
|
||||
else if(getMovementY() < 0){
|
||||
setMovementY(getMovementY() + velocity);
|
||||
if(getMovementY() > 0){
|
||||
setMovementY(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Actor collidingActor(){
|
||||
for(Actor a : getStage().getActors()){
|
||||
if(a instanceof InteractionObject || a instanceof MovingNpc){
|
||||
Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight());
|
||||
Rectangle npc = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
|
||||
if(Intersector.overlaps(p, npc)){
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the SQRT2
|
||||
*/
|
||||
public static float getSQRT2() {
|
||||
return SQRT2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aSQRT2 the SQRT2 to set
|
||||
*/
|
||||
public static void setSQRT2(float aSQRT2) {
|
||||
SQRT2 = aSQRT2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the t
|
||||
*/
|
||||
public Texture getT() {
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t the t to set
|
||||
*/
|
||||
public void setT(Texture t) {
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the playerSprite
|
||||
*/
|
||||
public AnimatedSprite getPlayerSprite() {
|
||||
return playerSprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerSprite the playerSprite to set
|
||||
*/
|
||||
public void setPlayerSprite(AnimatedSprite playerSprite) {
|
||||
this.playerSprite = playerSprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the movementX
|
||||
*/
|
||||
public float getMovementX() {
|
||||
return movementX;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param movementX the movementX to set
|
||||
*/
|
||||
public void setMovementX(float movementX) {
|
||||
this.movementX = movementX;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the movementY
|
||||
*/
|
||||
public float getMovementY() {
|
||||
return movementY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param movementY the movementY to set
|
||||
*/
|
||||
public void setMovementY(float movementY) {
|
||||
this.movementY = movementY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the speed
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param speed the speed to set
|
||||
*/
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the velocity
|
||||
*/
|
||||
public float getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param velocity the velocity to set
|
||||
*/
|
||||
public void setVelocity(float velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the facing
|
||||
*/
|
||||
public int getFacing() {
|
||||
return facing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param facing the facing to set
|
||||
*/
|
||||
public void setFacing(int facing) {
|
||||
this.facing = facing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the quests
|
||||
*/
|
||||
public ArrayList<Quest> getQuests() {
|
||||
return quests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param quests the quests to set
|
||||
*/
|
||||
public void setQuests(ArrayList<Quest> quests) {
|
||||
this.quests = quests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the collisionRect
|
||||
*/
|
||||
public Rectangle getCollisionRect() {
|
||||
return collisionRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param collisionRect the collisionRect to set
|
||||
*/
|
||||
public void setCollisionRect(Rectangle collisionRect) {
|
||||
this.collisionRect = collisionRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the questGroup
|
||||
*/
|
||||
public Group getQuestGroup() {
|
||||
return questGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param questGroup the questGroup to set
|
||||
*/
|
||||
public void setQuestGroup(Group questGroup) {
|
||||
this.questGroup = questGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stats
|
||||
*/
|
||||
public Stats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stats the stats to set
|
||||
*/
|
||||
public void setStats(Stats stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue