Items sind ne geile Sache

master
Jonathan Hager 6 years ago
parent 4891d9ad78
commit cf183a0c88

@ -6,6 +6,7 @@
package com.dungeoncrawler.model;
import com.dungeoncrawler.model.entities.*;
import com.dungeoncrawler.model.items.Sword;
/**
*
@ -145,9 +146,92 @@ public class DungeonGenerator {
Room tempRoom = new Room(new ItemContainer[itemAmount], new Entity[enemyAmount]);
// Items werden generiert
int[][] belegt = new int[itemAmount][2];
for(int j = 0; j < belegt.length; j++){
belegt[j][0] = -1;
belegt[j][1] = -1;
}
for(int i = 0; i < itemAmount; i++){
int xTile;
int yTile;
boolean istFertig = false;
do {
System.out.println("läuft");
// Tiles des Entities werden generiert
xTile = generateTile(sizeX);
yTile = generateTile(sizeY);
// Test, ob Tiles bereits belegt
boolean hatGeklappt = true;
for(int j = 0; j < belegt.length; j++){
if(j != i){
if(xTile == belegt[j][0] && yTile == belegt[j][1]){
hatGeklappt = false;
break;
}
}
}
if(hatGeklappt == true){
// Tiles zum Array hinzufügen
for(int j = 0; j < belegt.length; j++){
if(belegt[j][0] == -1){
belegt[j][0] = xTile;
belegt[j][1] = yTile;
}
}
istFertig = true;
}
} while(!istFertig);
// Berechnung der Positionen
int xPos = xTile * tileSize;
int yPos = yTile * tileSize;
// Typ des Entities wird generiert
Item tempItem;
int id = (int) (Math.random() * 2);
switch(id){
case 0:
tempItem = new Sword(lvl);
break;
/*case 1:
temp = new Swordsman(xPos, yPos, lvl);
break;
*/
default:
tempItem = null;
}
if(tempItem == null){
System.out.println("Es gibt Probleme, schau mal beim Raumgenerator nach. Es sind sogar sehr problematische Probleme mit den Items");
}
ItemContainer tempContainer;
if(tempItem != null){
tempContainer = new ItemContainer(xPos, yPos, tempItem);
}
else{
tempContainer = null;
}
tempRoom.setItem(tempContainer, i);
}
// Entities werden generiert
int[][] belegt = new int[enemyAmount][2];
belegt = new int[enemyAmount][2];
for(int j = 0; j < belegt.length; j++){
belegt[j][0] = -1;
belegt[j][1] = -1;

@ -44,6 +44,10 @@ public class Room {
this.item = item;
}
public void setItem(ItemContainer item, int i) {
this.item[i] = item;
}
/**
* @return the enemies
*/

@ -49,6 +49,7 @@ public class GameScreen {
TiledMap tm;
OrthographicCamera camera;
ArrayList<AnimatedObject> objects;
ArrayList<AnimatedObject> mapItems;
Timer animations;
@ -127,6 +128,7 @@ public class GameScreen {
tm = getM().getMaps()[level][roomPosX][roomPosY].getMap();
objects = getM().getMaps()[level][roomPosX][roomPosY].getObjects();
mapItems = getM().getMaps()[level][roomPosX][roomPosY].getMapItems();
if(tm == null){
System.out.println("Dein scheiß geht net");
@ -185,6 +187,10 @@ public class GameScreen {
object.getSprite().draw(batch);
}
for(AnimatedObject mapItem : mapItems){
mapItem.getSprite().draw(batch);
}
player.draw(batch);
//controls.draw(batch);
//DRAW'T JEDES ENTITY - prueft vorher ob vorhanden

@ -15,10 +15,12 @@ import java.util.ArrayList;
public class MapContainer {
private TiledMap map;
private ArrayList<AnimatedObject> objects;
private ArrayList<AnimatedObject> mapItems;
public MapContainer(TiledMap map){
this.map = map;
this.objects = new ArrayList<>();
this.mapItems = new ArrayList<>();
}
/**
@ -49,4 +51,18 @@ public class MapContainer {
this.objects = objects;
}
/**
* @return the mapItems
*/
public ArrayList<AnimatedObject> getMapItems() {
return mapItems;
}
/**
* @param mapItems the mapItems to set
*/
public void setMapItems(ArrayList<AnimatedObject> mapItems) {
this.mapItems = mapItems;
}
}

@ -14,6 +14,8 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.Item;
import com.dungeoncrawler.model.ItemContainer;
import com.dungeoncrawler.model.Level;
import com.dungeoncrawler.model.Room;
@ -26,12 +28,13 @@ public class MapGenerator {
Texture tiles;
TextureRegion[][] splitTiles;
Texture torchT;
Texture sword;
public MapGenerator(Texture tiles){
this.tiles = tiles;
splitTiles = TextureRegion.split(this.tiles, 48, 48);
torchT = new Texture("sprites/torch.png");
//torch = TextureRegion.split(torchT, 48, 48);
sword = new Texture("sprites/sword.png");
}
public Map generateMap(Dungeon d){
@ -311,6 +314,19 @@ public class MapGenerator {
layers.add(dynamicLayer);
layers.add(staticLayer);
for(int i = 0; i < r.getItem().length; i++){
if(r.getItem()[i] != null){
ItemContainer container = r.getItem()[i];
Item item = container.getItem();
if(item.getId() == 2){
AnimatedObject swordSprite = new AnimatedObject(sword, 24, 24);
swordSprite.getSprite().setPosition(container.getxPos(), container.getyPos());
temp.getMapItems().add(swordSprite);
}
}
}
return temp;
}

Loading…
Cancel
Save