Skip to content
This repository has been archived by the owner on Dec 28, 2019. It is now read-only.

Commit

Permalink
Die Dämonen im Inneren dieser Branch besiegt
Browse files Browse the repository at this point in the history
Amen
  • Loading branch information
S-Florian committed May 29, 2017
1 parent 0381859 commit 82ef51f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Platformer_001/Assets/Scenes (Level)/Kampagne.unity
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ MonoBehaviour:
prefab: {fileID: 1792102471104630, guid: c7876e361f641a843950a49414b9a42a, type: 2}
- type: 1
prefab: {fileID: 1967912431008734, guid: 4ab129c002285f14f9c17592c97c6f5e, type: 2}
- type: 2
prefab: {fileID: 1660809210920558, guid: 69447e927c1931b44b083bcc73254aff, type: 2}
backgroundImages:
- {fileID: 21300000, guid: 39b71b37258efbc4fa8352f20d1ce00c, type: 3}
tileSize: 2
Expand Down
26 changes: 24 additions & 2 deletions Platformer_001/Assets/Scripts/Kampagne/LevelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class LevelGenerator : MonoBehaviour {
[Serializable]
public enum LevelObjectType {
Tile,
Item
Item,
Enemy
};

[Serializable]
Expand Down Expand Up @@ -60,13 +61,15 @@ public struct Level

private readonly Dictionary<int, ObjectDef> idTileDict = new Dictionary<int, ObjectDef>();
private readonly Dictionary<int, ObjectDef> idItemDict = new Dictionary<int, ObjectDef>();
private readonly Dictionary<int, ObjectDef> idEnemyDict = new Dictionary<int, ObjectDef>();

private readonly Dictionary<LevelObjectType, GameObject> prefabDefaultDict = new Dictionary<LevelObjectType, GameObject>();

private Dictionary<int, LevelObjectType> idToType = new Dictionary<int, LevelObjectType>();

public LevelGenerator() {
idToType[0x00] = LevelObjectType.Tile;
idToType[0x2F] = LevelObjectType.Enemy;
idToType[0xFF] = LevelObjectType.Item;
}

Expand Down Expand Up @@ -98,10 +101,13 @@ void Start() {
idItemDict[cts.colour.g] = def;
break;

case LevelObjectType.Enemy:
idEnemyDict[cts.colour.g] = def;
break;

default:
break;
}

}

foreach (PrefabDefault d in defaultPrefabs) {
Expand All @@ -126,6 +132,12 @@ private void CommonDecode(Dictionary<int, ObjectDef> dict, int id, Action<Object
if (!dict.ContainsKey(id)) return;

var objDef = dict[id];

if (!prefabDefaultDict.ContainsKey (objDef.type)) {
print (objDef.type + " " + objDef.sprite.name);
return;
}

if (objDef.prefab == null) objDef.prefab = prefabDefaultDict[objDef.type];
f(objDef, id);
}
Expand All @@ -140,6 +152,10 @@ private void DecodeMapInfo(Color32 pixel, int x, int y) {
CommonDecode(idItemDict, pixel.g, (def, id) => SpawnItemAt(def, id, x, y));
break;

case 0x2F:
CommonDecode(idEnemyDict, pixel.g, (def, id) => SpawnEnemyAt(def, id, x, y));
break;

case 0x7F:
spawnPoint.Set(x, y + 1.0f);
break;
Expand Down Expand Up @@ -229,6 +245,12 @@ private GameObject SpawnItemAt(ObjectDef objDef, int id, int x, int y) {
return obj;
}

private GameObject SpawnEnemyAt(ObjectDef objDef, int id, int x, int y){
if (objDef.prefab == null) return null;
var obj = Instantiate(objDef.prefab, new Vector2(x, y), Quaternion.identity, transform);
return obj;
}

public void NeuGenerieren() {
EmptyMap();
LoadMap();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82ef51f

Please sign in to comment.