diff --git a/Assets/Prefabs/Coin.prefab b/Assets/Prefabs/Coin.prefab new file mode 100644 index 0000000..2d52daf --- /dev/null +++ b/Assets/Prefabs/Coin.prefab @@ -0,0 +1,145 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1974526777167790} + m_IsPrefabParent: 1 +--- !u!1 &1797689433515008 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4913752447394922} + - component: {fileID: 212353043096038578} + m_Layer: 0 + m_Name: coin + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1974526777167790 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4395446404358834} + - component: {fileID: 58442750661671820} + - component: {fileID: 114638934637166232} + m_Layer: 0 + m_Name: Coin + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4395446404358834 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1974526777167790} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4913752447394922} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4913752447394922 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1797689433515008} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4395446404358834} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!58 &58442750661671820 +CircleCollider2D: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1974526777167790} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0.010867804, y: 0} + serializedVersion: 2 + m_Radius: 0.38045308 +--- !u!114 &114638934637166232 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1974526777167790} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ba8e1d7b878a1234390e852ac146280f, type: 3} + m_Name: + m_EditorClassIdentifier: + collector: {fileID: 0} +--- !u!212 &212353043096038578 +SpriteRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1797689433515008} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 1310459315 + m_SortingLayer: -1 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: bdae77f5d1df9744baf4a2e174270ffa, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 10, y: 10} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 diff --git a/Assets/Prefabs/Coin.prefab.meta b/Assets/Prefabs/Coin.prefab.meta new file mode 100644 index 0000000..78fc070 --- /dev/null +++ b/Assets/Prefabs/Coin.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 35e8b8e102a45a1489ef949961dca4a6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/CodeDEV.unity b/Assets/Scenes/CodeDEV.unity index e962701..8d901c2 100644 --- a/Assets/Scenes/CodeDEV.unity +++ b/Assets/Scenes/CodeDEV.unity @@ -799,52 +799,6 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 ---- !u!1001 &809524311 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_RootOrder - value: 7 - objectReference: {fileID: 0} - - target: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - propertyPath: m_IsActive - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: dd625f75dbf83194392a299951cf04fb, type: 2} - m_IsPrefabParent: 0 --- !u!1 &816024604 GameObject: m_ObjectHideFlags: 0 @@ -1459,7 +1413,7 @@ Prefab: - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} propertyPath: m_AnchoredPosition.x - value: 64.16286 + value: 64.21245 objectReference: {fileID: 0} - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} @@ -1992,6 +1946,52 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!1001 &1915345372 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_RootOrder + value: 7 + objectReference: {fileID: 0} + - target: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} + m_IsPrefabParent: 0 --- !u!1 &2012930729 GameObject: m_ObjectHideFlags: 0 @@ -2284,6 +2284,7 @@ MonoBehaviour: m_EditorClassIdentifier: scorpion: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2} bug: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2} + coin: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319, type: 2} BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9, diff --git a/Assets/Scripts/Entities/Coin.cs b/Assets/Scripts/Entities/Coin.cs new file mode 100644 index 0000000..4b1de6b --- /dev/null +++ b/Assets/Scripts/Entities/Coin.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +namespace Assets.Scripts.Entities { + [RequireComponent(typeof(Collider2D))] + public class Coin : Entity { + + void OnTriggerEnter2D(Collider2D bumper) { + if ( objective == null ) + return; + Player ply = objective.GetPlayer(); + if ( ply != null && ply.gameObject != null && bumper.gameObject.Equals(ply.gameObject) ) { + Debug.Log("Collected coin..."); + objective.RemoveEntity(this); + GameObject.Destroy(this.gameObject); + } + } + } +} diff --git a/Assets/Scripts/Entities/Collectable.cs.meta b/Assets/Scripts/Entities/Coin.cs.meta similarity index 83% rename from Assets/Scripts/Entities/Collectable.cs.meta rename to Assets/Scripts/Entities/Coin.cs.meta index d1a99e5..280b53e 100644 --- a/Assets/Scripts/Entities/Collectable.cs.meta +++ b/Assets/Scripts/Entities/Coin.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a1c36145cdffcde4c83f575b19b85c88 +guid: ba8e1d7b878a1234390e852ac146280f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Entities/Collectable.cs b/Assets/Scripts/Entities/Collectable.cs deleted file mode 100644 index 0818638..0000000 --- a/Assets/Scripts/Entities/Collectable.cs +++ /dev/null @@ -1,3 +0,0 @@ -public class Collectable : Entity { - public Collectable() : base() { } -} diff --git a/Assets/Scripts/Entities/Enemy.cs b/Assets/Scripts/Entities/Enemy.cs index cf6009d..829f816 100644 --- a/Assets/Scripts/Entities/Enemy.cs +++ b/Assets/Scripts/Entities/Enemy.cs @@ -5,10 +5,6 @@ using Assets.Scripts.Entities.Attack; namespace Assets.Scripts.Entities { public class Enemy : Mob { - public enum Enemys { - SCORPION, - BUG - } [SerializeField] private float speed = 1; @@ -31,11 +27,23 @@ namespace Assets.Scripts.Entities { ps.Play(); } } + if ( objective != null ) { + Player ply = objective.GetPlayer(); + if ( ply != null ) + victim = ply.gameObject; + } + + } void Update() { if ( victim == null || attack == null ) { + if ( objective != null ) { + Player ply = objective.GetPlayer(); + if ( ply != null ) + victim = ply.gameObject; + } return; } @@ -64,9 +72,5 @@ namespace Assets.Scripts.Entities { } - - public void SetVictim(GameObject g) { - victim = g; - } } } diff --git a/Assets/Scripts/Entities/Entity.cs b/Assets/Scripts/Entities/Entity.cs index b162502..bc9529f 100644 --- a/Assets/Scripts/Entities/Entity.cs +++ b/Assets/Scripts/Entities/Entity.cs @@ -3,6 +3,12 @@ using System.Collections.Generic; using UnityEngine; public abstract class Entity : MonoBehaviour { + public enum Entities { + SCORPION, + BUG, + COIN + } + protected EntityObjective objective; /// diff --git a/Assets/Scripts/Entities/Spider.cs b/Assets/Scripts/Entities/Spider.cs index 88fa926..87aef56 100644 --- a/Assets/Scripts/Entities/Spider.cs +++ b/Assets/Scripts/Entities/Spider.cs @@ -12,7 +12,7 @@ namespace Assets.Scripts.Entities } - private void Start() + protected override void Start() { SetAttack(new SingleShot(this.gameObject)); } diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 595bead..b144666 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -1,344 +1,347 @@ -using Assets.Scripts.Entities; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class GameController : MonoBehaviour { - - private Room start; - private Room finish; - - public enum EndedCause { - WIN, DIED - } - - // Enemy Prefabs - [Header("Enemys")] - [SerializeField] - GameObject scorpion; - [SerializeField] - GameObject bug; - - [Space(10)] - // Generation Settings - [Header("Tile Prefabs")] - [SerializeField] - GameObject BorderOuter; - [SerializeField] - GameObject BorderInner; - [SerializeField] - GameObject BorderSingle; - [SerializeField] - GameObject Ground0; - [SerializeField] - GameObject Ground1; - [SerializeField] - GameObject Ground2; - [SerializeField] - GameObject Ground3; - [SerializeField] - GameObject DoorInner; - [SerializeField] - GameObject DoorOuter; - [SerializeField] - GameObject Rock; - [SerializeField] - GameObject RockL; - [SerializeField] - GameObject RockU; - [SerializeField] - GameObject RockR; - [SerializeField] - GameObject RockD; - [SerializeField] - GameObject RockLU; - [SerializeField] - GameObject RockLR; - [SerializeField] - GameObject RockLD; - [SerializeField] - GameObject RockUR; - [SerializeField] - GameObject RockUD; - [SerializeField] - GameObject RockRD; - [SerializeField] - GameObject RockLURD; - [SerializeField] - GameObject RockLUD; - [SerializeField] - GameObject RockLUR; - [SerializeField] - GameObject RockURD; - [SerializeField] - GameObject RockLRD; - [SerializeField] - GameObject Flag; - - private Dictionary genPrefabs; - private Dictionary enemyPrefabs; - - [Space(10)] - [Header("References")] - - [SerializeField] - private GameObject playerPrefab; - - [SerializeField] - private GameObject ui; - - [SerializeField] - private GameObject cam; - - [SerializeField] - private GameObject mapRoot; - - private bool engineInitDone; - private Player player; - - public static GameController instance; - public GameController() { - instance = this; - } - - public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED }; - private EndedCause endCause = EndedCause.DIED; - private GameState state = GameState.UNSET; - - // Use this for initialization - void Start () { - 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.Ground0, Ground0 }, - { GenerationProcessor.ExtendedTileType.Ground1, Ground1 }, - { GenerationProcessor.ExtendedTileType.Ground2, Ground2 }, - { GenerationProcessor.ExtendedTileType.Ground3, Ground3 }, - { GenerationProcessor.ExtendedTileType.DoorInner, DoorInner }, - { GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter }, - { GenerationProcessor.ExtendedTileType.Flag, Flag } - }; - enemyPrefabs = new Dictionary { - { Enemy.Enemys.SCORPION, scorpion }, - { Enemy.Enemys.BUG, bug } - }; - - } - - // Update is called once per frame - void Update() { - if ( !engineInitDone ) { - engineInitDone = true; - Debug.Log("First Frame"); - ChangeState(GameState.INIT); - } - } - - public void ChangeState(GameState nextState) { - if ( nextState != state ) { - state = nextState; - StateLogic(nextState); - } - } - - void StateLogic(GameState nstate) { - switch ( nstate ) { - case GameState.INIT: - Init(); - ChangeState(GameState.STARTING); - break; - case GameState.STARTING: - Starting(); - ChangeState(GameState.RUNNING); - break; - case GameState.RUNNING: - Running(); - break; - case GameState.ENDED: - Ended(); - break; - default: - print("Wrong GameState for StateLogic() call!"); - break; - } - - } - - private void Init() { - // Generation - DungeonGenerator dg = new DungeonGenerator(); - GenerationProcessor gp = new GenerationProcessor(genPrefabs); - dg.Generate(); - - // Start room - GameObject goStart = gp.ProcessRoom(dg.start.tiles); - goStart.name = "Start"; - List lt = new List(goStart.GetComponentsInChildren()); - GameObject doorRoot = new GameObject(); - doorRoot.name = "Doors"; - doorRoot.transform.SetParent(goStart.transform); - start = goStart.AddComponent(); - start.SetCenter(dg.start.GetCenter()); - lt = lt.FindAll(x => x.tag == "door"); - lt.ForEach(x => { - x.SetParent(doorRoot.transform); - x.gameObject.GetComponent().SetParent(start); - }); - start.SetDoorsRootObject(doorRoot); - - // Spawnpoint - GameObject spawnpointRoot = new GameObject(); - spawnpointRoot.name = "Spawnpoints"; - spawnpointRoot.transform.SetParent(goStart.transform); - spawnpointRoot.transform.position = new Vector3(dg.start.roomPosition.x, dg.start.roomPosition.y, 0); - GameObject spawn = new GameObject(); - spawn.transform.SetParent(spawnpointRoot.transform); - spawn.transform.position = new Vector3(dg.start.GetCenter().x, dg.start.GetCenter().y, 0); - start.SetSpawnPointsRootObject(spawnpointRoot); - - start.Reload(); - - start.transform.SetParent(mapRoot.transform); - - // Finish room - GameObject goFinish = gp.ProcessRoom(dg.end.tiles); - goFinish.name = "Finish"; - List ltf = new List(goFinish.GetComponentsInChildren()); - GameObject doorRootf = new GameObject(); - doorRootf.name = "Doors"; - doorRootf.transform.SetParent(goFinish.transform); - ltf = ltf.FindAll(x => x.tag == "door"); - finish = goFinish.AddComponent(); - finish.SetCenter(dg.end.GetCenter()); - ltf.ForEach(x => { - x.SetParent(doorRootf.transform); - x.gameObject.GetComponent().SetParent(finish); - }); - finish.SetDoorsRootObject(doorRootf); - finish.Reload(); - finish.transform.SetParent(mapRoot.transform); - gp.CreateGOFromType(finish.GetCenter(), 0, Room.TileType.DOOR, GenerationProcessor.ExtendedTileType.Flag, goFinish); - - // Other Rooms - 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); - Room grom = groom.AddComponent(); - grom.SetCenter(gr.GetCenter()); - ltg = ltg.FindAll(x => x.tag == "door"); - ltg.ForEach(x => { - 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); - } - - // Hallways - GameObject goHallways = gp.ProcessRoom(dg.path.tiles); - goHallways.name = "Hallways"; - goHallways.AddComponent(); - goHallways.transform.SetParent(mapRoot.transform); - } - - private void Starting() { - - StartObjective goal = new StartObjective(start, playerPrefab); - start.SetObjective(goal); - start.OnPlayerEnter(player); - player = goal.GetPlayer(); - cam.GetComponent().LevelBgm(); - if ( player != null ) { - cam.GetComponent().SetFollow(player.gameObject); - GetUI().InitHealthController(player); - GetUI().InitBrakeController(player); - } else { - Debug.Log("No Player spawned!"); +using Assets.Scripts.Entities; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GameController : MonoBehaviour { + + private Room start; + private Room finish; + + public enum EndedCause { + WIN, DIED + } + + // Enemy Prefabs + [Header("Entities")] + [SerializeField] + GameObject scorpion; + [SerializeField] + GameObject bug; + [SerializeField] + GameObject coin; + + [Space(10)] + // Generation Settings + [Header("Tile Prefabs")] + [SerializeField] + GameObject BorderOuter; + [SerializeField] + GameObject BorderInner; + [SerializeField] + GameObject BorderSingle; + [SerializeField] + GameObject Ground0; + [SerializeField] + GameObject Ground1; + [SerializeField] + GameObject Ground2; + [SerializeField] + GameObject Ground3; + [SerializeField] + GameObject DoorInner; + [SerializeField] + GameObject DoorOuter; + [SerializeField] + GameObject Rock; + [SerializeField] + GameObject RockL; + [SerializeField] + GameObject RockU; + [SerializeField] + GameObject RockR; + [SerializeField] + GameObject RockD; + [SerializeField] + GameObject RockLU; + [SerializeField] + GameObject RockLR; + [SerializeField] + GameObject RockLD; + [SerializeField] + GameObject RockUR; + [SerializeField] + GameObject RockUD; + [SerializeField] + GameObject RockRD; + [SerializeField] + GameObject RockLURD; + [SerializeField] + GameObject RockLUD; + [SerializeField] + GameObject RockLUR; + [SerializeField] + GameObject RockURD; + [SerializeField] + GameObject RockLRD; + [SerializeField] + GameObject Flag; + + private Dictionary genPrefabs; + private Dictionary entitiesPrefabs; + + [Space(10)] + [Header("References")] + + [SerializeField] + private GameObject playerPrefab; + + [SerializeField] + private GameObject ui; + + [SerializeField] + private GameObject cam; + + [SerializeField] + private GameObject mapRoot; + + private bool engineInitDone; + private Player player; + + public static GameController instance; + public GameController() { + instance = this; + } + + public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED }; + private EndedCause endCause = EndedCause.DIED; + private GameState state = GameState.UNSET; + + // Use this for initialization + void Start () { + 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.Ground0, Ground0 }, + { GenerationProcessor.ExtendedTileType.Ground1, Ground1 }, + { GenerationProcessor.ExtendedTileType.Ground2, Ground2 }, + { GenerationProcessor.ExtendedTileType.Ground3, Ground3 }, + { GenerationProcessor.ExtendedTileType.DoorInner, DoorInner }, + { GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter }, + { GenerationProcessor.ExtendedTileType.Flag, Flag } + }; + entitiesPrefabs = new Dictionary { + { Entity.Entities.SCORPION, scorpion }, + { Entity.Entities.BUG, bug }, + { Entity.Entities.COIN, coin } + }; + + } + + // Update is called once per frame + void Update() { + if ( !engineInitDone ) { + engineInitDone = true; + Debug.Log("First Frame"); + ChangeState(GameState.INIT); } - - finish.SetObjective(new FinishObjective(finish)); - - } - - private void Running() { - - } - - private void Ended() { - Debug.Log("Game ended"); - //Time.timeScale = 0; - if ( ui != null ) { - Debug.Log("show end UI"); - if(endCause == EndedCause.DIED) { - cam.GetComponent().GameOverBgm(); - ui.GetComponent().ShowGameOverUI(); - } else if(endCause == EndedCause.WIN) { - //cam.GetComponent().SfxPlay(2); - player.InflictDamage(int.MaxValue/2); - ui.GetComponent().ShowWinUI(); - } - } else { - Debug.Log("No UI specified"); - } - } - - public AudioControl GetAudioControl() { - return cam.GetComponent(); - } - - public UIController GetUI() { - return ui.GetComponent(); - } - - public Dictionary GetEnemyPrefabs() { - return enemyPrefabs; - } - - public bool GameEnded() { - return state == GameState.ENDED; - } - - public void EndGame(EndedCause cause) { - if (state == GameState.ENDED) - return; // Already ended game - endCause = cause; - ChangeState(GameState.ENDED); - } -} + } + + public void ChangeState(GameState nextState) { + if ( nextState != state ) { + state = nextState; + StateLogic(nextState); + } + } + + void StateLogic(GameState nstate) { + switch ( nstate ) { + case GameState.INIT: + Init(); + ChangeState(GameState.STARTING); + break; + case GameState.STARTING: + Starting(); + ChangeState(GameState.RUNNING); + break; + case GameState.RUNNING: + Running(); + break; + case GameState.ENDED: + Ended(); + break; + default: + print("Wrong GameState for StateLogic() call!"); + break; + } + + } + + private void Init() { + // Generation + DungeonGenerator dg = new DungeonGenerator(); + GenerationProcessor gp = new GenerationProcessor(genPrefabs); + dg.Generate(); + + // Start room + GameObject goStart = gp.ProcessRoom(dg.start.tiles); + goStart.name = "Start"; + List lt = new List(goStart.GetComponentsInChildren()); + GameObject doorRoot = new GameObject(); + doorRoot.name = "Doors"; + doorRoot.transform.SetParent(goStart.transform); + start = goStart.AddComponent(); + start.SetCenter(dg.start.GetCenter()); + lt = lt.FindAll(x => x.tag == "door"); + lt.ForEach(x => { + x.SetParent(doorRoot.transform); + x.gameObject.GetComponent().SetParent(start); + }); + start.SetDoorsRootObject(doorRoot); + + // Spawnpoint + GameObject spawnpointRoot = new GameObject(); + spawnpointRoot.name = "Spawnpoints"; + spawnpointRoot.transform.SetParent(goStart.transform); + spawnpointRoot.transform.position = new Vector3(dg.start.roomPosition.x, dg.start.roomPosition.y, 0); + GameObject spawn = new GameObject(); + spawn.transform.SetParent(spawnpointRoot.transform); + spawn.transform.position = new Vector3(dg.start.GetCenter().x, dg.start.GetCenter().y, 0); + start.SetSpawnPointsRootObject(spawnpointRoot); + + start.Reload(); + + start.transform.SetParent(mapRoot.transform); + + // Finish room + GameObject goFinish = gp.ProcessRoom(dg.end.tiles); + goFinish.name = "Finish"; + List ltf = new List(goFinish.GetComponentsInChildren()); + GameObject doorRootf = new GameObject(); + doorRootf.name = "Doors"; + doorRootf.transform.SetParent(goFinish.transform); + ltf = ltf.FindAll(x => x.tag == "door"); + finish = goFinish.AddComponent(); + finish.SetCenter(dg.end.GetCenter()); + ltf.ForEach(x => { + x.SetParent(doorRootf.transform); + x.gameObject.GetComponent().SetParent(finish); + }); + finish.SetDoorsRootObject(doorRootf); + finish.Reload(); + finish.transform.SetParent(mapRoot.transform); + gp.CreateGOFromType(finish.GetCenter(), 0, Room.TileType.DOOR, GenerationProcessor.ExtendedTileType.Flag, goFinish); + + // Other Rooms + 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); + Room grom = groom.AddComponent(); + grom.SetCenter(gr.GetCenter()); + ltg = ltg.FindAll(x => x.tag == "door"); + ltg.ForEach(x => { + 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); + } + + // Hallways + GameObject goHallways = gp.ProcessRoom(dg.path.tiles); + goHallways.name = "Hallways"; + goHallways.AddComponent(); + goHallways.transform.SetParent(mapRoot.transform); + } + + private void Starting() { + + StartObjective goal = new StartObjective(start, playerPrefab); + start.SetObjective(goal); + start.OnPlayerEnter(player); + player = goal.GetPlayer(); + cam.GetComponent().LevelBgm(); + if ( player != null ) { + cam.GetComponent().SetFollow(player.gameObject); + GetUI().InitHealthController(player); + GetUI().InitBrakeController(player); + } else { + Debug.Log("No Player spawned!"); + } + + finish.SetObjective(new FinishObjective(finish)); + + } + + private void Running() { + + } + + private void Ended() { + Debug.Log("Game ended"); + //Time.timeScale = 0; + if ( ui != null ) { + Debug.Log("show end UI"); + if(endCause == EndedCause.DIED) { + cam.GetComponent().GameOverBgm(); + ui.GetComponent().ShowGameOverUI(); + } else if(endCause == EndedCause.WIN) { + //cam.GetComponent().SfxPlay(2); + player.InflictDamage(int.MaxValue/2); + ui.GetComponent().ShowWinUI(); + } + } else { + Debug.Log("No UI specified"); + } + } + + public AudioControl GetAudioControl() { + return cam.GetComponent(); + } + + public UIController GetUI() { + return ui.GetComponent(); + } + + public Dictionary GetEntitiesPrefabs() { + return entitiesPrefabs; + } + + public bool GameEnded() { + return state == GameState.ENDED; + } + + public void EndGame(EndedCause cause) { + if (state == GameState.ENDED) + return; // Already ended game + endCause = cause; + ChangeState(GameState.ENDED); + } +} diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index d7b23fd..cf9b1ff 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -442,18 +442,18 @@ public class DungeonGenerator { } public static void GenerateObjective(Room r) { - Dictionary enemyPrefabs = GameController.instance.GetEnemyPrefabs(); // TODO not so cool + Dictionary enemyPrefabs = GameController.instance.GetEntitiesPrefabs(); // TODO not so cool Objective o = null; - int rand = UnityEngine.Random.Range(0, 2); + int rand = UnityEngine.Random.Range(0, 3); switch (rand) { case 0: { // Scorpion Attack!!!!: List lg = new List(); int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count); for ( int c = 0; c < count; c++ ) { - lg.Add(enemyPrefabs[Enemy.Enemys.SCORPION]); + lg.Add(enemyPrefabs[Entity.Entities.SCORPION]); } EntityObjective eo = new EntityObjective(r, lg); o = eo; @@ -464,12 +464,23 @@ public class DungeonGenerator { List lg = new List(); int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count); for ( int c = 0; c < count; c++ ) { - lg.Add(enemyPrefabs[Enemy.Enemys.BUG]); + lg.Add(enemyPrefabs[Entity.Entities.BUG]); } EntityObjective eo = new EntityObjective(r, lg); o = eo; } break; + case 2: { + // Coins!!!!: + List lg = new List(); + int count = UnityEngine.Random.Range(1, (int) Mathf.Floor(r.GetSpawnpoints().Count / 2)); + for ( int c = 0; c < count; c++ ) { + lg.Add(enemyPrefabs[Entity.Entities.COIN]); + } + EntityObjective eo = new EntityObjective(r, lg); + o = eo; + } + break; } r.SetObjective(o); diff --git a/Assets/Scripts/Objectives/EntityObjective.cs b/Assets/Scripts/Objectives/EntityObjective.cs index 169d14d..6f774fa 100644 --- a/Assets/Scripts/Objectives/EntityObjective.cs +++ b/Assets/Scripts/Objectives/EntityObjective.cs @@ -38,8 +38,7 @@ public class EntityObjective : Objective { 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); + tempObject.GetComponent().SetObjective(this); entityList.Add(tempObject); } diff --git a/Assets/Scripts/Objectives/Objective.cs b/Assets/Scripts/Objectives/Objective.cs index 75ceaa5..f10760e 100644 --- a/Assets/Scripts/Objectives/Objective.cs +++ b/Assets/Scripts/Objectives/Objective.cs @@ -47,5 +47,9 @@ public abstract class Objective { return finished; } + public Player GetPlayer() { + return player; + } + } diff --git a/Assets/graphics/textures/Entities/Coin/coin.png.meta b/Assets/graphics/textures/Entities/Coin/coin.png.meta index 92de097..11b1a97 100644 --- a/Assets/graphics/textures/Entities/Coin/coin.png.meta +++ b/Assets/graphics/textures/Entities/Coin/coin.png.meta @@ -43,7 +43,7 @@ TextureImporter: spriteMeshType: 1 alignment: 0 spritePivot: {x: 0.5, y: 0.5} - spritePixelsToUnits: 100 + spritePixelsToUnits: 1000 spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 @@ -67,6 +67,39 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 spriteSheet: serializedVersion: 2 sprites: []