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;
Player p;
Archer a;
Timer t;
Timer tAttack;
Timer coords;
@Override
public void create(){
batch = new SpriteBatch();
v = new View();
p = new Player();
p = new Player(200f, 200f);
d = new Dungeon(p);
v = new View();
p.setxPos(v.getPlayerX());
p.setyPos(v.getPlayerY());
dg = new DungeonGenerator();
dg.ichWillSpielen();
p = new Player();
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);
t = new Timer();
t.scheduleTask(new Timer.Task() {
tAttack = new Timer();
tAttack.scheduleTask(new Timer.Task() {
@Override
public void run() {
if(p.getxPos() == a.getxPos()){
if(p.getyPos() < a.getyPos()){
a.attack(0); //unten
if(p.getyPos() > a.getyPos()){
a.attack(0); //UP
if(v.getArrowTravel() == 0){
v.arrow(a,0);
}
}
if(p.getyPos() > a.getyPos()){
a.attack(1); //oben
else if(p.getyPos() < a.getyPos()){
a.attack(2); //DOWN
if(v.getArrowTravel() == 0){
v.arrow(a,1);
v.arrow(a,2);
}
}
}
else if(p.getyPos() == a.getyPos()){
if(p.getxPos() < a.getxPos()){
a.attack(2); //links
if(p.getxPos() > a.getxPos()){
a.attack(1); //RIGHT
if(v.getArrowTravel() == 0){
v.arrow(a,2);
v.arrow(a,1);
}
}
if(p.getxPos() > a.getxPos()){
a.attack(3); //rechts
else if(p.getxPos() < a.getxPos()){
a.attack(3); //LEFT
if(v.getArrowTravel() == 0){
v.arrow(a,3);
}
@ -78,10 +83,29 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
}
}
},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
public void render(){
p.setxPos(v.getPlayerX());
p.setyPos(v.getPlayerY());
a.setxPos(v.getArcherX());
a.setyPos(v.getArcherY());
v.render(batch, p , a);
}

@ -61,7 +61,7 @@ public class DungeonGenerator {
}
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++){
Level temp = d.getLevel()[i];

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

@ -3,7 +3,7 @@ import com.dungeoncrawler.model.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);
this.maxhp = 5*lvl;

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

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