GammelJAN 6 years ago
commit 29e2223a25

@ -13,6 +13,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.MapLayers; import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapObjects; import com.badlogic.gdx.maps.MapObjects;
import com.badlogic.gdx.maps.objects.RectangleMapObject; import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Intersector;
@ -103,11 +104,44 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
public void run() { public void run() {
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){
d.getCurrentEntities()[i].randomMove(roomX, roomY); if(m != null){
// Gets the collisions relevant sprites
MapObjects mapObjects = m.getM().getMaps()[level][roomPosX][roomPosY].getMap().getLayers().get(0).getObjects();
Rectangle playerSprite = m.getPlayer().getCollisionSprite();
Entity temp = d.getCurrentEntities()[i];
int x = (int) temp.getxPos();
int y = (int) temp.getyPos();
d.getCurrentEntities()[i].move((int) d.getPlayer().getxPos(), (int) d.getPlayer().getyPos());
Sprite tempObject = m.entitySprites[i];
boolean overlaps = false;
if(Intersector.overlaps(tempObject.getBoundingRectangle(), playerSprite)){
overlaps = true;
}
else{
for(RectangleMapObject rectangleObject : mapObjects.getByType(RectangleMapObject.class)){
Rectangle rectangle = rectangleObject.getRectangle();
if(Intersector.overlaps(tempObject.getBoundingRectangle(), rectangle)){
overlaps = true;
break;
}
}
}
if(overlaps){
d.getCurrentEntities()[i].setxPos(x);
d.getCurrentEntities()[i].setyPos(y);
}
}
} }
} }
} }
},0,1f); },0, 0.03f);
} }

@ -1,7 +1,8 @@
package com.dungeoncrawler.model; package com.dungeoncrawler.model;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapObjects;
import com.badlogic.gdx.math.Rectangle;
public abstract class Entity { public abstract class Entity {
@ -14,7 +15,7 @@ public abstract class Entity {
protected float movementX; protected float movementX;
protected float movementY; protected float movementY;
protected int id; protected int id;
protected int facing; protected int direction;
protected Inventory inv; protected Inventory inv;
@ -25,16 +26,9 @@ public abstract class Entity {
this.lvl = lvl; this.lvl = lvl;
this.movementX = 0; this.movementX = 0;
this.movementY = 0; this.movementY = 0;
this.facing = 2; this.direction = 2;
} }
public void attack(){ public void attack(){
} }
@ -62,26 +56,16 @@ public abstract class Entity {
movementY = 0; movementY = 0;
} }
public void rdmMove(){ public void updateDirection(){
if(movementX > 1){
} direction = 1;
public int direction(){ // returns direction the entity is facing depending on its movement
if(movementX == -3f){ // TIS IS SHIT - NEED REWORK
facing = 3;
}
else if(movementX == 3f){
facing = 1;
}
else if(movementY == 3f){
facing = 0;
} }
else if(movementY == -3f){ else if(movementX < -1){
facing = 2; direction = 0;
} }
return facing;
} }
abstract public void move(int xPosPlayer, int yPosPlayer);
// GETTER + SETTER // GETTER + SETTER
public float getxPos() { public float getxPos() {
@ -152,15 +136,12 @@ public abstract class Entity {
return this.id; return this.id;
} }
public int getFacing(){ public int getDirection(){
return facing; return direction;
}
public void setFacing(int facing){
this.facing = facing;
}
public void randomMove(int x, int y){
} }
public void setDirection(int direction){
this.direction = direction;
}
} }

@ -1,156 +1,26 @@
package com.dungeoncrawler.model.entities; package com.dungeoncrawler.model.entities;
import com.dungeoncrawler.model.Entity; import com.dungeoncrawler.model.Entity;
import com.badlogic.gdx.utils.Timer;
public class Archer extends Entity{ public class Archer extends Entity{
Timer tup;
Timer tright;
Timer tdown;
Timer tleft;
int timerRuns;
boolean isRunning;
public Archer(float xPos, float yPos, int lvl) { public Archer(float xPos, float yPos, int lvl) {
super(xPos, yPos, lvl); super(xPos, yPos, lvl);
this.maxhp = 5*lvl; this.maxhp = 5*lvl;
this.hp = this.maxhp; this.hp = this.maxhp;
this.facing = 2; this.direction = 2;
this.dmg = 3*lvl; this.dmg = 3*lvl;
this.id = 0; this.id = 0;
// TODO: Sinnvolle Werte finden // TODO: Sinnvolle Werte finden
tup = new Timer(); direction = 2;
tright = new Timer();
tdown = new Timer();
tleft = new Timer();
isRunning = false;
timerRuns = 0;
facing = 2;
tup.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(0);
setyPos(getyPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tup.stop();
}
}
},0,0.015f);
tup.stop();
tright.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(1);
setxPos(getxPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tright.stop();
}
}
},0,0.015f);
tright.stop();
tdown.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(2);
setyPos(getyPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tdown.stop();
}
}
},0,0.015f);
tdown.stop();
tleft.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(3);
setxPos(getxPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tleft.stop();
}
}
},0,0.015f);
tleft.stop();
} }
@Override @Override
public void randomMove(int x, int y) { public void move(int xPosPlayer, int yPosPlayer) {
double i = Math.random(); // Nothing
if(i <= 0.2){
if(isRunning == false){
if(getyPos() >= (x-1) * 48f){
}
else{
setIsRunning(true);
tup.start();
}
}
}
else if(i > 0.2 && i <= 0.4){
if(isRunning == false){
if(getxPos() >= (y-1) * 48f){
}
else{
setIsRunning(true);
tright.start();
}
}
}
else if(i > 0.4 && i <= 0.6){
if(isRunning == false){
if(getyPos() <= 48f){
}
else{
setIsRunning(true);
tdown.start();
}
}
}
else if(i > 0.6 && i <= 0.8){
if(isRunning == false){
if(getxPos() <= 48f){
}
else{
setIsRunning(true);
tleft.start();
}
}
}
else{
}
}
private void setIsRunning(boolean n){
isRunning = n;
}
private boolean getIsRunning(){
return isRunning;
}
public int getTimerRuns(){
return timerRuns;
}
public void setTimerRuns(int n){
timerRuns = n;
} }

@ -6,14 +6,9 @@
package com.dungeoncrawler.model.entities; package com.dungeoncrawler.model.entities;
import com.dungeoncrawler.model.Entity; import com.dungeoncrawler.model.Entity;
import com.badlogic.gdx.utils.Timer;
public class Arrow extends Entity{ public class Arrow extends Entity{
Timer toben;
Timer tunten;
Timer trechts;
Timer tlinks;
float xStart; float xStart;
float yStart; float yStart;
int direction; int direction;
@ -22,61 +17,11 @@ public class Arrow extends Entity{
super(xPos, yPos, lvl); super(xPos, yPos, lvl);
xStart = xPos; xStart = xPos;
yStart = yPos; yStart = yPos;
Timer toben = new Timer();
Timer tunten = new Timer();
Timer trechts = new Timer();
Timer tlinks = new Timer();
this.direction = direction; this.direction = direction;
this.dmg = 3*lvl; this.dmg = 3*lvl;
this.id = 2; this.id = 2;
toben.scheduleTask(new Timer.Task() { }
@Override
public void run() {
setyPos(getyPos() + 3f);
}
},0,0.1f);
toben.stop();
tunten.scheduleTask(new Timer.Task() {
@Override
public void run() {
setyPos(getyPos() - 3f);
}
},0,0.1f);
tunten.stop();
trechts.scheduleTask(new Timer.Task() {
@Override
public void run() {
setxPos(getxPos() + 3f);
}
},0,0.1f);
trechts.stop();
tlinks.scheduleTask(new Timer.Task() {
@Override
public void run() {
setyPos(getxPos() - 3f);
}
},0,0.1f);
tlinks.stop();
switch(direction){
case 0:
toben.start();
break;
case 1:
trechts.start();
break;
case 2:
tunten.start();
break;
case 3:
tlinks.start();
break;
}
}
public float getxStart(){ public float getxStart(){
return xStart; return xStart;
@ -84,4 +29,9 @@ public class Arrow extends Entity{
public float getyStart(){ public float getyStart(){
return yStart; return yStart;
} }
@Override
public void move(int xPosPlayer, int yPosPlayer) {
// Nothing
}
} }

@ -5,11 +5,9 @@
*/ */
package com.dungeoncrawler.model.entities; package com.dungeoncrawler.model.entities;
import com.dungeoncrawler.model.Entity; import com.dungeoncrawler.model.Entity;
import com.dungeoncrawler.model.Inventory; import com.dungeoncrawler.model.Inventory;
import com.dungeoncrawler.model.Item; import com.dungeoncrawler.model.Item;
import com.dungeoncrawler.model.ItemContainer;
/** /**
* *
* @author Jan * @author Jan
@ -40,6 +38,7 @@ public class Player extends Entity {
public Inventory getInv(){ public Inventory getInv(){
return inv; return inv;
} }
public void updateItems(){ public void updateItems(){
if(inv.getItem(1) != null){ if(inv.getItem(1) != null){
dmg = standartDmg + inv.getItem(1).getDmg(); dmg = standartDmg + inv.getItem(1).getDmg();
@ -49,6 +48,7 @@ public class Player extends Entity {
dmg = standartDmg; dmg = standartDmg;
maxhp = standartMaxHp; maxhp = standartMaxHp;
} }
}
} }

@ -1,151 +1,53 @@
package com.dungeoncrawler.model.entities; package com.dungeoncrawler.model.entities;
import com.badlogic.gdx.utils.Timer;
import com.dungeoncrawler.model.Entity; import com.dungeoncrawler.model.Entity;
public class Swordsman extends Entity { public class Swordsman extends Entity {
Timer tup;
Timer tright;
Timer tdown;
Timer tleft;
int timerRuns;
boolean isRunning;
public Swordsman(float xPos, float yPos, int lvl) { public Swordsman(float xPos, float yPos, int lvl) {
super(xPos, yPos, lvl); super(xPos, yPos, lvl);
this.maxhp = 5*lvl; this.maxhp = 5*lvl;
this.hp = this.maxhp; this.hp = this.maxhp;
this.facing = 2; this.direction = 2;
this.dmg = 3*lvl; this.dmg = 3*lvl;
this.id = 1; this.id = 1;
// TODO: Sinnvolle Werte finden
tup = new Timer();
tright = new Timer();
tdown = new Timer();
tleft = new Timer();
isRunning = false;
timerRuns = 0;
facing = 2;
// TODO: Sinnvolle Werte finden
tup.scheduleTask(new Timer.Task() { direction = 2;
@Override
public void run() {
setFacing(0);
setyPos(getyPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tup.stop();
}
}
},0,0.025f);
tup.stop();
tright.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(1);
setxPos(getxPos() + 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tright.stop();
}
}
},0,0.025f);
tright.stop();
tdown.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(2);
setyPos(getyPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tdown.stop();
}
}
},0,0.025f);
tdown.stop();
tleft.scheduleTask(new Timer.Task() {
@Override
public void run() {
setFacing(3);
setxPos(getxPos() - 1f);
setTimerRuns(getTimerRuns() + 1);
if(getTimerRuns() >= 48){
setTimerRuns(0);
setIsRunning(false);
tleft.stop();
}
}
},0,0.025f);
tleft.stop();
} }
@Override @Override
public void randomMove(int x, int y) { public void move(int xPosPlayer, int yPosPlayer){
double i = Math.random(); int deltaX = xPosPlayer - (int) xPos;
if(i <= 0.25){ int deltaY = yPosPlayer - (int) yPos;
if(isRunning == false){
if(yPos >= (x-1) * 48f){ double alpha;
} if(deltaX == 0 && deltaY >= 0){
else{ alpha = Math.PI / 2;
setIsRunning(true); }
tup.start(); 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(i > 0.25 && i <= 0.5){ else if(deltaX < 0 && deltaY > 0){
if(isRunning == false){ alpha = Math.PI - alpha;
if(xPos >= (y-1) * 48f){
}
else{
setIsRunning(true);
tright.start();
}
}
} }
else if(i > 0.5 && i <= 0.75){ else if(deltaX > 0 && deltaY < 0){
if(isRunning == false){ alpha = 2*Math.PI - alpha;
if(yPos <= 48f){
}
else{
setIsRunning(true);
tdown.start();
}
}
} }
else if(i > 0.75 && i <= 1){ }
if(isRunning == false){
if(xPos <= 48f){
}
else{
setIsRunning(true);
tleft.start();
}
}
}
}
private void setIsRunning(boolean n){
isRunning = n;
}
private boolean getIsRunning(){
return isRunning;
}
public int getTimerRuns(){ movementX = (int) (3 * Math.cos(alpha));
return timerRuns; movementY = (int) (3 * Math.sin(alpha));
}
public void setTimerRuns(int n){ xPos += movementX;
timerRuns = n; yPos += movementY;
} }

@ -28,7 +28,7 @@ public class GameScreen {
//ENTITIES //ENTITIES
Texture[] entityTextures; Texture[] entityTextures;
Sprite[] entitySprites; public Sprite[] entitySprites;
TextureRegion[][] archerRegions; TextureRegion[][] archerRegions;
Texture archerTexture; Texture archerTexture;
TextureRegion[][] swordsmanRegions; TextureRegion[][] swordsmanRegions;
@ -43,8 +43,8 @@ public class GameScreen {
TiledMapRenderer tmr; TiledMapRenderer tmr;
TiledMap tm; TiledMap tm;
OrthographicCamera camera; OrthographicCamera camera;
ArrayList<AnimatedObject> objects; public ArrayList<AnimatedObject> objects;
ArrayList<AnimatedObject> mapItems; public ArrayList<AnimatedObject> mapItems;
Timer animations; Timer animations;
Timer animatePlayer; Timer animatePlayer;
@ -279,7 +279,7 @@ public class GameScreen {
//DRAW'T JEDES ENTITY - prueft vorher ob vorhanden //DRAW'T JEDES ENTITY - prueft vorher ob vorhanden
for(int i = 0; i < e.length; i++){ for(int i = 0; i < e.length; i++){
if(e[i] != null){ if(e[i] != null){
switch(e[i].getFacing()){ switch(e[i].getDirection()){
case -1: case -1:
break; break;
case 0: case 0:
@ -355,7 +355,7 @@ public class GameScreen {
public Entity[] playerAttack(Entity e[], Player p, SpriteBatch batch){ public Entity[] playerAttack(Entity e[], Player p, SpriteBatch batch){
if(p.direction() == 0){ if(p.getDirection() == 0){
Texture attackTexture = new Texture("sprites/AttackHori.png"); Texture attackTexture = new Texture("sprites/AttackHori.png");
Sprite attackSprite = new Sprite(attackTexture); Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 8f); attackSprite.setX(p.getxPos() - 8f);
@ -376,7 +376,7 @@ public class GameScreen {
} }
} }
} }
else if(p.direction() == 1){ else if(p.getDirection()== 1){
Texture attackTexture = new Texture("sprites/AttackVert.png"); Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture); Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos()+ 32f); attackSprite.setX(p.getxPos()+ 32f);
@ -396,7 +396,7 @@ public class GameScreen {
} }
} }
} }
else if(p.direction() == 2){ else if(p.getDirection()== 2){
Texture attackTexture = new Texture("sprites/AttackHori.png"); Texture attackTexture = new Texture("sprites/AttackHori.png");
Sprite attackSprite = new Sprite(attackTexture); Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 8f); attackSprite.setX(p.getxPos() - 8f);
@ -416,7 +416,7 @@ public class GameScreen {
} }
} }
} }
else if(p.direction() == 3){ else if(p.getDirection()== 3){
Texture attackTexture = new Texture("sprites/AttackVert.png"); Texture attackTexture = new Texture("sprites/AttackVert.png");
Sprite attackSprite = new Sprite(attackTexture); Sprite attackSprite = new Sprite(attackTexture);
attackSprite.setX(p.getxPos() - 32f); attackSprite.setX(p.getxPos() - 32f);

Loading…
Cancel
Save