From 9f1170c9597fc64071868af9f4939214b9810437 Mon Sep 17 00:00:00 2001 From: GammelJan Date: Mon, 13 Apr 2020 23:11:13 +0200 Subject: [PATCH] ULTRA MEGA BUG --- core/src/THE_VOID/ArcherKI.java | 57 ++++++ .../dungeoncrawler/control/Controller.java | 56 ++++-- core/src/com/dungeoncrawler/model/Entity.java | 189 +++++++++++++----- .../dungeoncrawler/model/entities/Archer.java | 2 +- .../dungeoncrawler/model/entities/Arrow.java | 87 ++++++++ .../model/entities/Swordsman.java | 2 +- .../com/dungeoncrawler/view/GameScreen.java | 24 ++- 7 files changed, 334 insertions(+), 83 deletions(-) create mode 100644 core/src/THE_VOID/ArcherKI.java create mode 100644 core/src/com/dungeoncrawler/model/entities/Arrow.java diff --git a/core/src/THE_VOID/ArcherKI.java b/core/src/THE_VOID/ArcherKI.java new file mode 100644 index 0000000..7012756 --- /dev/null +++ b/core/src/THE_VOID/ArcherKI.java @@ -0,0 +1,57 @@ +package THE_VOID; + +/* + if(xPlayer == xPos){ //PLAYER auf X-Achse von Archer + if(yPlayer == yPos){} // //PLAYER pos = Archer pos + else if(yPlayer > yPos){movementY = 1f;} // //PLAYER ueber Archer + else if(yPlayer < yPos){movementY = -1f;} // //PLAYER unter Archer + } // + else if(yPlayer == yPos){ //PLAYER auf Y-Achse von Archer + if(xPlayer == xPos){} // //PLAYER pos = Archer pos + else if(xPlayer > xPos){movementX = 1f;} // //PLAYER rechts von Archer + else if(xPlayer < xPos){movementX = -1f;} // //PLAYER links von Archer + } // + else if(xPlayer > xPos){ //PLAYER rechts von Archer + if(yPlayer > yPos){ // //PLAYER ist im Quadrant I + if((yPlayer - yPos) > (xPlayer - xPos)){ // // //Weg zu PLAYER x kuerzer als zu PLAYER y + movementX = 1f; // // // + } // // // + else{ // // //Weg zu PLAYER y kuerzer als zu PLAYER x + movementY = 1f; // // + } // // + } // // + else if(yPlayer < yPos){ // //PLAYER ist im Quadrant II + if((yPos - yPlayer) > (xPlayer - xPos)){ // //Weg zu PLAYER x kuerzer als zu PLAYER y + movementX = 1f; // // + } // // + else{ // //Weg zu PLAYER y kuerzer als zu PLAYER y + movementY = -1f; // + } // + } // + } // + else if(xPlayer < xPos){ //PLAYER links von Archer + if(yPlayer < yPos){ // //PLAYER ist im Quadrant III + if((yPlayer - yPos) > (xPlayer - xPos)){ // // //Weg zu PLAYER x kuerzer als zu PLAYER y + movementX = -1f; // // // + } // // // + else{ // // //Weg zu PLAYER y kuerzer als zu PLAYER x + movementY = -1f; // // + } // // + } // // + else if(yPlayer > yPos){ // //PLAYER ist im Quadrant IV + if((yPlayer - yPos) > (xPos - xPlayer)){ // //Weg zu PLAYER x kuerzer als zu PLAYER y + movementX = -1; // // + } // // + else{ // //Weg zu PLAYER y kuerzer als zu PLAYER x + movementY = 1; // + } //////////// + } + } + + if(yPos + movementY < 0){ + + } + else if(xPos + movementX < 0){ + + }*/ + diff --git a/core/src/com/dungeoncrawler/control/Controller.java b/core/src/com/dungeoncrawler/control/Controller.java index 3de2d10..5c0e5a2 100644 --- a/core/src/com/dungeoncrawler/control/Controller.java +++ b/core/src/com/dungeoncrawler/control/Controller.java @@ -23,7 +23,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ DungeonGenerator dg; MainMenu v; Entity[] e; - Timer t; + Timer tEntities; GameScreen m; int[] tile; int[] posRoom; @@ -31,13 +31,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ int roomX; int roomY; + Entity[] arrows; + + + @Override public void create(){ - //TEST - - //TEST - + arrows = new Entity[10]; roomX = 8; roomY = 6; @@ -46,6 +47,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v = new MainMenu(); dg = new DungeonGenerator(); + d = dg.generateDungeon(0, 0, 0, new Player()); dg.ichWillSpielen(d); @@ -81,18 +83,23 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ e = new Entity[5]; Gdx.input.setInputProcessor(this); - t = new Timer(); + tEntities = new Timer(); - t.scheduleTask(new Timer.Task() { + tEntities.scheduleTask(new Timer.Task() { @Override public void run() { for(int i = 0; i< e.length; i++){ if(e[i] == null){} else{ - if(Math.random() < 0.05){ - m.arrow(e[i].direction(), e[i].getxPos(), e[i].getyPos()); + if(Math.random() < 0.05){ //Attacks with a chance of 5% every move + for(int n = 0; n < arrows.length; n++){ + if(arrows[n] == null){ + //arrows[n] = new Arrow(e[i].getxPos(), e[i].getyPos(), e[i].getLvl(), e[i].direction()); + //m.newEntity(n,arrows[n],e[i].getxPos(),e[i].getyPos()); + } + } } - e[i].rdmMove(d.getPlayer().getxPos(), d.getPlayer().getyPos()); + e[i].rdmMove(); m.setPlayerSpriteX(d.getPlayer().getxPos()); m.setPlayerSpriteY(d.getPlayer().getyPos()); m.setEntitySpriteX(i, d.getPlayer().getxPos()); @@ -100,7 +107,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } } - },0,0.1f); + },0,0.4f); + + } @@ -111,7 +120,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v.render(batch, d.getPlayer() , e); } - //PASSIERT IN GAMESCREEN (view) + //PASSIERT IN GAMESCREEN if(m != null){ //ENTITIES d.getPlayer().setxPos(m.getPlayerSpriteX()); @@ -125,7 +134,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ updateRoom(); // Render methode zum rendern der einzelnen Sprites wird aufgerufen - m.render(batch, d.getPlayer(), e, tile, level, posRoom); + m.render(batch, d.getPlayer(), e, arrows, tile, level, posRoom); } } } @@ -189,7 +198,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } - public void newEntity(Entity ent, int x, int y, int lvl){ + public void newEntity(Entity ent, float x, float y, int lvl){ for(int i = 0; i < e.length ; i++){ if(e[i] == null){ switch(ent.getId()){ @@ -206,7 +215,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } } - } + } + @Override public boolean keyDown(int keycode) { @@ -215,7 +225,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v.moveCursor(3); } if(m != null){ - d.getPlayer().setMovementX(-3); + d.getPlayer().setMovementX(-3f); } } @@ -224,7 +234,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v.moveCursor(1); } if(m != null){ - d.getPlayer().setMovementX(3); + d.getPlayer().setMovementX(+3f); } } @@ -233,7 +243,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v.moveCursor(2); } if(m != null){ - d.getPlayer().setMovementY(-3); + d.getPlayer().setMovementY(-3f); } } @@ -242,7 +252,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v.moveCursor(0); } if(m != null){ - d.getPlayer().setMovementY(3); + d.getPlayer().setMovementY(3f); } } @@ -253,7 +263,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ v = null; m = new GameScreen(d); Archer a = new Archer(0,0,0); - newEntity(a,0,0,0); + newEntity(a,96,96,0); + Swordsman s = new Swordsman(0,0,0); + newEntity(s,288,96,0); System.out.println("NICE"); } } @@ -340,4 +352,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ public boolean scrolled(int i) { return false; } + + + + } diff --git a/core/src/com/dungeoncrawler/model/Entity.java b/core/src/com/dungeoncrawler/model/Entity.java index d5b9559..53e1674 100644 --- a/core/src/com/dungeoncrawler/model/Entity.java +++ b/core/src/com/dungeoncrawler/model/Entity.java @@ -1,5 +1,7 @@ package com.dungeoncrawler.model; +import com.badlogic.gdx.utils.Timer; + public abstract class Entity { @@ -12,13 +14,92 @@ public abstract class Entity { protected float movementX; protected float movementY; protected int id; + + Timer tup; + Timer tright; + Timer tdown; + Timer tleft; + int timerRuns; + boolean isRunning; + int facing; - public Entity(int xPos, float 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; + + + tup = new Timer(); + 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); + setIsRunning(true); + setyPos(getyPos() + 1f); + setTimerRuns(getTimerRuns() + 1); + if(getTimerRuns() >= 48){ + setTimerRuns(0); + setIsRunning(false); + tup.stop(); + } + } + },0,0.03f); + tup.stop(); + tright.scheduleTask(new Timer.Task() { + @Override + public void run() { + setFacing(1); + setIsRunning(true); + setxPos(getxPos() + 1f); + setTimerRuns(getTimerRuns() + 1); + if(getTimerRuns() >= 48){ + setTimerRuns(0); + setIsRunning(false); + tright.stop(); + } + } + },0,0.03f); + tright.stop(); + tdown.scheduleTask(new Timer.Task() { + @Override + public void run() { + setFacing(2); + setIsRunning(true); + setyPos(getyPos() - 1f); + setTimerRuns(getTimerRuns() + 1); + if(getTimerRuns() >= 48){ + setTimerRuns(0); + setIsRunning(false); + tdown.stop(); + } + } + },0,0.03f); + tdown.stop(); + tleft.scheduleTask(new Timer.Task() { + @Override + public void run() { + setFacing(3); + setIsRunning(true); + setxPos(getxPos() - 1f); + setTimerRuns(getTimerRuns() + 1); + + if(getTimerRuns() >= 48){ + setTimerRuns(0); + setIsRunning(false); + tleft.stop(); + } + } + },0,0.03f); + tleft.stop(); } @@ -40,64 +121,44 @@ public abstract class Entity { movementY = 0; } - public void rdmMove(float xPlayer, float yPlayer){ + public void rdmMove(){ + double i = Math.random(); - if(xPlayer == xPos){ //PLAYER auf X-Achse von Archer - if(yPlayer == yPos){} // //PLAYER pos = Archer pos - else if(yPlayer > yPos){movementY = 1f;} // //PLAYER ueber Archer - else if(yPlayer < yPos){movementY = -1f;} // //PLAYER unter Archer - } // - else if(yPlayer == yPos){ //PLAYER auf Y-Achse von Archer - if(xPlayer == xPos){} // //PLAYER pos = Archer pos - else if(xPlayer > xPos){movementX = 1f;} // //PLAYER rechts von Archer - else if(xPlayer < xPos){movementX = -1f;} // //PLAYER links von Archer - } // - else if(xPlayer > xPos){ //PLAYER rechts von Archer - if(yPlayer > yPos){ // //PLAYER ist im Quadrant I - if((yPlayer - yPos) > (xPlayer - xPos)){ // // //Weg zu PLAYER x kuerzer als zu PLAYER y - movementX = 1f; // // // - } // // // - else{ // // //Weg zu PLAYER y kuerzer als zu PLAYER x - movementY = 1f; // // - } // // - } // // - else if(yPlayer < yPos){ // //PLAYER ist im Quadrant II - if((yPos - yPlayer) > (xPlayer - xPos)){ // //Weg zu PLAYER x kuerzer als zu PLAYER y - movementX = 1f; // // - } // // - else{ // //Weg zu PLAYER y kuerzer als zu PLAYER y - movementY = -1f; // - } // - } // - } // - else if(xPlayer < xPos){ //PLAYER links von Archer - if(yPlayer < yPos){ // //PLAYER ist im Quadrant III - if((yPlayer - yPos) > (xPlayer - xPos)){ // // //Weg zu PLAYER x kuerzer als zu PLAYER y - movementX = -1f; // // // - } // // // - else{ // // //Weg zu PLAYER y kuerzer als zu PLAYER x - movementY = -1f; // // - } // // - } // // - else if(yPlayer > yPos){ // //PLAYER ist im Quadrant IV - if((yPlayer - yPos) > (xPos - xPlayer)){ // //Weg zu PLAYER x kuerzer als zu PLAYER y - movementX = -1; // // - } // // - else{ // //Weg zu PLAYER y kuerzer als zu PLAYER x - movementY = 1; // - } //////////// + if(i <= 0.2){ + if(isRunning == false){ + tup.start(); + } + } + else if(i > 0.2 && i <= 0.4){ + if(isRunning == false){ + tright.start(); + } + } + else if(i > 0.4 && i <= 0.6){ + if(isRunning == false){ + if(yPos == 0){ + } + else{ + tdown.start(); } } - if(yPos + movementY < 0){ - } - else if(xPos + movementX < 0){ - + else if(i > 0.6 && i <= 0.8){ + if(isRunning == false){ + if(xPos == 0){ + } + else{ + tleft.start(); + } + } } else{ - move(); - } + facing = 2; } + + + move(); + } public int direction(){ // returns direction the entity is facing depending on its movement if(movementX < 0f){ // TIS IS SHIT - NEED REWORK @@ -184,4 +245,28 @@ public abstract class Entity { public int getId(){ return this.id; } + + private void setIsRunning(boolean n){ + isRunning = n; + } + private boolean getIsRunning(){ + return isRunning; + } + + public int getTimerRuns(){ + return timerRuns; + } + + public void setTimerRuns(int n){ + timerRuns = n; + } + + public void setFacing(int i){ + facing = i; + } + + public int getFacing(){ + return facing; + } + } \ No newline at end of file diff --git a/core/src/com/dungeoncrawler/model/entities/Archer.java b/core/src/com/dungeoncrawler/model/entities/Archer.java index a55f8e7..a989a39 100644 --- a/core/src/com/dungeoncrawler/model/entities/Archer.java +++ b/core/src/com/dungeoncrawler/model/entities/Archer.java @@ -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; diff --git a/core/src/com/dungeoncrawler/model/entities/Arrow.java b/core/src/com/dungeoncrawler/model/entities/Arrow.java new file mode 100644 index 0000000..a40ade0 --- /dev/null +++ b/core/src/com/dungeoncrawler/model/entities/Arrow.java @@ -0,0 +1,87 @@ +/* + * 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.dungeoncrawler.model.entities; + +import com.dungeoncrawler.model.Entity; +import com.badlogic.gdx.utils.Timer; + + +public class Arrow extends Entity{ + Timer toben; + Timer tunten; + Timer trechts; + Timer tlinks; + float xStart; + float yStart; + int direction; + + public Arrow(float xPos, float yPos, int lvl, int direction){ + super(xPos, yPos, lvl); + xStart = xPos; + yStart = yPos; + Timer toben = new Timer(); + Timer tunten = new Timer(); + Timer trechts = new Timer(); + Timer tlinks = new Timer(); + this.direction = direction; + this.dmg = 3*lvl; + 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(){ + return xStart; + } + public float getyStart(){ + return yStart; + } +} diff --git a/core/src/com/dungeoncrawler/model/entities/Swordsman.java b/core/src/com/dungeoncrawler/model/entities/Swordsman.java index 710cfc9..6f9faa9 100644 --- a/core/src/com/dungeoncrawler/model/entities/Swordsman.java +++ b/core/src/com/dungeoncrawler/model/entities/Swordsman.java @@ -3,7 +3,7 @@ import com.dungeoncrawler.model.Entity; public class Swordsman extends Entity { - public Swordsman(int xPos, int yPos, int lvl) { + public Swordsman(float xPos, float yPos, int lvl) { super(xPos, yPos, lvl); this.maxhp = 5*lvl; diff --git a/core/src/com/dungeoncrawler/view/GameScreen.java b/core/src/com/dungeoncrawler/view/GameScreen.java index f86fc29..42c0527 100644 --- a/core/src/com/dungeoncrawler/view/GameScreen.java +++ b/core/src/com/dungeoncrawler/view/GameScreen.java @@ -53,7 +53,6 @@ public class GameScreen { arrowTextures = new Texture[10]; arrowSprites = new Sprite[10]; - //Timer[] arrows = new Timer[10]; //MAP float w = Gdx.graphics.getWidth(); @@ -73,7 +72,7 @@ public class GameScreen { } - public void render (SpriteBatch batch, Player p, Entity[] e, int[] tile, int level, int[] posRoom) { + public void render (SpriteBatch batch, Player p, Entity[] e, Entity[] arrows, int[] tile, int level, int[] posRoom) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); @@ -147,11 +146,18 @@ public class GameScreen { entitySprites[i].draw(batch); } } + for(int i = 0; i < arrowSprites.length; i++){ + if(arrowSprites[i] != null){ + arrowSprites[i].setX(arrows[i].getxPos()); + arrowSprites[i].setY(arrows[i].getyPos()); + arrowSprites[i].draw(batch); + } + } batch.end(); } - public void newEntity(int i,Entity e, int x, int y){ + public void newEntity(int i,Entity e, float x, float y){ if(e.getId() == 0){ //nimmt entity ID -> 0 = Archer || 1 = Swordsman entityTextures[i] = new Texture("archer.png"); archerRegions = TextureRegion.split(entityTextures[i], 64, 64); @@ -167,15 +173,15 @@ public class GameScreen { entitySprites[i].setX(x); entitySprites[i].setY(y); } + else if(e.getId() == 2){ + arrowTextures[i] = new Texture("key.png"); + arrowSprites[i] = new Sprite(arrowTextures[i]); + arrowSprites[i].setX(x); + arrowSprites[i].setY(y); + } } - public void arrow(int direction, float x, float y){ - - - System.out.println("ATTACK"); - } - //GETTER public float getPlayerSpriteX(){ return player.getX();