From 1004f959979f4baa8e7a97d0363f79d0a404d70f Mon Sep 17 00:00:00 2001 From: Saibotk Date: Mon, 23 Apr 2018 16:44:02 +0200 Subject: [PATCH] Add Objective generation | rename mainkaefer to bug --- Assets/Prefabs/Scorpion.prefab | 2 +- Assets/Scenes/CodeDEV.unity | 22 ++++- .../Scripts/Entities/{Maikäfer.cs => Bug.cs} | 26 +++--- .../{Maikäfer.cs.meta => Bug.cs.meta} | 0 Assets/Scripts/Entities/Enemy.cs | 6 +- Assets/Scripts/Entities/Spider.cs | 14 +-- Assets/Scripts/GameController.cs | 86 +++++++++++++------ Assets/Scripts/Generation/DungeonGenerator.cs | 29 +++++-- Assets/Scripts/Generation/GenRoom.cs | 1 + Assets/Scripts/Objectives/EntityObjective.cs | 11 ++- 10 files changed, 137 insertions(+), 60 deletions(-) rename Assets/Scripts/Entities/{Maikäfer.cs => Bug.cs} (53%) rename Assets/Scripts/Entities/{Maikäfer.cs.meta => Bug.cs.meta} (100%) diff --git a/Assets/Prefabs/Scorpion.prefab b/Assets/Prefabs/Scorpion.prefab index f2743e5..60aa844 100644 --- a/Assets/Prefabs/Scorpion.prefab +++ b/Assets/Prefabs/Scorpion.prefab @@ -52,7 +52,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1303102899095328} 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_Children: - {fileID: 4615957218218632} diff --git a/Assets/Scenes/CodeDEV.unity b/Assets/Scenes/CodeDEV.unity index 2855e7f..ab2be01 100644 --- a/Assets/Scenes/CodeDEV.unity +++ b/Assets/Scenes/CodeDEV.unity @@ -623,6 +623,11 @@ Prefab: propertyPath: m_IsActive value: 0 objectReference: {fileID: 0} + - target: {fileID: 60772848946696534, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2} m_IsPrefabParent: 0 @@ -721,6 +726,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5d9a051e822e2cf4ea3ca01c5a4df37c, type: 3} m_Name: m_EditorClassIdentifier: + followSpeed: 0.05 + minZoom: 5 + zoomFactor: 4 + zoomSpeed: 0.05 + startingDist: 5 followThis: {fileID: 0} --- !u!114 &881384373 MonoBehaviour: @@ -741,6 +751,11 @@ MonoBehaviour: - {fileID: 1908750963} - {fileID: 368878861} - {fileID: 1908750963} +--- !u!1 &979562542 stripped +GameObject: + m_PrefabParentObject: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, + type: 2} + m_PrefabInternal: {fileID: 1597985551} --- !u!1 &1028937042 GameObject: m_ObjectHideFlags: 0 @@ -966,7 +981,7 @@ Prefab: - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} propertyPath: m_AnchoredPosition.x - value: 67.14285 + value: 0 objectReference: {fileID: 0} - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} @@ -1045,6 +1060,10 @@ Prefab: propertyPath: m_RootOrder value: 5 objectReference: {fileID: 0} + - target: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2} m_IsPrefabParent: 0 @@ -1366,6 +1385,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 87d25c2cd3eb97749b79f2cb5f7c5cea, type: 3} m_Name: m_EditorClassIdentifier: + scorpion: {fileID: 979562542} BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319, type: 2} BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9, diff --git a/Assets/Scripts/Entities/Maikäfer.cs b/Assets/Scripts/Entities/Bug.cs similarity index 53% rename from Assets/Scripts/Entities/Maikäfer.cs rename to Assets/Scripts/Entities/Bug.cs index 13e1a0c..34e2062 100644 --- a/Assets/Scripts/Entities/Maikäfer.cs +++ b/Assets/Scripts/Entities/Bug.cs @@ -1,20 +1,18 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Assets.Scripts.Entities.Attack; - -namespace Assets.Scripts.Entities { - -public class Maikäfer : MonoBehaviourEnemy { +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Assets.Scripts.Entities.Attack; + +namespace Assets.Scripts.Entities { + + public class Bug : Enemy { + + public Bug() : base(15) { - public Maikäfer() : base(15) - { - } - private void Start() - { + private void Start() { SetAttack(new MeleeAttack(this.gameObject)); } } -} +} diff --git a/Assets/Scripts/Entities/Maikäfer.cs.meta b/Assets/Scripts/Entities/Bug.cs.meta similarity index 100% rename from Assets/Scripts/Entities/Maikäfer.cs.meta rename to Assets/Scripts/Entities/Bug.cs.meta diff --git a/Assets/Scripts/Entities/Enemy.cs b/Assets/Scripts/Entities/Enemy.cs index ee08494..9eb2959 100644 --- a/Assets/Scripts/Entities/Enemy.cs +++ b/Assets/Scripts/Entities/Enemy.cs @@ -4,7 +4,11 @@ using UnityEngine; using Assets.Scripts.Entities.Attack; namespace Assets.Scripts.Entities { - class Enemy : Mob { + public class Enemy : Mob { + public enum Enemys { + SCORPION, + BUG + } [SerializeField] private float speed = 1; diff --git a/Assets/Scripts/Entities/Spider.cs b/Assets/Scripts/Entities/Spider.cs index c503622..88fa926 100644 --- a/Assets/Scripts/Entities/Spider.cs +++ b/Assets/Scripts/Entities/Spider.cs @@ -3,18 +3,18 @@ using System.Collections.Generic; using UnityEngine; 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)); } } -} +} diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 858231c..cf70356 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -1,11 +1,10 @@ -using System.Collections; +using Assets.Scripts.Entities; +using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameController : MonoBehaviour { - - private Room start; private Room finish; @@ -13,6 +12,12 @@ public class GameController : MonoBehaviour { WIN, DIED } + // Enemy Prefabs + [Header("Enemys")] + [SerializeField] + GameObject scorpion; + + [Space(10)] // Generation Settings [Header("Tile Prefabs")] [SerializeField] @@ -61,6 +66,7 @@ public class GameController : MonoBehaviour { GameObject RockLRD; private Dictionary genPrefabs; + private Dictionary enemyPrefabs; [Space(10)] [Header("References")] @@ -91,29 +97,34 @@ public class GameController : MonoBehaviour { // Use this for initialization void Start () { - genPrefabs = new Dictionary(); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderInner, BorderInner); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.Rock, Rock); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockL, RockL); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockU, RockU); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockR, RockR); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockD, RockD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLU, RockLU); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLR, RockLR); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLD, RockLD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLURD, RockLURD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockRD, RockRD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUR, RockUR); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUD, RockUD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUD, RockLUD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUR, RockLUR); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockURD, RockURD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLRD, RockLRD); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.Ground, Ground); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.DoorInner, DoorInner); - genPrefabs.Add(GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter); + genPrefabs = new Dictionary { + { GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter }, + { GenerationProcessor.ExtendedTileType.BorderInner, BorderInner }, + { GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle }, + { GenerationProcessor.ExtendedTileType.Rock, Rock }, + { GenerationProcessor.ExtendedTileType.RockL, RockL }, + { GenerationProcessor.ExtendedTileType.RockU, RockU }, + { GenerationProcessor.ExtendedTileType.RockR, RockR }, + { GenerationProcessor.ExtendedTileType.RockD, RockD }, + { GenerationProcessor.ExtendedTileType.RockLU, RockLU }, + { GenerationProcessor.ExtendedTileType.RockLR, RockLR }, + { GenerationProcessor.ExtendedTileType.RockLD, RockLD }, + { GenerationProcessor.ExtendedTileType.RockLURD, RockLURD }, + { GenerationProcessor.ExtendedTileType.RockRD, RockRD }, + { GenerationProcessor.ExtendedTileType.RockUR, RockUR }, + { GenerationProcessor.ExtendedTileType.RockUD, RockUD }, + { GenerationProcessor.ExtendedTileType.RockLUD, RockLUD }, + { GenerationProcessor.ExtendedTileType.RockLUR, RockLUR }, + { GenerationProcessor.ExtendedTileType.RockURD, RockURD }, + { GenerationProcessor.ExtendedTileType.RockLRD, RockLRD }, + { GenerationProcessor.ExtendedTileType.Ground, Ground }, + { GenerationProcessor.ExtendedTileType.DoorInner, DoorInner }, + { GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter } + }; + enemyPrefabs = new Dictionary { + { Enemy.Enemys.SCORPION, scorpion } + }; + } // Update is called once per frame @@ -176,7 +187,7 @@ public class GameController : MonoBehaviour { }); start.SetDoorsRootObject(doorRoot); - // WIP + // Spawnpoint GameObject spawnpointRoot = new GameObject(); spawnpointRoot.name = "Spawnpoints"; spawnpointRoot.transform.SetParent(goStart.transform); @@ -210,6 +221,8 @@ public class GameController : MonoBehaviour { foreach (GenRoom gr in dg.rooms) { GameObject groom = gp.ProcessRoom(gr.tiles); List ltg = new List(groom.GetComponentsInChildren()); + + // Doors GameObject doorRootg = new GameObject(); doorRootg.name = "Doors"; doorRootg.transform.SetParent(groom.transform); @@ -219,9 +232,22 @@ public class GameController : MonoBehaviour { x.SetParent(doorRootg.transform); x.gameObject.GetComponent().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.Reload(); + DungeonGenerator.GenerateObjective(grom); groom.transform.SetParent(mapRoot.transform); } @@ -277,6 +303,10 @@ public class GameController : MonoBehaviour { return ui.GetComponent(); } + public Dictionary GetEnemyPrefabs() { + return enemyPrefabs; + } + public bool GameEnded() { return state == GameState.ENDED; } diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 7022036..80db011 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -1,4 +1,5 @@ -using System; +using Assets.Scripts.Entities; +using System; using System.Collections.Generic; using UnityEngine; @@ -214,13 +215,13 @@ public class DungeonGenerator { } foreach ( GenRoom r in rooms ) - makeRoomRelative(r); - makeRoomRelative(start); - makeRoomRelative(end); - makeRoomRelative(path); + MakeRoomRelative(r); + MakeRoomRelative(start); + MakeRoomRelative(end); + MakeRoomRelative(path); } - public void makeRoomRelative(GenRoom room) { + public void MakeRoomRelative(GenRoom room) { room.roomPosition = room.bounds.position; foreach ( Vector2Int v in room.tiles.Keys ) { v.Set(( v - room.roomPosition ).x, ( v - room.roomPosition ).y); @@ -439,4 +440,20 @@ public class DungeonGenerator { } } } + + public static void GenerateObjective(Room r) { + Dictionary enemyPrefabs = GameController.instance.GetEnemyPrefabs(); // TODO not so cool + // TODO add more types + Objective o; + + // ENTITYOBJECTIVE ENEMYS: + List lg = new List(); + //GameObject scorp = enemyPrefabs[Enemy.Enemys.SCORPION]; + lg.Add(enemyPrefabs[Enemy.Enemys.SCORPION]); + EntityObjective eo = new EntityObjective(r, lg); + o = eo; + + + r.SetObjective(o); + } } \ No newline at end of file diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index ada813e..c72452f 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -19,6 +19,7 @@ public class GenRoom { // All positions are in room space relative to the room's anchor public Dictionary tiles = new Dictionary(); public HashSet spawnpoints = new HashSet(); + public Objective objective = null; public float Distance(GenRoom r) { return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y); diff --git a/Assets/Scripts/Objectives/EntityObjective.cs b/Assets/Scripts/Objectives/EntityObjective.cs index 68603ad..169d14d 100644 --- a/Assets/Scripts/Objectives/EntityObjective.cs +++ b/Assets/Scripts/Objectives/EntityObjective.cs @@ -1,4 +1,5 @@ -using System.Collections; +using Assets.Scripts.Entities; +using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -26,13 +27,19 @@ public class EntityObjective : Objective { public override void ActivateGoal(Player ply) { if ( activated ) return; - activated = true; base.ActivateGoal(ply); foreach ( GameObject i in prefabList ) { 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); List spawnPointList = room.GetSpawnpoints(); tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position; + tempObject.GetComponent().SetVictim(player.gameObject); + tempObject.GetComponent().SetObjective(this); entityList.Add(tempObject); }