Add coins as collection event | Added GetPlayer() to Objective
This commit is contained in:
parent
55a0a24914
commit
0fb7631b77
14 changed files with 642 additions and 410 deletions
145
Assets/Prefabs/Coin.prefab
Normal file
145
Assets/Prefabs/Coin.prefab
Normal file
|
@ -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
|
8
Assets/Prefabs/Coin.prefab.meta
Normal file
8
Assets/Prefabs/Coin.prefab.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35e8b8e102a45a1489ef949961dca4a6
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 100100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -799,52 +799,6 @@ AudioSource:
|
||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
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
|
--- !u!1 &816024604
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -1459,7 +1413,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: 64.16286
|
value: 64.21245
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
@ -1992,6 +1946,52 @@ AudioSource:
|
||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
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
|
--- !u!1 &2012930729
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -2284,6 +2284,7 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
scorpion: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2}
|
scorpion: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2}
|
||||||
bug: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
|
bug: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
|
||||||
|
coin: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
|
||||||
BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319,
|
BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319,
|
||||||
type: 2}
|
type: 2}
|
||||||
BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9,
|
BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9,
|
||||||
|
|
21
Assets/Scripts/Entities/Coin.cs
Normal file
21
Assets/Scripts/Entities/Coin.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: a1c36145cdffcde4c83f575b19b85c88
|
guid: ba8e1d7b878a1234390e852ac146280f
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -1,3 +0,0 @@
|
||||||
public class Collectable : Entity {
|
|
||||||
public Collectable() : base() { }
|
|
||||||
}
|
|
|
@ -5,10 +5,6 @@ using Assets.Scripts.Entities.Attack;
|
||||||
|
|
||||||
namespace Assets.Scripts.Entities {
|
namespace Assets.Scripts.Entities {
|
||||||
public class Enemy : Mob {
|
public class Enemy : Mob {
|
||||||
public enum Enemys {
|
|
||||||
SCORPION,
|
|
||||||
BUG
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float speed = 1;
|
private float speed = 1;
|
||||||
|
@ -31,11 +27,23 @@ namespace Assets.Scripts.Entities {
|
||||||
ps.Play();
|
ps.Play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( objective != null ) {
|
||||||
|
Player ply = objective.GetPlayer();
|
||||||
|
if ( ply != null )
|
||||||
|
victim = ply.gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
|
|
||||||
if ( victim == null || attack == null ) {
|
if ( victim == null || attack == null ) {
|
||||||
|
if ( objective != null ) {
|
||||||
|
Player ply = objective.GetPlayer();
|
||||||
|
if ( ply != null )
|
||||||
|
victim = ply.gameObject;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +72,5 @@ namespace Assets.Scripts.Entities {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVictim(GameObject g) {
|
|
||||||
victim = g;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,12 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public abstract class Entity : MonoBehaviour {
|
public abstract class Entity : MonoBehaviour {
|
||||||
|
public enum Entities {
|
||||||
|
SCORPION,
|
||||||
|
BUG,
|
||||||
|
COIN
|
||||||
|
}
|
||||||
|
|
||||||
protected EntityObjective objective;
|
protected EntityObjective objective;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Assets.Scripts.Entities
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
protected override void Start()
|
||||||
{
|
{
|
||||||
SetAttack(new SingleShot(this.gameObject));
|
SetAttack(new SingleShot(this.gameObject));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,344 +1,347 @@
|
||||||
using Assets.Scripts.Entities;
|
using Assets.Scripts.Entities;
|
||||||
using System.Collections;
|
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;
|
||||||
|
|
||||||
public enum EndedCause {
|
public enum EndedCause {
|
||||||
WIN, DIED
|
WIN, DIED
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enemy Prefabs
|
// Enemy Prefabs
|
||||||
[Header("Enemys")]
|
[Header("Entities")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject scorpion;
|
GameObject scorpion;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject bug;
|
GameObject bug;
|
||||||
|
[SerializeField]
|
||||||
[Space(10)]
|
GameObject coin;
|
||||||
// Generation Settings
|
|
||||||
[Header("Tile Prefabs")]
|
[Space(10)]
|
||||||
[SerializeField]
|
// Generation Settings
|
||||||
GameObject BorderOuter;
|
[Header("Tile Prefabs")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject BorderInner;
|
GameObject BorderOuter;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject BorderSingle;
|
GameObject BorderInner;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Ground0;
|
GameObject BorderSingle;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Ground1;
|
GameObject Ground0;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Ground2;
|
GameObject Ground1;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Ground3;
|
GameObject Ground2;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject DoorInner;
|
GameObject Ground3;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject DoorOuter;
|
GameObject DoorInner;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Rock;
|
GameObject DoorOuter;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockL;
|
GameObject Rock;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockU;
|
GameObject RockL;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockR;
|
GameObject RockU;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockD;
|
GameObject RockR;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLU;
|
GameObject RockD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLR;
|
GameObject RockLU;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLD;
|
GameObject RockLR;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockUR;
|
GameObject RockLD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockUD;
|
GameObject RockUR;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockRD;
|
GameObject RockUD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLURD;
|
GameObject RockRD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLUD;
|
GameObject RockLURD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLUR;
|
GameObject RockLUD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockURD;
|
GameObject RockLUR;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject RockLRD;
|
GameObject RockURD;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject Flag;
|
GameObject RockLRD;
|
||||||
|
[SerializeField]
|
||||||
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
|
GameObject Flag;
|
||||||
private Dictionary<Enemy.Enemys, GameObject> enemyPrefabs;
|
|
||||||
|
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
|
||||||
[Space(10)]
|
private Dictionary<Entity.Entities, GameObject> entitiesPrefabs;
|
||||||
[Header("References")]
|
|
||||||
|
[Space(10)]
|
||||||
[SerializeField]
|
[Header("References")]
|
||||||
private GameObject playerPrefab;
|
|
||||||
|
[SerializeField]
|
||||||
[SerializeField]
|
private GameObject playerPrefab;
|
||||||
private GameObject ui;
|
|
||||||
|
[SerializeField]
|
||||||
[SerializeField]
|
private GameObject ui;
|
||||||
private GameObject cam;
|
|
||||||
|
[SerializeField]
|
||||||
[SerializeField]
|
private GameObject cam;
|
||||||
private GameObject mapRoot;
|
|
||||||
|
[SerializeField]
|
||||||
private bool engineInitDone;
|
private GameObject mapRoot;
|
||||||
private Player player;
|
|
||||||
|
private bool engineInitDone;
|
||||||
public static GameController instance;
|
private Player player;
|
||||||
public GameController() {
|
|
||||||
instance = this;
|
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;
|
public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED };
|
||||||
|
private EndedCause endCause = EndedCause.DIED;
|
||||||
// Use this for initialization
|
private GameState state = GameState.UNSET;
|
||||||
void Start () {
|
|
||||||
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject> {
|
// Use this for initialization
|
||||||
{ GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter },
|
void Start () {
|
||||||
{ GenerationProcessor.ExtendedTileType.BorderInner, BorderInner },
|
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject> {
|
||||||
{ GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle },
|
{ GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter },
|
||||||
{ GenerationProcessor.ExtendedTileType.Rock, Rock },
|
{ GenerationProcessor.ExtendedTileType.BorderInner, BorderInner },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockL, RockL },
|
{ GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockU, RockU },
|
{ GenerationProcessor.ExtendedTileType.Rock, Rock },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockR, RockR },
|
{ GenerationProcessor.ExtendedTileType.RockL, RockL },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockD, RockD },
|
{ GenerationProcessor.ExtendedTileType.RockU, RockU },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLU, RockLU },
|
{ GenerationProcessor.ExtendedTileType.RockR, RockR },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLR, RockLR },
|
{ GenerationProcessor.ExtendedTileType.RockD, RockD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLD, RockLD },
|
{ GenerationProcessor.ExtendedTileType.RockLU, RockLU },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLURD, RockLURD },
|
{ GenerationProcessor.ExtendedTileType.RockLR, RockLR },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockRD, RockRD },
|
{ GenerationProcessor.ExtendedTileType.RockLD, RockLD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockUR, RockUR },
|
{ GenerationProcessor.ExtendedTileType.RockLURD, RockLURD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockUD, RockUD },
|
{ GenerationProcessor.ExtendedTileType.RockRD, RockRD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLUD, RockLUD },
|
{ GenerationProcessor.ExtendedTileType.RockUR, RockUR },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLUR, RockLUR },
|
{ GenerationProcessor.ExtendedTileType.RockUD, RockUD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockURD, RockURD },
|
{ GenerationProcessor.ExtendedTileType.RockLUD, RockLUD },
|
||||||
{ GenerationProcessor.ExtendedTileType.RockLRD, RockLRD },
|
{ GenerationProcessor.ExtendedTileType.RockLUR, RockLUR },
|
||||||
{ GenerationProcessor.ExtendedTileType.Ground0, Ground0 },
|
{ GenerationProcessor.ExtendedTileType.RockURD, RockURD },
|
||||||
{ GenerationProcessor.ExtendedTileType.Ground1, Ground1 },
|
{ GenerationProcessor.ExtendedTileType.RockLRD, RockLRD },
|
||||||
{ GenerationProcessor.ExtendedTileType.Ground2, Ground2 },
|
{ GenerationProcessor.ExtendedTileType.Ground0, Ground0 },
|
||||||
{ GenerationProcessor.ExtendedTileType.Ground3, Ground3 },
|
{ GenerationProcessor.ExtendedTileType.Ground1, Ground1 },
|
||||||
{ GenerationProcessor.ExtendedTileType.DoorInner, DoorInner },
|
{ GenerationProcessor.ExtendedTileType.Ground2, Ground2 },
|
||||||
{ GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter },
|
{ GenerationProcessor.ExtendedTileType.Ground3, Ground3 },
|
||||||
{ GenerationProcessor.ExtendedTileType.Flag, Flag }
|
{ GenerationProcessor.ExtendedTileType.DoorInner, DoorInner },
|
||||||
};
|
{ GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter },
|
||||||
enemyPrefabs = new Dictionary<Enemy.Enemys, GameObject> {
|
{ GenerationProcessor.ExtendedTileType.Flag, Flag }
|
||||||
{ Enemy.Enemys.SCORPION, scorpion },
|
};
|
||||||
{ Enemy.Enemys.BUG, bug }
|
entitiesPrefabs = new Dictionary<Entity.Entities, GameObject> {
|
||||||
};
|
{ Entity.Entities.SCORPION, scorpion },
|
||||||
|
{ Entity.Entities.BUG, bug },
|
||||||
}
|
{ Entity.Entities.COIN, coin }
|
||||||
|
};
|
||||||
// Update is called once per frame
|
|
||||||
void Update() {
|
}
|
||||||
if ( !engineInitDone ) {
|
|
||||||
engineInitDone = true;
|
// Update is called once per frame
|
||||||
Debug.Log("First Frame");
|
void Update() {
|
||||||
ChangeState(GameState.INIT);
|
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<Transform> lt = new List<Transform>(goStart.GetComponentsInChildren<Transform>());
|
|
||||||
GameObject doorRoot = new GameObject();
|
|
||||||
doorRoot.name = "Doors";
|
|
||||||
doorRoot.transform.SetParent(goStart.transform);
|
|
||||||
start = goStart.AddComponent<Room>();
|
|
||||||
start.SetCenter(dg.start.GetCenter());
|
|
||||||
lt = lt.FindAll(x => x.tag == "door");
|
|
||||||
lt.ForEach(x => {
|
|
||||||
x.SetParent(doorRoot.transform);
|
|
||||||
x.gameObject.GetComponent<Door>().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<Transform> ltf = new List<Transform>(goFinish.GetComponentsInChildren<Transform>());
|
|
||||||
GameObject doorRootf = new GameObject();
|
|
||||||
doorRootf.name = "Doors";
|
|
||||||
doorRootf.transform.SetParent(goFinish.transform);
|
|
||||||
ltf = ltf.FindAll(x => x.tag == "door");
|
|
||||||
finish = goFinish.AddComponent<Room>();
|
|
||||||
finish.SetCenter(dg.end.GetCenter());
|
|
||||||
ltf.ForEach(x => {
|
|
||||||
x.SetParent(doorRootf.transform);
|
|
||||||
x.gameObject.GetComponent<Door>().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<Transform> ltg = new List<Transform>(groom.GetComponentsInChildren<Transform>());
|
|
||||||
|
|
||||||
// Doors
|
|
||||||
GameObject doorRootg = new GameObject();
|
|
||||||
doorRootg.name = "Doors";
|
|
||||||
doorRootg.transform.SetParent(groom.transform);
|
|
||||||
Room grom = groom.AddComponent<Room>();
|
|
||||||
grom.SetCenter(gr.GetCenter());
|
|
||||||
ltg = ltg.FindAll(x => x.tag == "door");
|
|
||||||
ltg.ForEach(x => {
|
|
||||||
x.SetParent(doorRootg.transform);
|
|
||||||
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.Reload();
|
|
||||||
DungeonGenerator.GenerateObjective(grom);
|
|
||||||
groom.transform.SetParent(mapRoot.transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hallways
|
|
||||||
GameObject goHallways = gp.ProcessRoom(dg.path.tiles);
|
|
||||||
goHallways.name = "Hallways";
|
|
||||||
goHallways.AddComponent<Room>();
|
|
||||||
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<AudioControl>().LevelBgm();
|
|
||||||
if ( player != null ) {
|
|
||||||
cam.GetComponent<CameraControl>().SetFollow(player.gameObject);
|
|
||||||
GetUI().InitHealthController(player);
|
|
||||||
GetUI().InitBrakeController(player);
|
|
||||||
} else {
|
|
||||||
Debug.Log("No Player spawned!");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finish.SetObjective(new FinishObjective(finish));
|
|
||||||
|
public void ChangeState(GameState nextState) {
|
||||||
}
|
if ( nextState != state ) {
|
||||||
|
state = nextState;
|
||||||
private void Running() {
|
StateLogic(nextState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Ended() {
|
void StateLogic(GameState nstate) {
|
||||||
Debug.Log("Game ended");
|
switch ( nstate ) {
|
||||||
//Time.timeScale = 0;
|
case GameState.INIT:
|
||||||
if ( ui != null ) {
|
Init();
|
||||||
Debug.Log("show end UI");
|
ChangeState(GameState.STARTING);
|
||||||
if(endCause == EndedCause.DIED) {
|
break;
|
||||||
cam.GetComponent<AudioControl>().GameOverBgm();
|
case GameState.STARTING:
|
||||||
ui.GetComponent<UIController>().ShowGameOverUI();
|
Starting();
|
||||||
} else if(endCause == EndedCause.WIN) {
|
ChangeState(GameState.RUNNING);
|
||||||
//cam.GetComponent<AudioControl>().SfxPlay(2);
|
break;
|
||||||
player.InflictDamage(int.MaxValue/2);
|
case GameState.RUNNING:
|
||||||
ui.GetComponent<UIController>().ShowWinUI();
|
Running();
|
||||||
}
|
break;
|
||||||
} else {
|
case GameState.ENDED:
|
||||||
Debug.Log("No UI specified");
|
Ended();
|
||||||
}
|
break;
|
||||||
}
|
default:
|
||||||
|
print("Wrong GameState for StateLogic() call!");
|
||||||
public AudioControl GetAudioControl() {
|
break;
|
||||||
return cam.GetComponent<AudioControl>();
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
public UIController GetUI() {
|
|
||||||
return ui.GetComponent<UIController>();
|
private void Init() {
|
||||||
}
|
// Generation
|
||||||
|
DungeonGenerator dg = new DungeonGenerator();
|
||||||
public Dictionary<Enemy.Enemys, GameObject> GetEnemyPrefabs() {
|
GenerationProcessor gp = new GenerationProcessor(genPrefabs);
|
||||||
return enemyPrefabs;
|
dg.Generate();
|
||||||
}
|
|
||||||
|
// Start room
|
||||||
public bool GameEnded() {
|
GameObject goStart = gp.ProcessRoom(dg.start.tiles);
|
||||||
return state == GameState.ENDED;
|
goStart.name = "Start";
|
||||||
}
|
List<Transform> lt = new List<Transform>(goStart.GetComponentsInChildren<Transform>());
|
||||||
|
GameObject doorRoot = new GameObject();
|
||||||
public void EndGame(EndedCause cause) {
|
doorRoot.name = "Doors";
|
||||||
if (state == GameState.ENDED)
|
doorRoot.transform.SetParent(goStart.transform);
|
||||||
return; // Already ended game
|
start = goStart.AddComponent<Room>();
|
||||||
endCause = cause;
|
start.SetCenter(dg.start.GetCenter());
|
||||||
ChangeState(GameState.ENDED);
|
lt = lt.FindAll(x => x.tag == "door");
|
||||||
}
|
lt.ForEach(x => {
|
||||||
}
|
x.SetParent(doorRoot.transform);
|
||||||
|
x.gameObject.GetComponent<Door>().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<Transform> ltf = new List<Transform>(goFinish.GetComponentsInChildren<Transform>());
|
||||||
|
GameObject doorRootf = new GameObject();
|
||||||
|
doorRootf.name = "Doors";
|
||||||
|
doorRootf.transform.SetParent(goFinish.transform);
|
||||||
|
ltf = ltf.FindAll(x => x.tag == "door");
|
||||||
|
finish = goFinish.AddComponent<Room>();
|
||||||
|
finish.SetCenter(dg.end.GetCenter());
|
||||||
|
ltf.ForEach(x => {
|
||||||
|
x.SetParent(doorRootf.transform);
|
||||||
|
x.gameObject.GetComponent<Door>().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<Transform> ltg = new List<Transform>(groom.GetComponentsInChildren<Transform>());
|
||||||
|
|
||||||
|
// Doors
|
||||||
|
GameObject doorRootg = new GameObject();
|
||||||
|
doorRootg.name = "Doors";
|
||||||
|
doorRootg.transform.SetParent(groom.transform);
|
||||||
|
Room grom = groom.AddComponent<Room>();
|
||||||
|
grom.SetCenter(gr.GetCenter());
|
||||||
|
ltg = ltg.FindAll(x => x.tag == "door");
|
||||||
|
ltg.ForEach(x => {
|
||||||
|
x.SetParent(doorRootg.transform);
|
||||||
|
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.Reload();
|
||||||
|
DungeonGenerator.GenerateObjective(grom);
|
||||||
|
groom.transform.SetParent(mapRoot.transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hallways
|
||||||
|
GameObject goHallways = gp.ProcessRoom(dg.path.tiles);
|
||||||
|
goHallways.name = "Hallways";
|
||||||
|
goHallways.AddComponent<Room>();
|
||||||
|
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<AudioControl>().LevelBgm();
|
||||||
|
if ( player != null ) {
|
||||||
|
cam.GetComponent<CameraControl>().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<AudioControl>().GameOverBgm();
|
||||||
|
ui.GetComponent<UIController>().ShowGameOverUI();
|
||||||
|
} else if(endCause == EndedCause.WIN) {
|
||||||
|
//cam.GetComponent<AudioControl>().SfxPlay(2);
|
||||||
|
player.InflictDamage(int.MaxValue/2);
|
||||||
|
ui.GetComponent<UIController>().ShowWinUI();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Debug.Log("No UI specified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioControl GetAudioControl() {
|
||||||
|
return cam.GetComponent<AudioControl>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIController GetUI() {
|
||||||
|
return ui.GetComponent<UIController>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<Entity.Entities, GameObject> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -442,18 +442,18 @@ public class DungeonGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GenerateObjective(Room r) {
|
public static void GenerateObjective(Room r) {
|
||||||
Dictionary<Enemy.Enemys, GameObject> enemyPrefabs = GameController.instance.GetEnemyPrefabs(); // TODO not so cool
|
Dictionary<Entity.Entities, GameObject> enemyPrefabs = GameController.instance.GetEntitiesPrefabs(); // TODO not so cool
|
||||||
|
|
||||||
Objective o = null;
|
Objective o = null;
|
||||||
|
|
||||||
int rand = UnityEngine.Random.Range(0, 2);
|
int rand = UnityEngine.Random.Range(0, 3);
|
||||||
switch (rand) {
|
switch (rand) {
|
||||||
case 0: {
|
case 0: {
|
||||||
// Scorpion Attack!!!!:
|
// Scorpion Attack!!!!:
|
||||||
List<GameObject> lg = new List<GameObject>();
|
List<GameObject> lg = new List<GameObject>();
|
||||||
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
|
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
|
||||||
for ( int c = 0; c < count; c++ ) {
|
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);
|
EntityObjective eo = new EntityObjective(r, lg);
|
||||||
o = eo;
|
o = eo;
|
||||||
|
@ -464,12 +464,23 @@ public class DungeonGenerator {
|
||||||
List<GameObject> lg = new List<GameObject>();
|
List<GameObject> lg = new List<GameObject>();
|
||||||
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
|
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
|
||||||
for ( int c = 0; c < count; c++ ) {
|
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);
|
EntityObjective eo = new EntityObjective(r, lg);
|
||||||
o = eo;
|
o = eo;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 2: {
|
||||||
|
// Coins!!!!:
|
||||||
|
List<GameObject> lg = new List<GameObject>();
|
||||||
|
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);
|
r.SetObjective(o);
|
||||||
|
|
|
@ -38,8 +38,7 @@ public class EntityObjective : Objective {
|
||||||
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<Entity>().SetObjective(this);
|
||||||
tempObject.GetComponent<Enemy>().SetObjective(this);
|
|
||||||
entityList.Add(tempObject);
|
entityList.Add(tempObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,5 +47,9 @@ public abstract class Objective {
|
||||||
return finished;
|
return finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player GetPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ TextureImporter:
|
||||||
spriteMeshType: 1
|
spriteMeshType: 1
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 1000
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
|
@ -67,6 +67,39 @@ TextureImporter:
|
||||||
allowsAlphaSplitting: 0
|
allowsAlphaSplitting: 0
|
||||||
overridden: 0
|
overridden: 0
|
||||||
androidETC2FallbackOverride: 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:
|
spriteSheet:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
sprites: []
|
sprites: []
|
||||||
|
|
Loading…
Add table
Reference in a new issue