1
0
Fork 0

Add Objective generation | rename mainkaefer to bug

This commit is contained in:
Saibotk 2018-04-23 16:44:02 +02:00
parent 7914b4d9da
commit 1004f95997
10 changed files with 137 additions and 60 deletions

View file

@ -52,7 +52,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1303102899095328} m_GameObject: {fileID: 1303102899095328}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 7.6580257, y: 3.506653, z: -0.08491792} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 4615957218218632} - {fileID: 4615957218218632}

View file

@ -623,6 +623,11 @@ Prefab:
propertyPath: m_IsActive propertyPath: m_IsActive
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 60772848946696534, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -721,6 +726,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5d9a051e822e2cf4ea3ca01c5a4df37c, type: 3} m_Script: {fileID: 11500000, guid: 5d9a051e822e2cf4ea3ca01c5a4df37c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
followSpeed: 0.05
minZoom: 5
zoomFactor: 4
zoomSpeed: 0.05
startingDist: 5
followThis: {fileID: 0} followThis: {fileID: 0}
--- !u!114 &881384373 --- !u!114 &881384373
MonoBehaviour: MonoBehaviour:
@ -741,6 +751,11 @@ MonoBehaviour:
- {fileID: 1908750963} - {fileID: 1908750963}
- {fileID: 368878861} - {fileID: 368878861}
- {fileID: 1908750963} - {fileID: 1908750963}
--- !u!1 &979562542 stripped
GameObject:
m_PrefabParentObject: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a,
type: 2}
m_PrefabInternal: {fileID: 1597985551}
--- !u!1 &1028937042 --- !u!1 &1028937042
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -966,7 +981,7 @@ Prefab:
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 67.14285 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2} type: 2}
@ -1045,6 +1060,10 @@ Prefab:
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 5 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -1366,6 +1385,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 87d25c2cd3eb97749b79f2cb5f7c5cea, type: 3} m_Script: {fileID: 11500000, guid: 87d25c2cd3eb97749b79f2cb5f7c5cea, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
scorpion: {fileID: 979562542}
BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319, BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319,
type: 2} type: 2}
BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9, BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9,

View file

@ -1,20 +1,18 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Assets.Scripts.Entities.Attack; using Assets.Scripts.Entities.Attack;
namespace Assets.Scripts.Entities { namespace Assets.Scripts.Entities {
public class Maikäfer : MonoBehaviourEnemy { public class Bug : Enemy {
public Bug() : base(15) {
public Maikäfer() : base(15)
{
} }
private void Start() private void Start() {
{
SetAttack(new MeleeAttack(this.gameObject)); SetAttack(new MeleeAttack(this.gameObject));
} }
} }
} }

View file

@ -4,7 +4,11 @@ using UnityEngine;
using Assets.Scripts.Entities.Attack; using Assets.Scripts.Entities.Attack;
namespace Assets.Scripts.Entities { namespace Assets.Scripts.Entities {
class Enemy : Mob { public class Enemy : Mob {
public enum Enemys {
SCORPION,
BUG
}
[SerializeField] [SerializeField]
private float speed = 1; private float speed = 1;

View file

@ -3,18 +3,18 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Assets.Scripts.Entities.Attack; using Assets.Scripts.Entities.Attack;
namespace Assets.Scripts.Entities namespace Assets.Scripts.Entities
{ {
class Spider : Enemy class Spider : Enemy
{ {
public Spider() : base(45) public Spider() : base(45)
{ {
} }
private void Start() private void Start()
{ {
SetAttack(new SingleShot(this.gameObject)); SetAttack(new SingleShot(this.gameObject));
} }
} }
} }

View file

@ -1,11 +1,10 @@
using System.Collections; using Assets.Scripts.Entities;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class GameController : MonoBehaviour { public class GameController : MonoBehaviour {
private Room start; private Room start;
private Room finish; private Room finish;
@ -13,6 +12,12 @@ public class GameController : MonoBehaviour {
WIN, DIED WIN, DIED
} }
// Enemy Prefabs
[Header("Enemys")]
[SerializeField]
GameObject scorpion;
[Space(10)]
// Generation Settings // Generation Settings
[Header("Tile Prefabs")] [Header("Tile Prefabs")]
[SerializeField] [SerializeField]
@ -61,6 +66,7 @@ public class GameController : MonoBehaviour {
GameObject RockLRD; GameObject RockLRD;
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs; private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
private Dictionary<Enemy.Enemys, GameObject> enemyPrefabs;
[Space(10)] [Space(10)]
[Header("References")] [Header("References")]
@ -91,29 +97,34 @@ public class GameController : MonoBehaviour {
// Use this for initialization // Use this for initialization
void Start () { void Start () {
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject>(); genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject> {
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter); { GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderInner, BorderInner); { GenerationProcessor.ExtendedTileType.BorderInner, BorderInner },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle); { GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Rock, Rock); { GenerationProcessor.ExtendedTileType.Rock, Rock },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockL, RockL); { GenerationProcessor.ExtendedTileType.RockL, RockL },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockU, RockU); { GenerationProcessor.ExtendedTileType.RockU, RockU },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockR, RockR); { GenerationProcessor.ExtendedTileType.RockR, RockR },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockD, RockD); { GenerationProcessor.ExtendedTileType.RockD, RockD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLU, RockLU); { GenerationProcessor.ExtendedTileType.RockLU, RockLU },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLR, RockLR); { GenerationProcessor.ExtendedTileType.RockLR, RockLR },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLD, RockLD); { GenerationProcessor.ExtendedTileType.RockLD, RockLD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLURD, RockLURD); { GenerationProcessor.ExtendedTileType.RockLURD, RockLURD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockRD, RockRD); { GenerationProcessor.ExtendedTileType.RockRD, RockRD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUR, RockUR); { GenerationProcessor.ExtendedTileType.RockUR, RockUR },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUD, RockUD); { GenerationProcessor.ExtendedTileType.RockUD, RockUD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUD, RockLUD); { GenerationProcessor.ExtendedTileType.RockLUD, RockLUD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUR, RockLUR); { GenerationProcessor.ExtendedTileType.RockLUR, RockLUR },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockURD, RockURD); { GenerationProcessor.ExtendedTileType.RockURD, RockURD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLRD, RockLRD); { GenerationProcessor.ExtendedTileType.RockLRD, RockLRD },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Ground, Ground); { GenerationProcessor.ExtendedTileType.Ground, Ground },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.DoorInner, DoorInner); { GenerationProcessor.ExtendedTileType.DoorInner, DoorInner },
genPrefabs.Add(GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter); { GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter }
};
enemyPrefabs = new Dictionary<Enemy.Enemys, GameObject> {
{ Enemy.Enemys.SCORPION, scorpion }
};
} }
// Update is called once per frame // Update is called once per frame
@ -176,7 +187,7 @@ public class GameController : MonoBehaviour {
}); });
start.SetDoorsRootObject(doorRoot); start.SetDoorsRootObject(doorRoot);
// WIP // Spawnpoint
GameObject spawnpointRoot = new GameObject(); GameObject spawnpointRoot = new GameObject();
spawnpointRoot.name = "Spawnpoints"; spawnpointRoot.name = "Spawnpoints";
spawnpointRoot.transform.SetParent(goStart.transform); spawnpointRoot.transform.SetParent(goStart.transform);
@ -210,6 +221,8 @@ public class GameController : MonoBehaviour {
foreach (GenRoom gr in dg.rooms) { foreach (GenRoom gr in dg.rooms) {
GameObject groom = gp.ProcessRoom(gr.tiles); GameObject groom = gp.ProcessRoom(gr.tiles);
List<Transform> ltg = new List<Transform>(groom.GetComponentsInChildren<Transform>()); List<Transform> ltg = new List<Transform>(groom.GetComponentsInChildren<Transform>());
// Doors
GameObject doorRootg = new GameObject(); GameObject doorRootg = new GameObject();
doorRootg.name = "Doors"; doorRootg.name = "Doors";
doorRootg.transform.SetParent(groom.transform); doorRootg.transform.SetParent(groom.transform);
@ -219,9 +232,22 @@ public class GameController : MonoBehaviour {
x.SetParent(doorRootg.transform); x.SetParent(doorRootg.transform);
x.gameObject.GetComponent<Door>().SetParent(grom); x.gameObject.GetComponent<Door>().SetParent(grom);
}); });
// Spawnpoints
GameObject tSpawnpointRoot = new GameObject();
tSpawnpointRoot.name = "Spawnpoints";
tSpawnpointRoot.transform.SetParent(groom.transform);
tSpawnpointRoot.transform.position = new Vector3(gr.roomPosition.x, gr.roomPosition.y, 0);
foreach(Vector2Int v in gr.spawnpoints) {
GameObject tspawn = new GameObject();
tspawn.transform.SetParent(tSpawnpointRoot.transform);
tspawn.transform.position = new Vector3(v.x, v.y, 0); // is this the center or the top left corner of a block?
}
grom.SetSpawnPointsRootObject(tSpawnpointRoot);
grom.SetDoorsRootObject(doorRootg); grom.SetDoorsRootObject(doorRootg);
grom.Reload(); grom.Reload();
DungeonGenerator.GenerateObjective(grom);
groom.transform.SetParent(mapRoot.transform); groom.transform.SetParent(mapRoot.transform);
} }
@ -277,6 +303,10 @@ public class GameController : MonoBehaviour {
return ui.GetComponent<UIController>(); return ui.GetComponent<UIController>();
} }
public Dictionary<Enemy.Enemys, GameObject> GetEnemyPrefabs() {
return enemyPrefabs;
}
public bool GameEnded() { public bool GameEnded() {
return state == GameState.ENDED; return state == GameState.ENDED;
} }

View file

@ -1,4 +1,5 @@
using System; using Assets.Scripts.Entities;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -214,13 +215,13 @@ public class DungeonGenerator {
} }
foreach ( GenRoom r in rooms ) foreach ( GenRoom r in rooms )
makeRoomRelative(r); MakeRoomRelative(r);
makeRoomRelative(start); MakeRoomRelative(start);
makeRoomRelative(end); MakeRoomRelative(end);
makeRoomRelative(path); MakeRoomRelative(path);
} }
public void makeRoomRelative(GenRoom room) { public void MakeRoomRelative(GenRoom room) {
room.roomPosition = room.bounds.position; room.roomPosition = room.bounds.position;
foreach ( Vector2Int v in room.tiles.Keys ) { foreach ( Vector2Int v in room.tiles.Keys ) {
v.Set(( v - room.roomPosition ).x, ( v - room.roomPosition ).y); v.Set(( v - room.roomPosition ).x, ( v - room.roomPosition ).y);
@ -439,4 +440,20 @@ public class DungeonGenerator {
} }
} }
} }
public static void GenerateObjective(Room r) {
Dictionary<Enemy.Enemys, GameObject> enemyPrefabs = GameController.instance.GetEnemyPrefabs(); // TODO not so cool
// TODO add more types
Objective o;
// ENTITYOBJECTIVE ENEMYS:
List<GameObject> lg = new List<GameObject>();
//GameObject scorp = enemyPrefabs[Enemy.Enemys.SCORPION];
lg.Add(enemyPrefabs[Enemy.Enemys.SCORPION]);
EntityObjective eo = new EntityObjective(r, lg);
o = eo;
r.SetObjective(o);
}
} }

View file

@ -19,6 +19,7 @@ public class GenRoom {
// All positions are in room space relative to the room's anchor // All positions are in room space relative to the room's anchor
public Dictionary<Vector2Int, GenTile> tiles = new Dictionary<Vector2Int, GenTile>(); public Dictionary<Vector2Int, GenTile> tiles = new Dictionary<Vector2Int, GenTile>();
public HashSet<Vector2Int> spawnpoints = new HashSet<Vector2Int>(); public HashSet<Vector2Int> spawnpoints = new HashSet<Vector2Int>();
public Objective objective = null;
public float Distance(GenRoom r) { public float Distance(GenRoom r) {
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y); return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);

View file

@ -1,4 +1,5 @@
using System.Collections; using Assets.Scripts.Entities;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -26,13 +27,19 @@ public class EntityObjective : Objective {
public override void ActivateGoal(Player ply) { public override void ActivateGoal(Player ply) {
if ( activated ) if ( activated )
return; return;
activated = true;
base.ActivateGoal(ply); base.ActivateGoal(ply);
foreach ( GameObject i in prefabList ) { foreach ( GameObject i in prefabList ) {
Debug.Log("[ROOMS] Spawning Entity..."); Debug.Log("[ROOMS] Spawning Entity...");
if(i == null || player == null) {
Debug.Log("[ROOMS] Failed.. Entity not set in GameController!");
return;
}
GameObject tempObject = GameObject.Instantiate(i); GameObject tempObject = GameObject.Instantiate(i);
List<Transform> spawnPointList = room.GetSpawnpoints(); List<Transform> spawnPointList = room.GetSpawnpoints();
tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position; tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position;
tempObject.GetComponent<Enemy>().SetVictim(player.gameObject);
tempObject.GetComponent<Enemy>().SetObjective(this);
entityList.Add(tempObject); entityList.Add(tempObject);
} }