From 0ea5229e9930282aa2306b55e15c6c2af8ac0845 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Sat, 2 May 2020 22:03:42 +0200 Subject: [PATCH] naja --- .../dungeoncrawler/control/Controller.java | 20 +++++---- core/src/com/dungeoncrawler/model/Entity.java | 6 +++ .../dungeoncrawler/model/entities/Arrow.java | 9 +++- .../com/dungeoncrawler/view/GameScreen.java | 42 +++---------------- 4 files changed, 31 insertions(+), 46 deletions(-) diff --git a/core/src/com/dungeoncrawler/control/Controller.java b/core/src/com/dungeoncrawler/control/Controller.java index e1d7c02..9c2992c 100644 --- a/core/src/com/dungeoncrawler/control/Controller.java +++ b/core/src/com/dungeoncrawler/control/Controller.java @@ -13,7 +13,6 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.maps.MapLayers; -import com.badlogic.gdx.maps.MapObject; import com.badlogic.gdx.maps.MapObjects; import com.badlogic.gdx.maps.objects.RectangleMapObject; import com.badlogic.gdx.math.Intersector; @@ -24,11 +23,7 @@ import com.dungeoncrawler.model.DungeonGenerator; import com.dungeoncrawler.model.entities.*; import com.dungeoncrawler.model.Entity; import com.badlogic.gdx.utils.Timer; -import com.dungeoncrawler.model.Item; import com.dungeoncrawler.model.ItemContainer; -import com.dungeoncrawler.model.items.Key; -import com.dungeoncrawler.model.items.Potion; -import com.dungeoncrawler.model.items.Amulet; import java.util.ArrayList; public class Controller extends ApplicationAdapter implements InputProcessor{ @@ -125,10 +120,15 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ boolean delete = false; if(Intersector.overlaps(tempObject.getBoundingRectangle(), playerSprite)){ overlaps = true; + if(d.getCurrentEntities()[i].getId() == 2){ - d.getCurrentEntities()[i].attack(d.getPlayer()); delete = true; + d.getCurrentEntities()[i].attack(d.getPlayer()); } + else{ + + } + } else{ for(RectangleMapObject rectangleObject : mapObjects.getByType(RectangleMapObject.class)){ @@ -155,7 +155,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } - + if(overlaps){ d.getCurrentEntities()[i].setxPos(x); d.getCurrentEntities()[i].setyPos(y); @@ -175,7 +175,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } - if(delete && d.getCurrentEntities()[i].getId() == 2){ + if(delete && d.getCurrentEntities()[i].getId() == 2 || d.getCurrentEntities()[i].getToDelete()){ d.getCurrentEntities()[i] = null; m.updateEntitySprite(d.getCurrentEntities()); @@ -353,6 +353,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ d.setCurrentEntities(d.getCurrentRoom().getEnemies()); } + public void attack(Entity attacker, Entity[] e){ + + } + public ArrayList playerPickUp(){ ArrayList tempItems = d.getCurrentRoom().getItems(); diff --git a/core/src/com/dungeoncrawler/model/Entity.java b/core/src/com/dungeoncrawler/model/Entity.java index 01b36d6..dd0d4de 100644 --- a/core/src/com/dungeoncrawler/model/Entity.java +++ b/core/src/com/dungeoncrawler/model/Entity.java @@ -17,6 +17,7 @@ public abstract class Entity { protected int id; protected int direction; protected Inventory inv; + protected boolean toDelete; @@ -27,6 +28,7 @@ public abstract class Entity { this.movementX = 0; this.movementY = 0; this.direction = 2; + this.toDelete = false; } public void attack(Entity e){ @@ -149,4 +151,8 @@ public abstract class Entity { this.direction = direction; } + public boolean getToDelete(){ + return this.toDelete; + } + } \ No newline at end of file diff --git a/core/src/com/dungeoncrawler/model/entities/Arrow.java b/core/src/com/dungeoncrawler/model/entities/Arrow.java index 598d4e6..5b4b8c6 100644 --- a/core/src/com/dungeoncrawler/model/entities/Arrow.java +++ b/core/src/com/dungeoncrawler/model/entities/Arrow.java @@ -12,6 +12,7 @@ public class Arrow extends Entity{ float xStart; float yStart; int direction; + int lifetime; public Arrow(float xPos, float yPos, int lvl, int direction){ super(xPos, yPos, lvl); @@ -20,7 +21,7 @@ public class Arrow extends Entity{ this.direction = direction; this.dmg = 3*lvl; this.id = 2; - + this.lifetime = 0; } public float getxStart(){ @@ -32,9 +33,15 @@ public class Arrow extends Entity{ @Override public Entity move(int xPosPlayer, int yPosPlayer) { + lifetime++; + xPos += movementX; yPos += movementY; + if(this.lifetime > 50){ + this.toDelete = true; + } + return null; } } diff --git a/core/src/com/dungeoncrawler/view/GameScreen.java b/core/src/com/dungeoncrawler/view/GameScreen.java index bdd79bb..69bf5f4 100644 --- a/core/src/com/dungeoncrawler/view/GameScreen.java +++ b/core/src/com/dungeoncrawler/view/GameScreen.java @@ -253,11 +253,6 @@ public class GameScreen { mapItem.getSprite().draw(batch); } - // Player wird gedrawt - for(Sprite sprite : player.getSprites()){ - sprite.draw(batch); - } - //controls.draw(batch); //DRAW'T JEDES ENTITY - prueft vorher ob vorhanden for(int i = 0; i < e.length; i++){ @@ -317,6 +312,11 @@ public class GameScreen { } } + // Player wird gedrawt + for(Sprite sprite : player.getSprites()){ + sprite.draw(batch); + } + /* for(int i = 0; i < arrowSprites.length; i++){ if(arrowSprites[i] != null){ @@ -448,38 +448,6 @@ public class GameScreen { return e; } - /* - public void moveItem(int i){ - if(i == 0){ - if(InventoryItemSprites[i] != null){ - for(int n = 2; n < InventoryItemSprites.length ; n++){ - if(InventoryItemSprites[n] == null){ - InventoryItemTextures[n] = InventoryItemTextures[i]; - InventoryItemSprites[n] = InventoryItemSprites[i]; - } - } - } - } - } - - */ - - - /* - public ItemContainer playerPickUp(ItemContainer[] items, Player p){ - for(int i = 0; i < items.length; i++){ - if(items[i] != null){ - if(Intersector.overlaps(player.getBoundingRectangle(), itemSprite[i].getBoundingRectangle())){ - player.pickUp(items[i].getItem()); - items[i] = null; - } - } - - } - return items; - } - */ - public void cleanUp(){ music.dispose(); }