Merge branch 'ki'

wichtig
master
Jonathan Hager 6 years ago
commit 4c79954afe

@ -102,9 +102,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
entityMovement.scheduleTask(new Timer.Task() { entityMovement.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
if(m != null){
//m.updateEntitySprite(d.getCurrentEntities());
for(int i = 0; i < d.getCurrentEntities().length; i++){ for(int i = 0; i < d.getCurrentEntities().length; i++){
if(d.getCurrentEntities()[i] != null){ if(d.getCurrentEntities()[i] != null){
if(m != null){
// Gets the collisions relevant sprites // Gets the collisions relevant sprites
MapObjects mapObjects = m.getM().getMaps()[level][roomPosX][roomPosY].getMap().getLayers().get(0).getObjects(); MapObjects mapObjects = m.getM().getMaps()[level][roomPosX][roomPosY].getMap().getLayers().get(0).getObjects();
Rectangle playerSprite = m.getPlayer().getCollisionSprite(); Rectangle playerSprite = m.getPlayer().getCollisionSprite();
@ -114,28 +116,69 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
int x = (int) temp.getxPos(); int x = (int) temp.getxPos();
int y = (int) temp.getyPos(); int y = (int) temp.getyPos();
d.getCurrentEntities()[i].move((int) d.getPlayer().getxPos(), (int) d.getPlayer().getyPos()); Entity arrow = d.getCurrentEntities()[i].move((int) d.getPlayer().getxPos(), (int) d.getPlayer().getyPos());
Sprite tempObject = m.entitySprites[i]; Sprite tempObject = m.entitySprites[i];
tempObject.setPosition(temp.getxPos(), temp.getyPos());
boolean overlaps = false; boolean overlaps = false;
boolean delete = false;
if(Intersector.overlaps(tempObject.getBoundingRectangle(), playerSprite)){ if(Intersector.overlaps(tempObject.getBoundingRectangle(), playerSprite)){
overlaps = true; overlaps = true;
if(d.getCurrentEntities()[i].getId() == 2){
d.getCurrentEntities()[i].attack(d.getPlayer());
delete = true;
}
} }
else{ else{
for(RectangleMapObject rectangleObject : mapObjects.getByType(RectangleMapObject.class)){ for(RectangleMapObject rectangleObject : mapObjects.getByType(RectangleMapObject.class)){
Rectangle rectangle = rectangleObject.getRectangle(); Rectangle rectangle = rectangleObject.getRectangle();
if(Intersector.overlaps(tempObject.getBoundingRectangle(), rectangle)){ if(Intersector.overlaps(tempObject.getBoundingRectangle(), rectangle)){
overlaps = true;
delete = true;
break;
}
}
if(d.getCurrentEntities()[i].getId() != 2){
for(int j = 0; j < m.entitySprites.length; j++){
if(i != j){
if(d.getCurrentEntities()[j] != null && d.getCurrentEntities()[j].getId() != 2){
if(Intersector.overlaps(tempObject.getBoundingRectangle(), m.entitySprites[j].getBoundingRectangle())){
overlaps = true; overlaps = true;
break; break;
} }
} }
} }
}
}
}
if(overlaps){ if(overlaps){
d.getCurrentEntities()[i].setxPos(x); d.getCurrentEntities()[i].setxPos(x);
d.getCurrentEntities()[i].setyPos(y); d.getCurrentEntities()[i].setyPos(y);
tempObject.setPosition(x, y);
}
m.entitySprites[i] = tempObject;
if(arrow != null){
for(int k = 5; k < d.getCurrentEntities().length; k++){
if(d.getCurrentEntities()[k] == null){
d.getCurrentEntities()[k] = arrow;
m.updateEntitySprite(d.getCurrentEntities());
break;
}
}
}
if(delete && d.getCurrentEntities()[i].getId() == 2){
d.getCurrentEntities()[i] = null;
m.updateEntitySprite(d.getCurrentEntities());
} }
} }
} }

@ -144,7 +144,7 @@ public class DungeonGenerator {
int itemAmount = (int) (Math.random() * 2); int itemAmount = (int) (Math.random() * 2);
int enemyAmount = (int) (Math.random() * 6); int enemyAmount = (int) (Math.random() * 6);
Room tempRoom = new Room(new ArrayList<ItemContainer>(itemAmount), new Entity[enemyAmount]); Room tempRoom = new Room(new ArrayList<ItemContainer>(itemAmount), new Entity[15]);
// Items werden generiert // Items werden generiert
int[][] belegt = new int[itemAmount][2]; int[][] belegt = new int[itemAmount][2];

@ -8,9 +8,9 @@ public abstract class Entity {
protected float xPos; protected float xPos;
protected float yPos; protected float yPos;
protected int hp; protected float hp;
protected int maxhp; protected float maxhp;
protected int dmg; protected float dmg;
protected int lvl; protected int lvl;
protected float movementX; protected float movementX;
protected float movementY; protected float movementY;
@ -29,8 +29,13 @@ public abstract class Entity {
this.direction = 2; this.direction = 2;
} }
public void attack(){ public void attack(Entity e){
if(e.getHp() - this.dmg < 0){
e.setHp(1);
}
else{
e.setHp(e.getHp() - this.dmg);
}
} }
public void update(){ public void update(){
xPos += movementX; xPos += movementX;
@ -65,7 +70,7 @@ public abstract class Entity {
} }
} }
abstract public void move(int xPosPlayer, int yPosPlayer); abstract public Entity move(int xPosPlayer, int yPosPlayer);
// GETTER + SETTER // GETTER + SETTER
public float getxPos() { public float getxPos() {
@ -84,27 +89,27 @@ public abstract class Entity {
this.yPos = yPos; this.yPos = yPos;
} }
public int getHp() { public float getHp() {
return hp; return hp;
} }
public void setHp(int hp) { public void setHp(float hp) {
this.hp = hp; this.hp = hp;
} }
public int getMaxhp() { public float getMaxhp() {
return maxhp; return maxhp;
} }
public void setMaxhp(int maxhp) { public void setMaxhp(float maxhp) {
this.maxhp = maxhp; this.maxhp = maxhp;
} }
public int getDmg() { public float getDmg() {
return dmg; return dmg;
} }
public void setDmg(int dmg) { public void setDmg(float dmg) {
this.dmg = dmg; this.dmg = dmg;
} }

@ -4,6 +4,8 @@ import com.dungeoncrawler.model.Entity;
public class Archer extends Entity{ public class Archer extends Entity{
int counter;
public Archer(float xPos, float yPos, int lvl) { public Archer(float xPos, float yPos, int lvl) {
super(xPos, yPos, lvl); super(xPos, yPos, lvl);
@ -12,6 +14,7 @@ public class Archer extends Entity{
this.direction = 2; this.direction = 2;
this.dmg = 3*lvl; this.dmg = 3*lvl;
this.id = 0; this.id = 0;
counter = 0;
// TODO: Sinnvolle Werte finden // TODO: Sinnvolle Werte finden
direction = 2; direction = 2;
@ -19,8 +22,64 @@ public class Archer extends Entity{
} }
@Override @Override
public void move(int xPosPlayer, int yPosPlayer) { public Entity move(int xPosPlayer, int yPosPlayer) {
// Nothing float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
double alpha;
if(deltaX == 0 && deltaY >= 0){
alpha = Math.PI / 2;
}
else if(deltaX == 0 && deltaY < 0){
alpha = Math.PI / -2;
}
else{
alpha = Math.abs(Math.atan(deltaY / deltaX));
if(deltaX < 0 && deltaY < 0){
alpha = Math.PI + alpha;
}
else if(deltaX < 0 && deltaY > 0){
alpha = Math.PI - alpha;
}
else if(deltaX > 0 && deltaY < 0){
alpha = 2*Math.PI - alpha;
}
}
int distance = (int) Math.abs((deltaY / Math.sin(alpha)));
Arrow a = null;
if(distance >= 124 && distance <= 164 && counter % 60 == 0){
a = new Arrow(this.xPos, this.yPos, this.lvl, 0);
movementX = (int) (4 * Math.cos(alpha));
movementY = (int) (4 * Math.sin(alpha));
a.setMovementX(movementX);
a.setMovementY(movementY);
}
else{
movementX = (int) (3 * Math.cos(alpha));
movementY = (int) (3 * Math.sin(alpha));
System.out.println(distance);
if(distance < 124){
movementX *= -1;
movementY *= -1;
}
else if(distance >= 124 && distance <= 164){
movementX = 0;
movementY = 0;
}
xPos += movementX;
yPos += movementY;
}
counter++;
return a;
} }

@ -31,7 +31,10 @@ public class Arrow extends Entity{
} }
@Override @Override
public void move(int xPosPlayer, int yPosPlayer) { public Entity move(int xPosPlayer, int yPosPlayer) {
// Nothing xPos += movementX;
yPos += movementY;
return null;
} }
} }

@ -14,18 +14,18 @@ import com.dungeoncrawler.model.Item;
*/ */
public class Player extends Entity { public class Player extends Entity {
int standartDmg; float standartDmg;
int standartMaxHp; float standartMaxHp;
public Player() { public Player() {
super(200, 200, 1); super(200, 200, 1);
this.maxhp = 5 * (lvl + 1); this.maxhp = 20 * (lvl + 1);
this.hp = this.maxhp; this.hp = this.maxhp;
this.standartMaxHp = 5 * (lvl + 1); this.standartMaxHp = 5 * (lvl + 1);
this.dmg = 3*lvl; this.dmg = 3*lvl;
this.standartDmg = dmg = 3*lvl; this.standartDmg = dmg;
id = -1; id = -1;
inv = new Inventory(3,2); inv = new Inventory(3,2);
// TODO: Sinnvolle Werte finden // TODO: Sinnvolle Werte finden
@ -50,8 +50,8 @@ public class Player extends Entity {
} }
} }
public void move(int x, int y){ public Entity move(int x, int y){
return null;
} }

@ -18,9 +18,9 @@ public class Swordsman extends Entity {
} }
@Override @Override
public void move(int xPosPlayer, int yPosPlayer){ public Entity move(int xPosPlayer, int yPosPlayer){
int deltaX = xPosPlayer - (int) xPos; float deltaX = xPosPlayer - (int) xPos;
int deltaY = yPosPlayer - (int) yPos; float deltaY = yPosPlayer - (int) yPos;
double alpha; double alpha;
if(deltaX == 0 && deltaY >= 0){ if(deltaX == 0 && deltaY >= 0){
@ -48,6 +48,9 @@ public class Swordsman extends Entity {
xPos += movementX; xPos += movementX;
yPos += movementY; yPos += movementY;
System.out.println("Winkel: " + Math.toDegrees(alpha));
return null;
} }

@ -90,7 +90,7 @@ public class GameScreen {
//ENTITIES //ENTITIES
entityTextures = new Texture[5]; entityTextures = new Texture[5];
entitySprites = new Sprite[5]; entitySprites = new Sprite[15];
arrowTextures = new Texture[10]; arrowTextures = new Texture[10];
arrowSprites = new Sprite[10]; arrowSprites = new Sprite[10];
@ -231,26 +231,9 @@ public class GameScreen {
camera.update(); camera.update();
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
for(int i = 0; i < e.length; i++){
if(e[i] != null){
if(e[i].getId() == 0){ //nimmt entity ID -> 0 = Archer || 1 = Swordsman || 2 = Arrow
entityTextures[i] = new Texture("sprites/archer.png");
archerRegions = TextureRegion.split(entityTextures[i], 48, 48);
entitySprites[i] = new Sprite(archerRegions[0][2]);
entitySprites[i].setX(e[i].getxPos());
entitySprites[i].setY(e[i].getyPos());
}
if(e[i].getId() == 1){
entityTextures[i] = new Texture("sprites/swordsman.png");
swordsmanRegions = TextureRegion.split(entityTextures[i], 48, 48);
entitySprites[i] = new Sprite(swordsmanRegions[0][2]);
entitySprites[i].setX(e[i].getxPos());
entitySprites[i].setY(e[i].getyPos());
}
}
}
updateEntitySprite(e);
//BATCH //BATCH
@ -351,7 +334,33 @@ public class GameScreen {
batch.end(); batch.end();
} }
public void updateEntitySprite(Entity[] e){
for(int i = 0; i < e.length; i++){
if(e[i] != null){
if(e[i].getId() == 0){ //nimmt entity ID -> 0 = Archer || 1 = Swordsman || 2 = Arrow
entityTextures[i] = new Texture("sprites/archer.png");
archerRegions = TextureRegion.split(entityTextures[i], 48, 48);
entitySprites[i] = new Sprite(archerRegions[0][2]);
entitySprites[i].setX(e[i].getxPos());
entitySprites[i].setY(e[i].getyPos());
}
if(e[i].getId() == 1){
entityTextures[i] = new Texture("sprites/swordsman.png");
swordsmanRegions = TextureRegion.split(entityTextures[i], 48, 48);
entitySprites[i] = new Sprite(swordsmanRegions[0][2]);
entitySprites[i].setX(e[i].getxPos());
entitySprites[i].setY(e[i].getyPos());
}
if(e[i].getId() == 2){
Texture tx = new Texture("sprites/sword.png");
//swordsmanRegions = TextureRegion.split(entityTextures[i], 48, 48);
entitySprites[i] = new Sprite(tx);
entitySprites[i].setX(e[i].getxPos());
entitySprites[i].setY(e[i].getyPos());
}
}
}
}
public Entity[] playerAttack(Entity e[], Player p, SpriteBatch batch){ public Entity[] playerAttack(Entity e[], Player p, SpriteBatch batch){

Loading…
Cancel
Save