Archer shoots in every Direction - (doesnt move) (1 try)

master
GammelJan 6 years ago
parent 44f9e0e11a
commit cdc3a87932

@ -24,50 +24,55 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
View v; View v;
Player p; Player p;
Archer a; Archer a;
Timer t; Timer tAttack;
Timer coords;
@Override @Override
public void create(){ public void create(){
batch = new SpriteBatch(); batch = new SpriteBatch();
v = new View(); p = new Player(200f, 200f);
p = new Player();
d = new Dungeon(p); d = new Dungeon(p);
v = new View();
p.setxPos(v.getPlayerX());
p.setyPos(v.getPlayerY());
dg = new DungeonGenerator(); dg = new DungeonGenerator();
dg.ichWillSpielen(); dg.ichWillSpielen();
p = new Player();
d = new Dungeon(p); d = new Dungeon(p);
a = new Archer(500, 200, 1); a = new Archer(500f, 200f, 1);
a.setxPos(v.getArcherX());
a.setyPos(v.getArcherY());
Gdx.input.setInputProcessor(this); Gdx.input.setInputProcessor(this);
t = new Timer(); tAttack = new Timer();
t.scheduleTask(new Timer.Task() { tAttack.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
if(p.getxPos() == a.getxPos()){ if(p.getxPos() == a.getxPos()){
if(p.getyPos() < a.getyPos()){ if(p.getyPos() > a.getyPos()){
a.attack(0); //unten a.attack(0); //UP
if(v.getArrowTravel() == 0){ if(v.getArrowTravel() == 0){
v.arrow(a,0); v.arrow(a,0);
} }
} }
if(p.getyPos() > a.getyPos()){ else if(p.getyPos() < a.getyPos()){
a.attack(1); //oben a.attack(2); //DOWN
if(v.getArrowTravel() == 0){ if(v.getArrowTravel() == 0){
v.arrow(a,1); v.arrow(a,2);
} }
} }
} }
else if(p.getyPos() == a.getyPos()){ else if(p.getyPos() == a.getyPos()){
if(p.getxPos() < a.getxPos()){ if(p.getxPos() > a.getxPos()){
a.attack(2); //links a.attack(1); //RIGHT
if(v.getArrowTravel() == 0){ if(v.getArrowTravel() == 0){
v.arrow(a,2); v.arrow(a,1);
} }
} }
if(p.getxPos() > a.getxPos()){ else if(p.getxPos() < a.getxPos()){
a.attack(3); //rechts a.attack(3); //LEFT
if(v.getArrowTravel() == 0){ if(v.getArrowTravel() == 0){
v.arrow(a,3); v.arrow(a,3);
} }
@ -78,10 +83,29 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
} }
} }
},0,0.5f); },0,0.5f);
coords = new Timer();
coords.scheduleTask(new Timer.Task() {
@Override
public void run() {
System.out.println("Player:");
System.out.println("X:" + p.getxPos());
System.out.println("Y:" + p.getyPos());
System.out.println("Archer:");
System.out.println("X:" + a.getxPos());
System.out.println("Y:" + a.getyPos());
}
},0,2f);
} }
@Override @Override
public void render(){ public void render(){
p.setxPos(v.getPlayerX());
p.setyPos(v.getPlayerY());
a.setxPos(v.getArcherX());
a.setyPos(v.getArcherY());
v.render(batch, p , a); v.render(batch, p , a);
} }

@ -61,7 +61,7 @@ public class DungeonGenerator {
} }
public void ichWillSpielen(){ public void ichWillSpielen(){
Dungeon d = this.generateDungeon(200, 200, 200, new Player()); Dungeon d = this.generateDungeon(200, 200, 200, new Player(200,200));
for(int i=0;i<d.getLevel().length;i++){ for(int i=0;i<d.getLevel().length;i++){
Level temp = d.getLevel()[i]; Level temp = d.getLevel()[i];

@ -3,30 +3,26 @@ package com.dungeoncrawler.model;
public abstract class Entity { public abstract class Entity {
protected int xPos; protected float xPos;
protected int yPos; protected float yPos;
protected int hp; protected int hp;
protected int maxhp; protected int maxhp;
protected int dmg; protected int dmg;
protected int lvl; protected int lvl;
protected int movementX; protected float movementX;
protected int movementY; protected float movementY;
public Entity(int xPos, int yPos, int lvl){ public Entity(float xPos, float yPos, int lvl){
this.xPos = xPos; this.xPos = xPos;
this.yPos = yPos; this.yPos = yPos;
this.lvl = lvl; this.lvl = lvl;
this.movementX = 0; this.movementX = 0f;
this.movementY = 0; this.movementY = 0f;
} }
public void attack(int i){ public void attack(int i){
if(i == 0){System.out.println("UNTEN");}
if(i == 1){System.out.println("OBEN");}
if(i == 2){System.out.println("LINKS");}
if(i == 3){System.out.println("RECHTS");}
} }
public void update(){ public void update(){
@ -42,47 +38,39 @@ public abstract class Entity {
public void rdmMove(){ public void rdmMove(){
switch((int) (Math.random() * 5)){ switch((int) (Math.random() * 5)){
case 0: //left case 0: //UP
for(int i = 0; i<=32;i++){ setMovementY(32f);
setMovementX(-1);
move(); move();
}
break; break;
case 1: //right case 1: //RIGHT
for(int i = 0; i<=32;i++){ setMovementX(32f);
setMovementX(1);
move(); move();
}
break; break;
case 2: //up case 2: //DOWN
for(int i = 0; i<=32;i++){ setMovementY(-32f);
setMovementY(1);
move(); move();
}
break; break;
case 3: //down case 3: //LEFT
for(int i = 0; i<=32;i++){ setMovementX(-32f);
setMovementY(-1);
move(); move();
}
break; break;
} }
} }
public int getxPos() { public float getxPos() {
return xPos; return xPos;
} }
public void setxPos(int xPos) { public void setxPos(float xPos) {
this.xPos = xPos; this.xPos = xPos;
} }
public int getyPos() { public float getyPos() {
return yPos; return yPos;
} }
public void setyPos(int yPos) { public void setyPos(float yPos) {
this.yPos = yPos; this.yPos = yPos;
} }
@ -118,19 +106,19 @@ public abstract class Entity {
this.lvl = lvl; this.lvl = lvl;
} }
public int getMovementX(){ public float getMovementX(){
return movementX; return movementX;
} }
public void setMovementX(int movementX){ public void setMovementX(float movementX){
this.movementX = movementX; this.movementX = movementX;
} }
public int getMovementY(){ public float getMovementY(){
return movementY; return movementY;
} }
public void setMovementY(int movementY){ public void setMovementY(float movementY){
this.movementY = movementY; this.movementY = movementY;
} }
} }

@ -3,7 +3,7 @@ import com.dungeoncrawler.model.Entity;
public class Archer extends Entity{ public class Archer extends Entity{
public Archer(int xPos, int 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;

@ -13,9 +13,10 @@ import com.dungeoncrawler.model.Entity;
*/ */
public class Player extends Entity { public class Player extends Entity {
public Player() { public Player(float xPos, float yPos) {
super(200, 200, 1); super(xPos, yPos, 0);
this.xPos = xPos;
this.yPos = yPos;
this.maxhp = 5*lvl; this.maxhp = 5*lvl;
this.hp = this.maxhp; this.hp = this.maxhp;

@ -33,6 +33,7 @@ public class View {
Timer tArrowDown = new Timer(); Timer tArrowDown = new Timer();
int ArrowTravel = 0; int ArrowTravel = 0;
public View() { public View() {
b = new Texture("Button.png"); b = new Texture("Button.png");
t = new Texture("Title.png"); t = new Texture("Title.png");
@ -41,6 +42,8 @@ public class View {
button = new Sprite(b); button = new Sprite(b);
title = new Sprite(t); title = new Sprite(t);
archer = new Sprite(a); archer = new Sprite(a);
archer.setX(500f);
archer.setY(200f);
arrow = new Texture("Archer.png"); arrow = new Texture("Archer.png");
Arrow = new Sprite(arrow); Arrow = new Sprite(arrow);
float w = Gdx.graphics.getWidth(); float w = Gdx.graphics.getWidth();
@ -52,13 +55,14 @@ public class View {
button.setY(400); button.setY(400);
regions = TextureRegion.split(p, 32, 32); regions = TextureRegion.split(p, 32, 32);
player = new Sprite(regions[0][2]); player = new Sprite(regions[0][2]);
player.setX(200); player.setX(200f);
player.setY(200); player.setY(200f);
tunten = new Timer(); tunten = new Timer();
toben = new Timer(); toben = new Timer();
tlinks = new Timer(); tlinks = new Timer();
trechts = new Timer(); trechts = new Timer();
tunten.scheduleTask(new Timer.Task() { tunten.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
@ -141,7 +145,7 @@ public class View {
tArrowLeft.scheduleTask(new Timer.Task() { tArrowLeft.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
Arrow.setX(Arrow.getX() - 3); Arrow.setX(Arrow.getX() - 3f);
ArrowTravel++; ArrowTravel++;
if(ArrowTravel >= 100){ if(ArrowTravel >= 100){
ArrowTravel = 0; ArrowTravel = 0;
@ -153,11 +157,11 @@ public class View {
tArrowRight.scheduleTask(new Timer.Task() { tArrowRight.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
Arrow.setX(Arrow.getX() + 3); Arrow.setX(Arrow.getX() + 3f);
ArrowTravel++; ArrowTravel++;
if(ArrowTravel >= 100){ if(ArrowTravel >= 100){
ArrowTravel = 0; ArrowTravel = 0;
tArrowLeft.stop(); tArrowRight.stop();
} }
} }
}, 0,1/40f); }, 0,1/40f);
@ -165,11 +169,11 @@ public class View {
tArrowUp.scheduleTask(new Timer.Task() { tArrowUp.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
Arrow.setY(Arrow.getY() + 3); Arrow.setY(Arrow.getY() + 3f);
ArrowTravel++; ArrowTravel++;
if(ArrowTravel >= 100){ if(ArrowTravel >= 100){
ArrowTravel = 0; ArrowTravel = 0;
tArrowLeft.stop(); tArrowUp.stop();
} }
} }
}, 0,1/50f); }, 0,1/50f);
@ -177,11 +181,11 @@ public class View {
tArrowDown.scheduleTask(new Timer.Task() { tArrowDown.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
Arrow.setY(Arrow.getY() - 3); Arrow.setY(Arrow.getY() - 3f);
ArrowTravel++; ArrowTravel++;
if(ArrowTravel >= 100){ if(ArrowTravel >= 100){
ArrowTravel = 0; ArrowTravel = 0;
tArrowLeft.stop(); tArrowDown.stop();
} }
} }
}, 0,1/50f); }, 0,1/50f);
@ -193,10 +197,10 @@ public class View {
public void render (SpriteBatch batch, Player p, Archer a) { public void render (SpriteBatch batch, Player p, Archer a) {
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
player.setX(player.getX()+ (float) p.getMovementX()); player.setX(player.getX()+ p.getMovementX());
player.setY(player.getY()+ (float) p.getMovementY()); player.setY(player.getY()+ p.getMovementY());
archer.setX((float)a.getxPos()); archer.setX(a.getxPos());
archer.setY((float)a.getyPos()); archer.setY(a.getyPos());
if(p.getMovementX() == 3){ if(p.getMovementX() == 3){
trechts.start(); trechts.start();
@ -225,7 +229,7 @@ public class View {
button.draw(batch); button.draw(batch);
player.draw(batch); player.draw(batch);
archer.draw(batch); archer.draw(batch);
if(ArrowTravel > 0){ if(ArrowTravel > 0 && ArrowTravel < 100){
Arrow.draw(batch); Arrow.draw(batch);
} }
batch.end(); batch.end();
@ -233,27 +237,27 @@ public class View {
public void arrow(Archer a, int i){ public void arrow(Archer a, int i){
switch(i){ switch(i){
case 0: case 0: //UP
Arrow.setX((float) a.getxPos()); Arrow.setX((float) a.getxPos());
Arrow.setY((float) a.getyPos()); Arrow.setY((float) a.getyPos());
tArrowDown.start(); tArrowUp.start();
break; break;
case 1: case 1: //RIGHT
Arrow.setX((float) a.getxPos()); Arrow.setX((float) a.getxPos());
Arrow.setY((float) a.getyPos()); Arrow.setY((float) a.getyPos());
tArrowUp.start(); tArrowRight.start();
break; break;
case 2: case 2: //DOWN
for(int n = 0; n < 50; n++){ for(int n = 0; n < 50; n++){
Arrow.setX((float) a.getxPos()); Arrow.setX((float) a.getxPos());
Arrow.setY((float) a.getyPos()); Arrow.setY((float) a.getyPos());
tArrowLeft.start(); tArrowDown.start();
} }
break; break;
case 3: case 3: //LEFT
Arrow.setX((float) a.getxPos()); Arrow.setX((float) a.getxPos());
Arrow.setY((float) a.getyPos()); Arrow.setY((float) a.getyPos());
tArrowRight.start(); tArrowLeft.start();
break; break;
} }
@ -281,4 +285,17 @@ public class View {
public int getArrowTravel(){ public int getArrowTravel(){
return ArrowTravel; return ArrowTravel;
} }
public float getPlayerX(){
return player.getX();
}
public float getPlayerY(){
return player.getY();
}
public float getArcherX(){
return archer.getX();
}
public float getArcherY(){
return archer.getY();
}
} }

Loading…
Cancel
Save