diff --git a/CMPT306_Fall2017/Assets/Prefabs/Door.prefab b/CMPT306_Fall2017/Assets/Prefabs/Door.prefab new file mode 100644 index 0000000000000000000000000000000000000000..45b3c043daae3f2a7ad25897f51c7a4725cd3c6a --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/Door.prefab @@ -0,0 +1,81 @@ +%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: 1627067515847650} + m_IsPrefabParent: 1 +--- !u!1 &1627067515847650 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4794795496181420} + - component: {fileID: 61596338423764238} + - component: {fileID: 114750194198579642} + m_Layer: 0 + m_Name: Door + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4794795496181420 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1627067515847650} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -28.105385, y: 50.126347, z: 0.3125} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &61596338423764238 +BoxCollider2D: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1627067515847650} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 +--- !u!114 &114750194198579642 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1627067515847650} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe1a3520b48c2419fa5f2c52c8deae66, type: 3} + m_Name: + m_EditorClassIdentifier: + startArea: {fileID: 0} + parent: {fileID: 0} diff --git a/CMPT306_Fall2017/Assets/Prefabs/Door.prefab.meta b/CMPT306_Fall2017/Assets/Prefabs/Door.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..6bd50f86667f73f12dc4f57cdcd9c15b243f323e --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/Door.prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 865f80a3a8702467e839fa3c56f2c486 +timeCreated: 1507666586 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Prefabs/cave.mat b/CMPT306_Fall2017/Assets/Prefabs/cave.mat new file mode 100644 index 0000000000000000000000000000000000000000..32553697f04977fab6d4b12191576e6137b95942 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/cave.mat @@ -0,0 +1,76 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: cave + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/CMPT306_Fall2017/Assets/Prefabs/cave.mat.meta b/CMPT306_Fall2017/Assets/Prefabs/cave.mat.meta new file mode 100644 index 0000000000000000000000000000000000000000..77274bd5039c6e152fb49cb92f5bfc2a2bdf1452 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/cave.mat.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f0f35e17332ad43ae8236030a1820a14 +timeCreated: 1506113653 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab b/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab new file mode 100644 index 0000000000000000000000000000000000000000..f0d1128aecd17104c00c80b7f33da02e911033ac --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab @@ -0,0 +1,82 @@ +%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: 1017459256821596} + m_IsPrefabParent: 1 +--- !u!1 &1017459256821596 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4798481356818472} + - component: {fileID: 33460964339467830} + - component: {fileID: 23164628432270298} + m_Layer: 0 + m_Name: caveMesh + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4798481356818472 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1017459256821596} + 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: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &23164628432270298 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1017459256821596} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 2100000, guid: f0f35e17332ad43ae8236030a1820a14, type: 2} + 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_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33460964339467830 +MeshFilter: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1017459256821596} + m_Mesh: {fileID: 0} diff --git a/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab.meta b/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..0932955a94b561cea2d8dc439973a809494a8a22 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Prefabs/caveMesh.prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b323062f6c4524926a4f04cf6e9fdd68 +timeCreated: 1506529275 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity b/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity new file mode 100644 index 0000000000000000000000000000000000000000..50f0e7dddeb174ca6df377396bb92821510b390d --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity @@ -0,0 +1,486 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 8 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 3 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 11 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 0 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 9 + m_Resolution: 2 + m_BakeResolution: 40 + m_TextureWidth: 1024 + m_TextureHeight: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 0 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 1024 + m_ReflectionCompression: 2 + m_MixedBakeMode: 1 + m_BakeBackend: 0 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 500 + m_PVRBounces: 2 + m_PVRFiltering: 0 + m_PVRFilteringMode: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousColorSigma: 1 + m_PVRFilteringAtrousNormalSigma: 1 + m_PVRFilteringAtrousPositionSigma: 1 + m_LightingDataAsset: {fileID: 0} + m_UseShadowmask: 0 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &142522251 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 142522253} + - component: {fileID: 142522252} + m_Layer: 0 + m_Name: SceneGenerator + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &142522252 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 142522251} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 10a34cba4651e944f8dca3c077f92db2, type: 3} + m_Name: + m_EditorClassIdentifier: + iterations: 100 + areaDatas: + - representation: {fileID: 0} + name: 'W ' + availableTransitions: 04000000 + - representation: {fileID: 0} + name: 'W ' + availableTransitions: 01000000 + - representation: {fileID: 0} + name: 'S W ' + availableTransitions: 0300000004000000 + - representation: {fileID: 0} + name: 'W ' + availableTransitions: 0300000002000000 + material: {fileID: 2100000, guid: f0f35e17332ad43ae8236030a1820a14, type: 2} + levelMesh: {fileID: 1017459256821596, guid: b323062f6c4524926a4f04cf6e9fdd68, type: 2} + dungeonHeight: 60 + dungeonWidth: 100 + startPoint: {fileID: 680867340} + doorPrefab: {fileID: 1627067515847650, guid: 865f80a3a8702467e839fa3c56f2c486, type: 2} +--- !u!4 &142522253 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 142522251} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 5, y: 5, z: 5} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &273414783 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 273414785} + - component: {fileID: 273414784} + m_Layer: 0 + m_Name: Directional light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &273414784 +Light: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 273414783} + m_Enabled: 1 + serializedVersion: 8 + m_Type: 1 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &273414785 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 273414783} + m_LocalRotation: {x: 0.40821794, y: -0.23456973, z: 0.109381676, w: 0.87542605} + m_LocalPosition: {x: -2.085776, y: -0.2778895, z: 1.4053876} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &528254818 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 528254823} + - component: {fileID: 528254822} + - component: {fileID: 528254821} + - component: {fileID: 528254820} + - component: {fileID: 528254819} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &528254819 +AudioListener: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 528254818} + m_Enabled: 1 +--- !u!124 &528254820 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 528254818} + m_Enabled: 1 +--- !u!92 &528254821 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 528254818} + m_Enabled: 1 +--- !u!20 &528254822 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 528254818} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 0 + m_AllowMSAA: 1 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 + m_StereoMirrorMode: 0 +--- !u!4 &528254823 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 528254818} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &680867340 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 680867344} + - component: {fileID: 680867343} + - component: {fileID: 680867342} + - component: {fileID: 680867341} + m_Layer: 0 + m_Name: Cube + m_TagString: Door + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!23 &680867341 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 680867340} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 10303, 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: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!65 &680867342 +BoxCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 680867340} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!33 &680867343 +MeshFilter: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 680867340} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &680867344 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 680867340} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 16.9, y: -3.7293634, z: -5.2704735} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1066371755 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalPosition.x + value: -32.744755 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalPosition.y + value: -5.9064903 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4292959204018798, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 58680468455928790, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: m_UsedByEffector + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 58680468455928790, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 58594067847029698, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: m_UsedByEffector + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 58594067847029698, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 114493167165369682, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: startArea + value: + objectReference: {fileID: 680867340} + - target: {fileID: 114083128046382276, guid: 43a50026743875842b5906d0e5d8116f, + type: 2} + propertyPath: startArea + value: + objectReference: {fileID: 680867340} + - target: {fileID: 1112599888398294, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_TagString + value: Player + objectReference: {fileID: 0} + - target: {fileID: 1763017534516472, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + propertyPath: m_TagString + value: Player + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 43a50026743875842b5906d0e5d8116f, type: 2} + m_IsPrefabParent: 0 diff --git a/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity.meta b/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity.meta new file mode 100644 index 0000000000000000000000000000000000000000..21c728d4e44ef06612538cc65c37da327df52067 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scenes/ProceduralScene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ee79ad84a39b5234087f4e1acafb5a5a +timeCreated: 1507747700 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts.meta new file mode 100644 index 0000000000000000000000000000000000000000..085a4e3223fd219c2f7f341c3333c1cf1934f8e0 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6d171325f12254a07b120a3f62883f34 +folderAsset: yes +timeCreated: 1506544688 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs new file mode 100644 index 0000000000000000000000000000000000000000..b117f7226d3bef0ca3d61242638acb2b7c70359e --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs @@ -0,0 +1,20 @@ +using UnityEngine; + +public class AutoDestroyParticleSystem : MonoBehaviour +{ + private ParticleSystem _particleSystem; + + public void Start() + { + _particleSystem = GetComponent<ParticleSystem> (); + } + + public void Update() + { + if (_particleSystem.isPlaying) + return; + + Destroy (gameObject); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..84059d981fe765cccbdfd4e1edce4e7d18311c29 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/AutoDestroyParticleSystem.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 946de4ba98e8d43129642dfb272676cf +timeCreated: 1472517453 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs new file mode 100644 index 0000000000000000000000000000000000000000..1323482deb6a345da94bbd4c91463f4678df257a --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs @@ -0,0 +1,29 @@ +using UnityEngine; +using System.Collections; + +public class Background : MonoBehaviour { + public Transform[] Backgrounds; + public float ParallaxScale; + public float ParallaxReductionFactor; + public float Smoothing; + + private Vector3 _lastPosition; + + public void Start() + { + _lastPosition = transform.position; + } + + public void Update() + { + var parallax = (_lastPosition.x - transform.position.x) * ParallaxScale; + + for (var i = 0; i < Backgrounds.Length; i++) + { + var backgroundTargetPosition = Backgrounds [i].position.x + parallax * (i * ParallaxReductionFactor + 1); + Backgrounds[i].position = Vector3.Lerp(Backgrounds[i].position, new Vector3(backgroundTargetPosition,Backgrounds[i].position.y,Backgrounds[i].position.z),Smoothing * Time.deltaTime); + } + + _lastPosition = transform.position; + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..c9376a706158024c9a295c7b010c7afb78a76537 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Background.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e350878b5ae64443f81d58d65a3aeb21 +timeCreated: 1471397583 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs new file mode 100644 index 0000000000000000000000000000000000000000..6e07e6b3dc953b0cc4e78887dbb791b9c97255cd --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using System.Collections; + +public class CameraController : MonoBehaviour { + + public Transform Player; + + public Vector2 + Margin, + Smoothing; + + public BoxCollider2D Bounds; + + private Vector3 + _min, + _max; + + public bool IsFollowing { get; set; } + + public void Start() + { + _min = Bounds.bounds.min; + _max = Bounds.bounds.max; + + } + + public void Update() + { + var x = transform.position.x; + var y = transform.position.y; + + if(IsFollowing) + { + if (Mathf.Abs (x - Player.position.x) > Margin.x) + x = Mathf.Lerp (x, Player.position.x, Smoothing.x * Time.deltaTime); + + if (Mathf.Abs (y - Player.position.y) > Margin.y) + y = Mathf.Lerp (y, Player.position.y, Smoothing.y * Time.deltaTime); + } + + var cameraHalfWidth = Camera.main.orthographicSize * ((float)Screen.width / Screen.height); + + x = Mathf.Clamp (x, _min.x + cameraHalfWidth, _max.x - cameraHalfWidth); + y = Mathf.Clamp (y, _min.y + Camera.main.orthographicSize, _max.y - Camera.main.orthographicSize); + + transform.position = new Vector3 (x, y, transform.position.z); + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..70c2e1fb550fe533dcf486ee7d5ddddc6cc3c139 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraController.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4614b7a475e4e4ca99bdbc18b3dd714f +timeCreated: 1470879848 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs new file mode 100644 index 0000000000000000000000000000000000000000..e0c7808a2b3dac428ce2ee2524d0a79f9d4ce5c5 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using System.Collections; + +public class CameraFollow : MonoBehaviour { + + public Transform lookAt; + + private Vector3 positionOffSet = new Vector3(0, 0, -6.5f); + + private void Start () { + } + + // Update is called once per frame + private void Update () { + transform.position = lookAt.transform.position + positionOffSet; + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..b702443b440704bfbd9b7260e8f361beb57c8dd0 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CameraFollow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 90809e32d58b44afdbab71e1248e5338 +timeCreated: 1467685840 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs new file mode 100644 index 0000000000000000000000000000000000000000..e10453f3081942c50416f4faf405752f20a6fac7 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs @@ -0,0 +1,332 @@ +using UnityEngine; +using System.Collections; + +public class CharacterController2D : MonoBehaviour { + + private const float SkinWidth = .02f; + private const int TotalHorizontalRays = 8; + private const int TotalVerticalRays = 4; + + private static readonly float SlopeLimitTangant = Mathf.Tan (75f * Mathf.Deg2Rad); + + public LayerMask PlatformMask; + public ControllerParameters2D DefaultParameters; + + public ControllerState2D State { get; private set; } + public Vector2 Velocity { get {return _velocity;} } + public bool CanJump { + get + { + if (Parameters.JumpRestrictions == ControllerParameters2D.JumpBehavior.CanJumpAnywhere) + return _jumpIn <= 0; + if (Parameters.JumpRestrictions == ControllerParameters2D.JumpBehavior.CanJumpOnGround) + return State.IsGrounded; + + return false; + } + } + public bool HandleCollisions { get; set; } + public ControllerParameters2D Parameters{ get { return _overrideParameters ?? DefaultParameters; } } + public GameObject StandingOn { get; private set; } + public Vector3 PlatformVelocity{ get; private set; } + + private Vector2 _velocity; + private Transform _transform; + private Vector3 _localScale; + private BoxCollider2D _boxCollider; + private ControllerParameters2D _overrideParameters; + private float _jumpIn; + private GameObject _lastStandingOn; + + private Vector3 + _activateGlobalPlatformPoint, + _activateLocalPlatformPoint; + + private Vector3 + _raycastTopLeft, + _raycastBottomRight, + _raycastBottomLeft; + + private float + _verticalDistanceBetweenRays, + _horizontalDistanceBetweenRays; + + public void Awake() + { + HandleCollisions = true; + State = new ControllerState2D(); + _transform = transform; + _localScale = transform.localScale; + _boxCollider = GetComponent<BoxCollider2D> (); + + var colliderWidth = _boxCollider.size.x * Mathf.Abs (transform.localScale.x) - (2 * SkinWidth); + _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); + + var colliderHeight = _boxCollider.size.y * Mathf.Abs (transform.localScale.y) - (2 * SkinWidth); + _verticalDistanceBetweenRays = colliderWidth / (TotalHorizontalRays - 1); + + } + + public void AddForce(Vector2 force) + { + _velocity = force; + } + + public void SetForce(Vector2 force) + { + _velocity += force; + } + + public void SetHorizontalForce(float x) + { + _velocity.x = x; + } + + public void SetVerticalForce(float y) + { + _velocity.y = y; + } + + public void Jump() + { + AddForce (new Vector2 (0, Parameters.JumpMagnitude)); + _jumpIn = Parameters.JumpFrequency; + } + + public void LateUpdate() + { + _jumpIn -= Time.deltaTime; + _velocity.y += Parameters.Gravity * Time.deltaTime; + Move(Velocity * Time.deltaTime); + } + + private void Move(Vector2 deltaMovement) + { + var wasGrounded = State.IsCollideBelow; + State.Reset (); + + if (HandleCollisions) + { + HandlePlatforms(); + CalculateRayOrigins(); + + if (deltaMovement.y < 0 && wasGrounded) + HandleVerticalSlope (ref deltaMovement); + + if (Mathf.Abs (deltaMovement.x) > .001f) + MoveHorizontally (ref deltaMovement); + + MoveVertically (ref deltaMovement); + + + } + + _transform.Translate (deltaMovement, Space.World); + + if (Time.deltaTime > 0) + _velocity = deltaMovement / Time.deltaTime; + + _velocity.x = Mathf.Min (_velocity.x, Parameters.MaxVelocity.x); + _velocity.y = Mathf.Min (_velocity.y, Parameters.MaxVelocity.y); + + if (State.IsMovingUpSlope) + _velocity.y = 0; + + + if (StandingOn != null) { + _activateGlobalPlatformPoint = transform.position; + _activateLocalPlatformPoint = StandingOn.transform.InverseTransformPoint (transform.position); + + if (_lastStandingOn != StandingOn) + { + if (_lastStandingOn != null) + _lastStandingOn.SendMessage ("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver); + + StandingOn.SendMessage ("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver); + _lastStandingOn = StandingOn; + } + else if (StandingOn != null) + StandingOn.SendMessage ("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver); + _lastStandingOn = null; + } + + + } + + private void HandlePlatforms() + { + if (StandingOn != null) { + var newGlobalPlatformPoint = StandingOn.transform.TransformPoint (_activateLocalPlatformPoint); + var moveDistance = newGlobalPlatformPoint - _activateGlobalPlatformPoint; + + if (moveDistance != Vector3.zero) + transform.Translate (moveDistance, Space.World); + + PlatformVelocity = (newGlobalPlatformPoint - _activateGlobalPlatformPoint) / Time.deltaTime; + } else + PlatformVelocity = Vector3.zero; + } + + + private void CalculateRayOrigins() + { + var size = new Vector2 (_boxCollider.size.x * Mathf.Abs (_localScale.x), _boxCollider.size.y * Mathf.Abs (_localScale.y)) / 2; + var center = new Vector2(_boxCollider.offset.x * _localScale.x, _boxCollider.offset.y * _localScale.y); + + _raycastTopLeft = _transform.position + new Vector3(center.x - size.x + SkinWidth, center.y + size.y + SkinWidth); + _raycastBottomRight = _transform.position + new Vector3( center.x + size.x - SkinWidth, center.y - size.y + SkinWidth); + _raycastBottomLeft = _transform.position + new Vector3( center.x - size.x + SkinWidth, center.y - size.y + SkinWidth); + + } + + private void MoveHorizontally(ref Vector2 deltaMovement) + { + var isGoingRight = deltaMovement.x > 0; + var rayDistance = Mathf.Abs (deltaMovement.x) + SkinWidth; + var rayDirection = isGoingRight ? Vector2.right : -Vector2.right; + var rayOrigin = isGoingRight ? _raycastBottomRight : _raycastBottomLeft; + + for ( var i = 0; i < TotalHorizontalRays; i++) + { + var rayVector = new Vector2(rayOrigin.x, rayOrigin.y + (i * _verticalDistanceBetweenRays)); + Debug.DrawRay(rayVector, rayDirection * rayDistance, Color.red); + + var RayCastHit = Physics2D.Raycast( rayVector, rayDirection, rayDistance, PlatformMask); + if (!RayCastHit) + continue; + + if ( i == 0 && HandleHorizontalSlope(ref deltaMovement, Vector2.Angle(RayCastHit.normal, Vector2.up), isGoingRight)) + break; + + deltaMovement.x = RayCastHit.point.x - rayVector.x; + + if (isGoingRight) + { + deltaMovement.x -= SkinWidth; + State.IsCollideRight = true; + } + + if ( rayDistance < SkinWidth + .0001f) + break; + + } + } + + private void MoveVertically(ref Vector2 deltaMovement) + { + var isGoingUp = deltaMovement.y > 0; + var rayDistance = Mathf.Abs (deltaMovement.y) + SkinWidth; + var rayDirection = isGoingUp ? Vector2.up : -Vector2.up; + var rayOrigin = isGoingUp ? _raycastTopLeft : _raycastBottomLeft; + + rayOrigin.x += deltaMovement.x; + + var standingOnDistance = float.MaxValue; + for ( var i = 0; i < TotalVerticalRays; i++) + { + var rayVector = new Vector2 (rayOrigin.x + (i * _horizontalDistanceBetweenRays), rayOrigin.y); + Debug.DrawRay (rayVector, rayDirection * rayDistance, Color.red); + + var raycastHit = Physics2D.Raycast(rayVector, rayDirection, rayDistance,PlatformMask); + if (!raycastHit) + continue; + + if( !isGoingUp) + { + var verticalDistanceToHit = _transform.position.y - raycastHit.point.y; + if( verticalDistanceToHit < standingOnDistance) + { + standingOnDistance = verticalDistanceToHit; + StandingOn = raycastHit.collider.gameObject; + } + deltaMovement.y = raycastHit.point.y - rayVector.y; + rayDistance = Mathf.Abs(deltaMovement.y); + + if(isGoingUp) + { + deltaMovement.y -= SkinWidth; + State.IsCollideAbove = true; + } + else + { + deltaMovement.y += SkinWidth; + State.IsCollideBelow = true; + } + + if (!isGoingUp && deltaMovement.y > .0001f) + State.IsMovingUpSlope = true; + + if(rayDistance < SkinWidth + .0001f) + break; + + } + } + } + + private void HandleVerticalSlope(ref Vector2 deltaMovement) + { + var center = (_raycastBottomLeft.x + _raycastBottomRight.x) / 2; + var direction = -Vector2.up; + + var slopeDistance = SlopeLimitTangant * (_raycastBottomRight.x - center); + var slopeRayVector = new Vector2 (center, _raycastBottomLeft.y); + + Debug.DrawRay (slopeRayVector, direction * slopeDistance, Color.yellow); + var raycastHit = Physics2D.Raycast (slopeRayVector, direction, slopeDistance, PlatformMask); + if (!raycastHit) + return; + + var isMovingDownSlope = Mathf.Sign(raycastHit.normal.x) == Mathf.Sign(deltaMovement.x); + if (!isMovingDownSlope) + return; + + var angle = Vector2.Angle(raycastHit.normal, Vector2.up); + if (Mathf.Abs (angle) < .0001f) + return; + + State.IsMovingDownSlope = true; + State.SlopeAngle = angle; + deltaMovement.y = raycastHit.point.y - slopeRayVector.y; + + } + + private bool HandleHorizontalSlope(ref Vector2 deltaMovement, float angle, bool IsGoingRight) + { + if ( Mathf.RoundToInt(angle) == 90) + return false; + + if (angle > Parameters.SlopeLimit) { + deltaMovement.x = 0; + return true; + } + + if (deltaMovement.y > .07f) + return true; + + deltaMovement.x += IsGoingRight ? -SkinWidth : SkinWidth; + deltaMovement.y = Mathf.Abs (Mathf.Tan (angle * Mathf.Deg2Rad) * deltaMovement.x); + State.IsMovingUpSlope = true; + State.IsCollideBelow = true; + return true; + } + + public void OnTriggerEnter2D(Collider2D other) + { + var parameters = other.gameObject.GetComponent<ControllerPhsyicsVolume2D> (); + if (parameters == null) + return; + + _overrideParameters = parameters.Parameters; + } + + public void OnTriggerExit2D(Collider2D other) + { + var parameters = other.gameObject.GetComponent<ControllerPhsyicsVolume2D> (); + + if (parameters == null) + return; + + _overrideParameters = null; + } + +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..9dbcefa10eb7532e220c5795f1b147292706d169 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/CharacterController2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3bac831b96d364a1983601d0171ee534 +timeCreated: 1469498720 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs new file mode 100644 index 0000000000000000000000000000000000000000..8aae3900a868ce59687802750d5325d16acfcae7 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +public class Checkpoint : MonoBehaviour +{ + private List<IPlayerRespawnListener> _listeners; + + public void Start() + { + _listeners = new List<IPlayerRespawnListener> (); + } + + public void PlayerHitCheckpoint() + { + } + + private IEnumerator PlayerHitCheckpointCo(int bonus) + { + yield break; + } + + public void PlayerLeftCheckpoint() + { + } + + public void SpawnPlayer(Player player) + { + player.RespawnAt (transform); + + foreach (var listener in _listeners) + listener.OnPlayerRespwanInThisCheckpoint (this, player); + } + + public void AssignObjectToCheckpoint(IPlayerRespawnListener listener) + { + _listeners.Add (listener); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..9dfd5eefbf529d3c70a9930b8590844ab4a3d167 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Checkpoint.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 69a3f8437d6db43f6820e83a93f9f4bb +timeCreated: 1471905161 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs new file mode 100644 index 0000000000000000000000000000000000000000..214ef49bca1b6a31129efc4dffef3a6220ba45c1 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using System.Collections; + +public class ControllerParameters : MonoBehaviour { + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..91a7cef987b53966e49cf08e0afdc25f7238ad89 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 208a6a9bb86094f67a528f99509a6fe4 +timeCreated: 1469421216 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs new file mode 100644 index 0000000000000000000000000000000000000000..989f0b0e972931372a9888aa207739e02404d8e6 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs @@ -0,0 +1,27 @@ +using System; +using UnityEngine; +using System.Collections; + +[Serializable] +public class ControllerParameters2D +{ + public enum JumpBehavior + { + CanJumpOnGround, + CanJumpAnywhere, + CantJump + } + + public Vector2 MaxVelocity = new Vector2(float.MaxValue, float.MaxValue); + + [Range(0, 90)] + public float SlopeLimit = 30; + + public float Gravity = -25f; + + public JumpBehavior JumpRestrictions; + + public float JumpFrequency = .25f; + + public float JumpMagnitude = 12; +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d5151987cdcf0d9cb572bbee558685de812e484b --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerParameters2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8edf32cefad87450a98e70e96aa67193 +timeCreated: 1468450837 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs new file mode 100644 index 0000000000000000000000000000000000000000..dead41fdf1bba5442c628c293bfe9d96d2f6b2fc --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs @@ -0,0 +1,7 @@ +using UnityEngine; +using System.Collections; + +public class ControllerPhsyicsVolume2D : MonoBehaviour +{ + public ControllerParameters2D Parameters; +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..2df116c4bdb1086f5e4da905e5dc34e3ff09798d --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerPhsyicsVolume2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7690466e8d0c64988a9b601cb4962d10 +timeCreated: 1468451197 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs new file mode 100644 index 0000000000000000000000000000000000000000..b7ca1552cb2fddc406e8e38535e90a97830f5d8b --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs @@ -0,0 +1,41 @@ +using UnityEngine; +using System.Collections; + +public class ControllerState2D +{ + public bool IsCollideRight{ get; set;} + public bool IsCollideLeft{ get; set;} + public bool IsCollideAbove{ get; set;} + public bool IsCollideBelow{ get; set;} + public bool IsMovingDownSlope{ get; set;} + public bool IsMovingUpSlope{ get; set;} + public bool IsGrounded{ get { return IsCollideBelow; } } + public float SlopeAngle{ get; set;} + + public bool HasCollisions { get {return IsCollideRight || IsCollideLeft || IsCollideAbove || IsCollideBelow;}} + + public void Reset() + { + IsMovingUpSlope = + IsMovingDownSlope = + IsCollideLeft = + IsCollideRight = + IsCollideAbove = + IsCollideBelow = false; + + SlopeAngle = 0; + } + + public override string ToString() + { + return string.Format( + "(controller: r:{0} 1:{1} a:{2} b:{3} down-slope:{4} up-slope: {5} angle: {6}", + IsCollideLeft, + IsCollideRight, + IsCollideAbove, + IsCollideBelow, + IsMovingDownSlope, + IsMovingUpSlope, + SlopeAngle); + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..a0cfa01ead8691b14e74c20756626abcd35dc353 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/ControllerState2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6b399aa92a5a942f89011e01dc2607bb +timeCreated: 1469494109 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs new file mode 100644 index 0000000000000000000000000000000000000000..f60de20d63efbe15f8e78cc3b5095ab0403aeed3 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +public class FollowObject : MonoBehaviour +{ + + public Vector2 Offset; + public Transform Following; + + public void Update() + { + transform.position = Following.transform.position + (Vector3) Offset; + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..3259cb91e58af5ed6bd3652e46b449b948c728fa --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowObject.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 70108adb521764770812c71f0ae80898 +timeCreated: 1474852229 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs new file mode 100644 index 0000000000000000000000000000000000000000..026e6750570dbc784b1e18592eb2924c282aa233 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs @@ -0,0 +1,46 @@ +using UnityEngine; +using System.Collections.Generic; +using System.Collections; + +public class FollowPath : MonoBehaviour { + public enum FollowType + { + MoveTowards, + Lerp + } + + public FollowType Type = FollowType.MoveTowards; + public PathDefinition Path; + public float Speed = 1; + public float MaxDistanceToGoal = .1f; + + private IEnumerator<Transform>_currentPoint; + + public void Start() + { + if (Path == null) { + Debug.LogError ("Path cannot be null", gameObject); + } + + _currentPoint = Path.GetPathsEnumerator(); + _currentPoint.MoveNext(); + + if (_currentPoint.Current == null) + return; + transform.position = _currentPoint.Current.position; + } + + public void Update (){ + if (_currentPoint == null || _currentPoint == null) + return; + + if (Type == FollowType.MoveTowards) + transform.position = Vector3.MoveTowards (transform.position, _currentPoint.Current.position, Time.deltaTime * Speed); + else if (Type == FollowType.Lerp) + transform.position = Vector3.Lerp (transform.position, _currentPoint.Current.position, Time.deltaTime * Speed); + + var distanceSquared = (transform.position - _currentPoint.Current.position).sqrMagnitude; + if( distanceSquared < MaxDistanceToGoal * MaxDistanceToGoal) + _currentPoint.MoveNext(); + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..54220c9a584384200c758a9ef566e82cba43959c --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/FollowPath.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 191df361effaa4da79ce9c24f8592622 +timeCreated: 1468972615 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs new file mode 100644 index 0000000000000000000000000000000000000000..cd7a911ab3cd180dfa3863ab890bac41fb06b3b1 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +public class GameHud : MonoBehaviour +{ + public GUISkin Skin; + + public void OnGUI() + { + GUI.skin = Skin; + + GUILayout.BeginArea(new Rect (0, 0, Screen.width, Screen.height)); + { + GUILayout.BeginVertical(Skin.GetStyle ("GameHud")); + { + GUILayout.Label(string.Format ("Points: {0}", GameManager.Instance.Points), Skin.GetStyle ("PointsText")); + + var time = LevelManager.Instance.RunningTime; + GUILayout.Label(string.Format ("{0:00}:{1:00} with {2} bonus", time.Minutes + (time.Hours * 60), time.Seconds, LevelManager.Instance.CurrentTimeBonus), Skin.GetStyle("TimeText")); + } + GUILayout.EndVertical(); + } + GUILayout.EndArea (); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..6bf59b4a18e753bbe1f6a6606e05450b6e4c17bb --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameHud.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2b13b843f7fdd4890b367d203e56067f +timeCreated: 1471905160 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..dd94aa64c5ccbfc7221af63271986ff9c34d868a --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +public class GameManager +{ + private static GameManager _instance; + public static GameManager Instance{ get { return _instance ??(_instance = new GameManager());}} + + public int Points { get; private set;} + + private GameManager() + { + } + + public void Reset() + { + Points = 0; + } + + public void ResetPoints(int points) + { + Points = points; + } + + public void AddPoints ( int pointsToAdd) + { + Points += pointsToAdd; + } +} + + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..6665ca9f013cffabea6aa836dc944c8755ebe59c --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GameManager.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 830b970def0fe4e3f89b026e3c6913a1 +timeCreated: 1471905161 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs new file mode 100644 index 0000000000000000000000000000000000000000..594334573fb9cbc540ba1a5420f2aec2668348df --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +public class GiveDamageToPlayer : MonoBehaviour +{ + public int DamageToGive = 10; + + private Vector2 + _lastPosition, + _velocity; + + public void LateUpdate() + { + _velocity = (_lastPosition - (Vector2) transform.position / Time.deltaTime); + _lastPosition = transform.position; + } + + public void OnTriggerEnter2D(Collider2D other) + { + var player = other.GetComponent<Player> (); + if (player == null) + return; + + player.TakeDamage (DamageToGive); + var controller = player.GetComponent<CharacterController2D> (); + var totalVelocity = controller.Velocity + _velocity; + + controller.SetForce (new Vector2 ( + -1 * Mathf.Sign (totalVelocity.x) * Mathf.Clamp (Mathf.Abs (totalVelocity.x) * 5, 10, 20), + -1 * Mathf.Sign (totalVelocity.y) * Mathf.Clamp (Mathf.Abs (totalVelocity.y) * 2, 0, 15))); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..ce8a3b6b5acf2e3d18f10bc8217c26aeab003b27 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/GiveDamageToPlayer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9cf8cfc3492424d03a956e673d0c07a5 +timeCreated: 1474851351 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs new file mode 100644 index 0000000000000000000000000000000000000000..12971cac0cdafcc9c2177846dfbea84e4e46ca3a --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +public class HealthBar : MonoBehaviour +{ + public Player Player; + public Transform ForegroundSprite; + public SpriteRenderer ForegroundRenderer; + public Color MaxHealthColor = new Color(255/ 255f, 63/ 255f, 63 / 255f); + public Color MinHealtherColor = new Color(64/ 255f, 137 / 255f, 255 / 255f); + + public void Update() + { + var healthPercent = Player.Health / (float)Player.MaxHealth; + + ForegroundSprite.localScale = new Vector3 (healthPercent, 1, 1); + ForegroundRenderer.color = Color.Lerp (MaxHealthColor, MinHealtherColor, healthPercent); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..0a895ad0373ac6ffcccf62820fbdea10243d1297 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/HealthBar.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9bfa97e09dfe04109ba1816bf5432b42 +timeCreated: 1474851308 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs new file mode 100644 index 0000000000000000000000000000000000000000..30bf25092ab5f7d6bb10015f856e7fcb10112a84 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs @@ -0,0 +1,4 @@ +public interface IPlayerRespawnListener +{ + void OnPlayerRespwanInThisCheckpoint(Checkpoint checkpount, Player player); +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..2a911f7b659eb54e9542bd09b09582fd69d03615 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/IPlayerRespawnListener.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3fff801870bcc49e98d3ae0fb06549b6 +timeCreated: 1472517453 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs new file mode 100644 index 0000000000000000000000000000000000000000..91da460b534d063bd9ed4d8bd48df7bfc2135be6 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +public class InstaKill : MonoBehaviour +{ + public void OnTriggerEnter2D(Collider2D other) + { + var player = other.GetComponent<Player>(); + if (player == null) + return; + + LevelManager.Instance.KillPlayer (); + } +} + + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..07077813b0b50e00d3167b38931f6f4c0a3ece3f --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/InstaKill.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 98e456307a8bb4c81b943dd1ca6e9919 +timeCreated: 1472331862 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs new file mode 100644 index 0000000000000000000000000000000000000000..c17ce7f3e23363c9e6ac45f8d18933bb5fa579c3 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs @@ -0,0 +1,12 @@ +using UnityEngine; +using System.Collections; + +public class JumpPlatform : MonoBehaviour +{ + public float JumpMagnitude = 20; + + public void ControllerEnter2D(CharacterController2D controller) + { + controller.SetVerticalForce (JumpMagnitude); + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..27919f7905ee4a8a99fe311dbcfd23895bf25b93 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/JumpPlatform.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 817ecfe0d475246aba76d7651f5e9d68 +timeCreated: 1470606482 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..46a64360fa34dc7335236cc7110117beff6d4129 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs @@ -0,0 +1,116 @@ +using UnityEngine; +using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; + +public class LevelManager : MonoBehaviour { + + public static LevelManager Instance{ get; private set;} + + public Player Player { get; private set; } + public CameraController Camera { get; private set; } + public TimeSpan RunningTime { get { return DateTime.UtcNow - _started; } } + + public int CurrentTimeBonus + { + get + { + var secondDifference = (int)(BonusCutOffSeconds-RunningTime.TotalSeconds); + return Mathf.Max (0, secondDifference) * BonusSecondMultiplier; + } + } + + private List<Checkpoint> _checkpoints; + private int _currentCheckPointIndex; + private DateTime _started; + private int _savedPoints; + + + public Checkpoint DebugSpawn; + public int BonusCutOffSeconds; + public int BonusSecondMultiplier; + + public void Awake() + { + Instance = this; + } + + public void Start() + { + _checkpoints = FindObjectsOfType<Checkpoint>().OrderBy(t => t.transform.position.x).ToList(); + _currentCheckPointIndex = _checkpoints.Count > 0 ? 0 : -1; + + Player = FindObjectOfType<Player> (); + Camera = FindObjectOfType<CameraController> (); + + _started = DateTime.UtcNow; + + var listeners = FindObjectsOfType<MonoBehaviour>().OfType<IPlayerRespawnListener>(); + foreach (var listener in listeners) + { + for (var i = _checkpoints.Count - 1; i >= 0; i--) + { + var distance = ((MonoBehaviour)listener).transform.position.x - _checkpoints [i].transform.position.x; + if (distance < 0) + continue; + + _checkpoints [i].AssignObjectToCheckpoint (listener); + break; + } + } + +#if UNITY_EDITOR + if (DebugSpawn != null) + DebugSpawn.SpawnPlayer (Player); + else if (_currentCheckPointIndex != -1) + _checkpoints [_currentCheckPointIndex].SpawnPlayer (Player); + +#else + if (_currentCheckPointIndex != 1) + _checkpoints[_currentCheckPointIndex].SpawnPlayer(Player); +#endif + + + } + + public void Update() + { + var isAtLastCheckpoint = _currentCheckPointIndex + 1 >= _checkpoints.Count; + if (isAtLastCheckpoint) + return; + + var distanceToNextCheckpoint = _checkpoints [_currentCheckPointIndex + 1].transform.position.x - Player.transform.position.x; + if (distanceToNextCheckpoint >= 0) + return; + + _checkpoints [_currentCheckPointIndex].PlayerLeftCheckpoint (); + _currentCheckPointIndex++; + _checkpoints [_currentCheckPointIndex].PlayerHitCheckpoint (); + + GameManager.Instance.AddPoints (CurrentTimeBonus); + _savedPoints = GameManager.Instance.Points; + _started = DateTime.UtcNow; + + } + + public void KillPlayer() + { + StartCoroutine(KillPlayerCo()); + } + + private IEnumerator KillPlayerCo() + { + Player.Kill(); + Camera.IsFollowing = false; + yield return new WaitForSeconds(2f); + + Camera.IsFollowing = true; + + if (_currentCheckPointIndex != -1) + _checkpoints [_currentCheckPointIndex].SpawnPlayer (Player); + + _started = DateTime.UtcNow; + GameManager.Instance.ResetPoints (_savedPoints); + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..bc54f53ca9c9fef1e9d4dfc5aadc63db31caf12e --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/LevelManager.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 28ee1112dd162473986dcde784a02115 +timeCreated: 1471903497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs new file mode 100644 index 0000000000000000000000000000000000000000..3c91b300b01a836915ec4566801f21fbd50ef609 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs @@ -0,0 +1,46 @@ +using UnityEngine; +using System.Collections; + +public class Movement : MonoBehaviour { + + private float inputDirection; + private float inputHeight; + private float verticalVelocity; + private bool doubleJump = false; + + private float speed = 5.0f; + private float gravity= 0.5f; + + private Vector3 moveVector; + private CharacterController controller; + + void Start () { + controller = GetComponent<CharacterController> (); + } + + // Update is called once per frame + void Update () { + inputDirection = Input.GetAxis ("Horizontal") * speed; + + if (controller.isGrounded) { + + verticalVelocity = 0; + + if (Input.GetKeyDown (KeyCode.Space)) { + verticalVelocity = 10; + doubleJump = true; + } + } else { + if (Input.GetKeyDown (KeyCode.Space)) { + if (doubleJump) { + verticalVelocity = 10; + doubleJump = false; + } + } + verticalVelocity -= gravity; + } + moveVector = new Vector3 (inputDirection, verticalVelocity, 0); + controller.Move (moveVector * Time.deltaTime); + } +} + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..1731e66fe3278b94f36b622fbefbb13272afb972 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Movement.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1cb7d5bc81ddd40588013ec439743411 +timeCreated: 1467852453 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs new file mode 100644 index 0000000000000000000000000000000000000000..2617c920be228d574d08902abb5e33a645dfd517 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs @@ -0,0 +1,45 @@ +using UnityEngine; +using System; +using System.Collections.Generic; +using System.Collections; +using System.Linq; + +public class PathDefinition : MonoBehaviour { + + public Transform[] Points; + + public IEnumerator<Transform> GetPathsEnumerator() + { + if (Points == null || Points.Length < 1) + yield break; + var direction = 1; + var index = 0; + while (true) { + yield return Points[index]; + + if (Points.Length == 1) + continue; + + if (index <= 0) + direction = 1; + else if (index >= Points.Length - 1) + direction = -1; + + index = index + direction; + } + } + + public void OnDrawGizmos() + { + if (Points == null || Points.Length < 2) + return; + + var points = Points.Where (tag => tag != null).ToList (); + if (points.Count < 2) + return; + + for (var i = 1; i < points.Count; i++) { + Gizmos.DrawLine(points[i - 1].position, points[i].position); + } + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..4244652201b0bda9745e8c28e0e031aa7b37191a --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PathDefinition.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f5c9ac095973249608b8e4e334463e11 +timeCreated: 1468970423 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs new file mode 100644 index 0000000000000000000000000000000000000000..3bd67e13b751a4a069872211762030b624afd9ef --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs @@ -0,0 +1,101 @@ +using UnityEngine; +using System.Collections; + +public class Player : MonoBehaviour { + + private bool _isFacingRight; + private CharacterController2D _controller; + private float _normalizedHorizontalSpeed; + + public float MaxSpeed =8; + public float SpeedAccelerationOnGround = 10f; + public float SpeedAccelerateionInAir = 5f; + public int MaxHealth = 100; + public GameObject OuchEffect; + + public int Health { get; private set; } + public bool IsDead { get; private set; } + + public void Awake() + { + + _controller = GetComponent <CharacterController2D>(); + _isFacingRight = transform.localScale.x > 0; + Health = MaxHealth; + + } + + public void Update() + { + if(!IsDead) + HandleInput(); + + var movementFactor = _controller.State.IsGrounded ? SpeedAccelerationOnGround : SpeedAccelerateionInAir; + if (IsDead) + _controller.SetHorizontalForce (0); + else + _controller.SetHorizontalForce (Mathf.Lerp(_controller.Velocity.x, _normalizedHorizontalSpeed * MaxSpeed, Time.deltaTime * movementFactor)); + + } + + public void Kill() + { + _controller.HandleCollisions = false; + this.gameObject.GetComponent<Collider2D>().enabled = false; + IsDead = true; + + _controller.SetForce (new Vector2 (0, 20)); + } + + public void RespawnAt(Transform spawnPoint) + { + if (!_isFacingRight) + Flip(); + + IsDead = false; + this.gameObject.GetComponent<Collider2D>().enabled = true; + _controller.HandleCollisions = true; + + transform.position = spawnPoint.position; + } + + public void TakeDamage(int damage) + { + Instantiate (OuchEffect, transform.position, transform.rotation); + Health -= damage; + + if (Health <= 0) + LevelManager.Instance.KillPlayer(); + } + + private void HandleInput () + { + if (Input.GetKey (KeyCode.D)) { + _normalizedHorizontalSpeed = 1; + if (!_isFacingRight) + Flip (); + } + + else if ( Input.GetKey(KeyCode.A)) + { + _normalizedHorizontalSpeed = -1; + if (_isFacingRight) + Flip (); + } + else + { + _normalizedHorizontalSpeed = 0; + } + + if(_controller.CanJump && Input.GetKeyDown(KeyCode.Space)) + { + _controller.Jump(); + } + } + + private void Flip() + { + transform.localScale = new Vector3 (-transform.localScale.x, transform.localScale.y, transform.localScale.z); + _isFacingRight = transform.localScale.x > 0; + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..41592e16fd65fd47a35f81e32b43a6edc324739b --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Player.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d1c9e7f668f264e7c8f5b8c57a30f22e +timeCreated: 1469421143 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs new file mode 100644 index 0000000000000000000000000000000000000000..898ea78c000713376d75423add0292f26f9c95ec --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +public class PointStar : MonoBehaviour, IPlayerRespawnListener +{ + public GameObject Effect; + public int PointsToAdd = 10; + + public void OnTriggerEnter2D(Collider2D other) + { + if (other.GetComponent<Player> () == null) + return; + + GameManager.Instance.AddPoints (PointsToAdd); + Instantiate (Effect, transform.position, transform.rotation); + + gameObject.SetActive (false); + } + public void OnPlayerRespwanInThisCheckpoint(Checkpoint checkpount, Player player) + { + gameObject.SetActive(true); + } +} + + + + diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d8e1b0fa04ec20c09246a3e8f753040d67df417e --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/PointStar.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b87edeb3cc040481bb4641fdaba3b3be +timeCreated: 1472517453 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs new file mode 100644 index 0000000000000000000000000000000000000000..1f94915a9e9d6462215690927fa3b5d8cf2aa7bf --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs @@ -0,0 +1,64 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; + +namespace NG{ +class Room : IComparable<Room> { + public List<Coordinates> tiles; + public List<Coordinates> edgeTiles; + public List<Room> connectedRooms; + public int roomSize; + public bool isAccessibleFromMainRoom; + public bool isMainRoom; + + public Room() { + } + + public Room(List<Coordinates> roomTiles, int[,] map) { + tiles = roomTiles; + roomSize = tiles.Count; + connectedRooms = new List<Room>(); + + edgeTiles = new List<Coordinates>(); + foreach (Coordinates tile in tiles) { + for (int x = tile.x-1; x <= tile.x+1; x++) { + for (int y = tile.y-1; y <= tile.y+1; y++) { + if (x == tile.x || y == tile.y) { + if (map[x,y] == 1) { + edgeTiles.Add(tile); + } + } + } + } + } + } + + public void SetAccessibleFromMainRoom() { + if (!isAccessibleFromMainRoom) { + isAccessibleFromMainRoom = true; + foreach (Room connectedRoom in connectedRooms) { + connectedRoom.SetAccessibleFromMainRoom(); + } + } + } + + public static void ConnectRooms(Room roomA, Room roomB) { + if (roomA.isAccessibleFromMainRoom) { + roomB.SetAccessibleFromMainRoom (); + } else if (roomB.isAccessibleFromMainRoom) { + roomA.SetAccessibleFromMainRoom(); + } + roomA.connectedRooms.Add (roomB); + roomB.connectedRooms.Add (roomA); + } + + public bool IsConnected(Room otherRoom) { + return connectedRooms.Contains(otherRoom); + } + + public int CompareTo(Room otherRoom) { + return otherRoom.roomSize.CompareTo (roomSize); + } + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d939dec4378f8c6eb81f125642ebef0dddc05966 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/Room.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6216c27d1599b492f9096eca267fd874 +timeCreated: 1506197815 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs b/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs new file mode 100644 index 0000000000000000000000000000000000000000..cb6cbe92001e190117385d27cae5c6d766cd969b --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using System.Collections; + +public class SortParticleSystem : MonoBehaviour { + + public string LayerName = "Particles"; + + public void Start() + { + this.GetComponent<ParticleSystemRenderer>().sortingLayerName = "Particles"; + } + +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs.meta b/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..dd92d1e34ddc926c7cb0aeb5ad8abbb008e895ac --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/OldScripts/SortParticleSystem.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f69c2a91122da4f13b0b35e7dec3a9c0 +timeCreated: 1471399247 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap.meta new file mode 100644 index 0000000000000000000000000000000000000000..453f1c7d45dd4d424d1290a20364197f6e698713 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7cbd56a6a03150240b74d38497e00375 +folderAsset: yes +timeCreated: 1477463977 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/.DS_Store b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4138336ef0472a33deb172270ad30b39c3f0cd2e Binary files /dev/null and b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/.DS_Store differ diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs new file mode 100644 index 0000000000000000000000000000000000000000..3b0fb88e20d24970f100c563213de230f9a27fb9 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace NG +{ + public class Area : MonoBehaviour + { + public AreaData areaData { get; set; } + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..e7a086a5a24493fe3bb3766ad8e1ae6c127336a0 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Area.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2a96a6b53d424f34e848dce592e17d1e +timeCreated: 1477461567 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs new file mode 100644 index 0000000000000000000000000000000000000000..2d473c459704aaecc1eb0039a8b6151b6790e1b8 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +namespace NG +{ + + [Serializable] // Serialized so it will show in Unity's inspector. + public class AreaData + { + [HideInInspector] + public GameObject representation; + + public string name; + + /// <summary> + /// The transitions that are available on this Area + /// </summary> + public Direction[] availableTransitions; + + public Coordinates coordinates; + + /// <summary> + /// The transitions that have been connected to. + /// </summary> + public Dictionary<Direction, KeyValuePair<AreaData, Direction>> transitions = + new Dictionary<Direction, KeyValuePair<AreaData, Direction>>(); + + /// <summary> + /// Constructor with the minimum required values to set up the properties. + /// </summary> + /// <param name="name">The name of the area</param> + /// <param name="availableTransitions"> + /// A list of transitions this area has. This list is copied. + /// </param> + public AreaData(string name, Direction[] availableTransitions) + { + this.name = name; + + // We need to make a copy of this array since it will be supplied from + // a template AreaData and we don't want to affect the original. + this.availableTransitions = new Direction[availableTransitions.Length]; + availableTransitions.CopyTo(this.availableTransitions, 0); + } + + + /// <summary> + /// When the transition has been used we will add it to the transitions list. + /// </summary> + /// <param name="thisAreasTransition"> + /// The transition on this area that is being used up. + /// </param> + /// <param name="areaConnectedTo"> + /// The area that this transition connects to. + /// </param> + /// <param name="areasConnection"> + /// The connection on the area that this transition connects to (should always be opposite). + /// </param> + public void SetTransitionUsed( + Direction thisAreasTransition, AreaData areaConnectedTo, Direction areasConnection) + { + if (transitions == null) + transitions = new Dictionary<Direction, KeyValuePair<AreaData, Direction>>(); + + for (int i = 0; i < availableTransitions.Length; i++) + { + if (availableTransitions[i] == thisAreasTransition) + availableTransitions[i] = Direction.None; + } + + if (!transitions.ContainsKey(thisAreasTransition)) + { + transitions.Add( + thisAreasTransition, + new KeyValuePair<AreaData, Direction>(areaConnectedTo, areasConnection)); + } + else + throw new Exception("transition: {0} has already been used!"); + } + + + /// <summary> + /// Returns a string representation of the suppied direction array. + /// Used in generating the names of an AreaData. + /// </summary> + /// <param name="array">The array of Directions to convert to a string.</param> + /// <returns>a string representation of the suppied direction array.</returns> + public static string GetTransitionList(Direction[] array) + { + string s = ""; + for (int i = 0; i < array.Length; i++) + { + s += array[i].ToString() + " "; + } + + return s; + } + + + /// <summary> + /// How many transitions have been set up? + /// </summary> + /// <returns>The count of transitions that have been set on this AreaData.</returns> + public int GetTransitionCount() + { + return transitions == null ? 0 : transitions.Count; + } + + /// <summary> + /// Tells us if the direction has been used or if it is available on this AreaData at all. + /// </summary> + /// <param name="direction">The direction to check.</param> + /// <returns> + /// True if the a tranisition in the Direction can be made, otherwise false. + /// </returns> + public bool GetIsTransitionAvailable(Direction direction) + { + bool isAvailable = false; + for (int i = 0; i < availableTransitions.Length; i++) + { + if (availableTransitions[i] == direction) + { + isAvailable = true; + break; + } + } + + if (!isAvailable) + return false; + + if (transitions == null) + transitions = new Dictionary<Direction, KeyValuePair<AreaData, Direction>>(); + + foreach (var item in transitions) + { + if (item.Key == direction) + return false; + } + + return true; + } + + + /// <summary> + /// Does this AreaData have ANY available transitions? + /// </summary> + /// <returns>True if there are available transitions, otherwise false.</returns> + public bool HasAnyAvailableTransition() + { + int availableTransitionCount = 0; + foreach (var item in availableTransitions) + { + if (item != Direction.None) + availableTransitionCount++; + } + + + return availableTransitionCount > (transitions == null ? 0 : transitions.Count); + } + + + /// <summary> + /// A user-friendly string representation of this AreaData. + /// </summary> + /// <returns>A user-friendly string representation of this AreaData.</returns> + public override string ToString() + { + string s = "name : " + name + "\n"; + + s += "availableTransitions: \n"; + foreach (var item in availableTransitions) + { + s += "\t" + item.ToString() + "\n"; + } + + s += "coordinate: " + coordinates.ToString() + "\n"; + + s += "transitions: \n"; + + if (transitions == null) + transitions = new Dictionary<Direction, KeyValuePair<AreaData, Direction>>(); + + foreach (var item in transitions) + { + s += "\tDirection: " + item.Key.ToString() + + " Area: " + item.Value.Key.name + " Connection: " + item.Value.Value.ToString() + "\n"; + } + + + return s; + } + } + +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..18c9f6f5e4d7e523fbc98b7bdfd2f6080d57b9a6 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaData.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5515a3dc47faf8649b57ed74be70a469 +timeCreated: 1477420577 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs new file mode 100644 index 0000000000000000000000000000000000000000..cc4c8235beb0dbdda1992eaa398ecc0b96fcc7ff --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs @@ -0,0 +1,20 @@ +using UnityEditor; + +namespace NG +{ + [CustomEditor(typeof(Area))] + public class AreaInspector : Editor + { + private Area _area; + + public override void OnInspectorGUI() + { + _area = (Area)target; + + if (_area.areaData != null) + EditorGUILayout.HelpBox("AreaData: \n" + _area.areaData.ToString(), MessageType.None, true); + else + EditorGUILayout.HelpBox("Area data is null", MessageType.Error); + } + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..4d47ddd6ce11885e18071674dcaf27083d8dd26c --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/AreaInspector.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6bb92c8215126cd4383b0d7d2bba9e65 +timeCreated: 1477461567 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs new file mode 100644 index 0000000000000000000000000000000000000000..bd2967ff5ca5e2f7e82d2000f3b2e15e541a4369 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs @@ -0,0 +1,54 @@ +using UnityEngine; +namespace NG +{ + public struct Coordinates + { + public int x; + public int y; + public Coordinates(int x, int y) + { + this.x = x; + this.y = y; + } + + public override string ToString() + { + return string.Format("({0},{1})", x, y); + } + + public Vector2 ToVector2() + { + return new Vector2(x, y); + } + + /// <summary> + /// Returns the coordinate for an adjacent area based on the supplied direction. + /// </summary> + /// <param name="direction">The diretion the adjacent coordinate is at.</param> + /// <returns>A new set of coordinates for that are adjacent to this coordinate.</returns> + public Coordinates GetAdjacentCoordinate(Direction direction) + { + int x = this.x; + int y = this.y; + switch (direction) + { + case Direction.N: + y += 60; + break; + case Direction.E: + x += 100; + break; + case Direction.S: + y -= 60; + break; + case Direction.W: + x -= 100; + break; + default: + break; + } + + return new Coordinates(x, y); + } + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..74dfcd08c90a576fa6675c3240f1ec93d0c2ce74 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Coordinate.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9f04307d33b19744d98a71924aeab197 +timeCreated: 1477423487 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs new file mode 100644 index 0000000000000000000000000000000000000000..434c868b75190ab115bf1cfc4877242994c270eb --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EnterDoor : MonoBehaviour { + + List<GameObject> obj; + bool hasLeftDoor; + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } + + void OnCollisionEnter2D(Collision2D coll){ + Debug.Log ("Here"); + if (coll.collider.tag == "Player") { + coll.transform.position += new Vector3 (100, 0, 0); + } + } + +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..35c03bb27a933f50478a295a31d944b0ff6fc132 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/EnterDoor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fe1a3520b48c2419fa5f2c52c8deae66 +timeCreated: 1507584493 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs new file mode 100644 index 0000000000000000000000000000000000000000..c542bca68e72de1f01a15d8a0dc2f46bb3627cde --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs @@ -0,0 +1,24 @@ +namespace NG +{ + public enum Direction { None, N, E, S, W } + + public static class DirectionExt + { + public static Direction GetOpposite(this Direction direction) + { + switch (direction) + { + case Direction.N: + return Direction.S; + case Direction.E: + return Direction.W; + case Direction.S: + return Direction.N; + case Direction.W: + return Direction.E; + default: + throw new System.Exception("Invalid Direction: " + direction.ToString()); + } + } + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..76308c244ae8d27b74740ff0a877a3721d0d24d7 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/Enums.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a5c0166774112d84786b90889f318d8f +timeCreated: 1477423487 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..f59a66b55e2795a5e25c93000754c0a2b44f5735 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs @@ -0,0 +1,168 @@ +using UnityEngine; +using System.Collections; +using System; +using System.Collections.Generic; + +public class LevelGenerator : MonoBehaviour { + + public int width; + public int height; + + public string seed; + public bool useRandomSeed; + + [Range(0,100)] + public int randomFillPercent; + + public GameObject door; + + int[,] map; + int doorWidth1; + int doorHeight1; + int doorWidth2; + int doorHeight2; + + int n = 0; + int e = 0; + int s = 0; + int w = 0; + + void Start() { + GenerateMap(); + } + + void Update() { + if (Input.GetMouseButtonDown(0)) { + GenerateMap(); + } + } + + void GenerateMap() { + map = new int[width,height]; + RandomFillMap(); + + for (int i = 0; i < 5; i ++) { + SmoothMap(); + } + + MeshCreator meshGen = GetComponent<MeshCreator>(); + meshGen.GenerateMesh(map, 1); + } + + + void RandomFillMap() { + if (useRandomSeed) { + seed = Time.time.ToString(); + } + + System.Random pseudoRandom = new System.Random(seed.GetHashCode()); + + for (int x = 0; x < width; x ++) { + for (int y = 0; y < height; y ++) { + if (x < doorWidth2 && x > doorWidth1 && y < doorHeight1 && y > doorHeight2) { + map [x, y] = 0; + } + else if (x == 0 || x == width - 1 || y == 0 || y == height - 1) { + map [x, y] = 1; + } + else { + map[x,y] = (pseudoRandom.Next(0, 100) < randomFillPercent)? 1: 0; + } + } + } + } + + public void doorPicker(String direction){ + if (direction == "N") { + doorWidth1 = (width/2) - 10; + doorWidth2 = (width/2) + 10; + doorHeight1 = height -1; + doorHeight2 = height - 5; + + n += 1; + GameObject nDoor = Instantiate(door); + nDoor.transform.SetParent (this.transform); + nDoor.transform.position = this.transform.position + new Vector3(0, height/3, 0); + nDoor.GetComponent<BoxCollider2D> ().isTrigger = true; + nDoor.tag = "DoorN"; + nDoor.name = "north door" + n; + } + if (direction == "E") { + doorWidth1 = width - 5; + doorWidth2 = width - 1; + doorHeight1 = (height / 2) + 10; + doorHeight2 = (height / 2) - 10; + + e += 1; + GameObject eDoor = new GameObject (); + eDoor.transform.SetParent (this.transform); + eDoor.transform.position = this.transform.position + new Vector3(width/3, 0, 0); + eDoor.AddComponent<BoxCollider2D> (); + eDoor.GetComponent<BoxCollider2D> ().isTrigger = true; + eDoor.tag = "DoorE"; + eDoor.name = "east door" + e; + } + if (direction == "S") { + doorWidth1 = (width/2) - 10; + doorWidth2 = (width/2) + 10; + doorHeight1 = 5; + doorHeight2 = 0; + + s += 1; + GameObject sDoor = new GameObject (); + sDoor.transform.SetParent (this.transform); + sDoor.transform.position = this.transform.position - new Vector3 (0, height / 3, 0); + sDoor.AddComponent<BoxCollider2D> (); + sDoor.GetComponent<BoxCollider2D> ().isTrigger = true; + sDoor.tag = "DoorS"; + sDoor.name = "south door" + s; + } + if (direction == "W") { + doorWidth1 = 0; + doorWidth2 = 5; + doorHeight1 = (height/2) + 10; + doorHeight2 = (height / 2) - 10; + + w += 1; + GameObject wDoor = new GameObject (); + wDoor.transform.SetParent (this.transform); + wDoor.transform.position = this.transform.position - new Vector3(width/3, 0, 0); + wDoor.AddComponent<BoxCollider2D> (); + wDoor.GetComponent<BoxCollider2D> ().isTrigger = true; + wDoor.tag = "DoorW"; + wDoor.name = "west door" + w; + } + } + + void SmoothMap() { + for (int x = 0; x < width; x ++) { + for (int y = 0; y < height; y ++) { + int neighbourWallTiles = GetSurroundingWallCount(x,y); + + if (neighbourWallTiles > 4) + map[x,y] = 1; + else if (neighbourWallTiles < 4) + map[x,y] = 0; + + } + } + } + + int GetSurroundingWallCount(int gridX, int gridY) { + int wallCount = 0; + for (int neighbourX = gridX - 1; neighbourX <= gridX + 1; neighbourX ++) { + for (int neighbourY = gridY - 1; neighbourY <= gridY + 1; neighbourY ++) { + if (neighbourX >= 0 && neighbourX < width && neighbourY >= 0 && neighbourY < height) { + if (neighbourX != gridX || neighbourY != gridY) { + wallCount += map[neighbourX,neighbourY]; + } + } + else { + wallCount ++; + } + } + } + + return wallCount; + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..03ffc65395deb07b80922312c582a092c4bf77ed --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/LevelGenerator.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dd13f63029e32489e9f35038445ef868 +timeCreated: 1506111519 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs new file mode 100644 index 0000000000000000000000000000000000000000..bfa0a0bd3638ad62fad6a6319c9c691b8744b7ab --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs @@ -0,0 +1,355 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MeshCreator : MonoBehaviour { + + public SquareGrid squareGrid; + public MeshFilter cave; + + List<Vector3> vertices; + List<int> triangles; + + Dictionary<int,List<Triangle>> triangleDictionary = new Dictionary<int, List<Triangle>> (); + List<List<int>> outlines = new List<List<int>> (); + HashSet<int> checkedVertices = new HashSet<int>(); + + public void GenerateMesh(int[,] map, float squareSize) { + + triangleDictionary.Clear (); + outlines.Clear (); + checkedVertices.Clear (); + + squareGrid = new SquareGrid(map, squareSize); + + vertices = new List<Vector3>(); + triangles = new List<int>(); + + for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) { + for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) { + TriangulateSquare(squareGrid.squares[x,y]); + } + } + + Mesh mesh = new Mesh(); + cave.mesh = mesh; + + mesh.vertices = vertices.ToArray(); + mesh.triangles = triangles.ToArray(); + mesh.RecalculateNormals(); + + int tileAmount = 10; + Vector2[] uvs = new Vector2[vertices.Count]; + for (int i =0; i < vertices.Count; i ++) { + float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize,map.GetLength(0)/2*squareSize,vertices[i].x) * tileAmount; + float percentY = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize,map.GetLength(0)/2*squareSize,vertices[i].z) * tileAmount; + uvs[i] = new Vector2(percentX,percentY); + } + mesh.uv = uvs; + + Generate2DColliders(); + + this.tag = "Walls"; + } + + void Generate2DColliders() { + + EdgeCollider2D[] currentColliders = gameObject.GetComponents<EdgeCollider2D> (); + for (int i = 0; i < currentColliders.Length; i++) { + Destroy(currentColliders[i]); + } + + CalculateMeshOutlines (); + + + foreach (List<int> outline in outlines) { + EdgeCollider2D edgeCollider = gameObject.AddComponent<EdgeCollider2D>(); + Vector2[] edgePoints = new Vector2[outline.Count]; + + for (int i =0; i < outline.Count; i ++) { + edgePoints[i] = new Vector2(vertices[outline[i]].x,vertices[outline[i]].z); + } + edgeCollider.points = edgePoints; + } + + } + + void TriangulateSquare(Square square) { + switch (square.configuration) { + case 0: + break; + + // 1 points: + case 1: + MeshFromPoints(square.centreLeft, square.centreBottom, square.bottomLeft); + break; + case 2: + MeshFromPoints(square.bottomRight, square.centreBottom, square.centreRight); + break; + case 4: + MeshFromPoints(square.topRight, square.centreRight, square.centreTop); + break; + case 8: + MeshFromPoints(square.topLeft, square.centreTop, square.centreLeft); + break; + + // 2 points: + case 3: + MeshFromPoints(square.centreRight, square.bottomRight, square.bottomLeft, square.centreLeft); + break; + case 6: + MeshFromPoints(square.centreTop, square.topRight, square.bottomRight, square.centreBottom); + break; + case 9: + MeshFromPoints(square.topLeft, square.centreTop, square.centreBottom, square.bottomLeft); + break; + case 12: + MeshFromPoints(square.topLeft, square.topRight, square.centreRight, square.centreLeft); + break; + case 5: + MeshFromPoints(square.centreTop, square.topRight, square.centreRight, square.centreBottom, square.bottomLeft, square.centreLeft); + break; + case 10: + MeshFromPoints(square.topLeft, square.centreTop, square.centreRight, square.bottomRight, square.centreBottom, square.centreLeft); + break; + + // 3 point: + case 7: + MeshFromPoints(square.centreTop, square.topRight, square.bottomRight, square.bottomLeft, square.centreLeft); + break; + case 11: + MeshFromPoints(square.topLeft, square.centreTop, square.centreRight, square.bottomRight, square.bottomLeft); + break; + case 13: + MeshFromPoints(square.topLeft, square.topRight, square.centreRight, square.centreBottom, square.bottomLeft); + break; + case 14: + MeshFromPoints(square.topLeft, square.topRight, square.bottomRight, square.centreBottom, square.centreLeft); + break; + + // 4 point: + case 15: + MeshFromPoints(square.topLeft, square.topRight, square.bottomRight, square.bottomLeft); + checkedVertices.Add(square.topLeft.vertexIndex); + checkedVertices.Add(square.topRight.vertexIndex); + checkedVertices.Add(square.bottomRight.vertexIndex); + checkedVertices.Add(square.bottomLeft.vertexIndex); + break; + } + + } + + void MeshFromPoints(params Node[] points) { + AssignVertices(points); + + if (points.Length >= 3) + CreateTriangle(points[0], points[1], points[2]); + if (points.Length >= 4) + CreateTriangle(points[0], points[2], points[3]); + if (points.Length >= 5) + CreateTriangle(points[0], points[3], points[4]); + if (points.Length >= 6) + CreateTriangle(points[0], points[4], points[5]); + + } + + void AssignVertices(Node[] points) { + for (int i = 0; i < points.Length; i ++) { + if (points[i].vertexIndex == -1) { + points[i].vertexIndex = vertices.Count; + vertices.Add(points[i].position); + } + } + } + + void CreateTriangle(Node a, Node b, Node c) { + triangles.Add(a.vertexIndex); + triangles.Add(b.vertexIndex); + triangles.Add(c.vertexIndex); + + Triangle triangle = new Triangle (a.vertexIndex, b.vertexIndex, c.vertexIndex); + AddTriangleToDictionary (triangle.vertexIndexA, triangle); + AddTriangleToDictionary (triangle.vertexIndexB, triangle); + AddTriangleToDictionary (triangle.vertexIndexC, triangle); + } + + void AddTriangleToDictionary(int vertexIndexKey, Triangle triangle) { + if (triangleDictionary.ContainsKey (vertexIndexKey)) { + triangleDictionary [vertexIndexKey].Add (triangle); + } else { + List<Triangle> triangleList = new List<Triangle>(); + triangleList.Add(triangle); + triangleDictionary.Add(vertexIndexKey, triangleList); + } + } + + void CalculateMeshOutlines() { + + for (int vertexIndex = 0; vertexIndex < vertices.Count; vertexIndex ++) { + if (!checkedVertices.Contains(vertexIndex)) { + int newOutlineVertex = GetConnectedOutlineVertex(vertexIndex); + if (newOutlineVertex != -1) { + checkedVertices.Add(vertexIndex); + + List<int> newOutline = new List<int>(); + newOutline.Add(vertexIndex); + outlines.Add(newOutline); + FollowOutline(newOutlineVertex, outlines.Count-1); + outlines[outlines.Count-1].Add(vertexIndex); + } + } + } + } + + void FollowOutline(int vertexIndex, int outlineIndex) { + outlines [outlineIndex].Add (vertexIndex); + checkedVertices.Add (vertexIndex); + int nextVertexIndex = GetConnectedOutlineVertex (vertexIndex); + + if (nextVertexIndex != -1) { + FollowOutline(nextVertexIndex, outlineIndex); + } + } + + int GetConnectedOutlineVertex(int vertexIndex) { + List<Triangle> trianglesContainingVertex = triangleDictionary [vertexIndex]; + + for (int i = 0; i < trianglesContainingVertex.Count; i ++) { + Triangle triangle = trianglesContainingVertex[i]; + + for (int j = 0; j < 3; j ++) { + int vertexB = triangle[j]; + if (vertexB != vertexIndex && !checkedVertices.Contains(vertexB)) { + if (IsOutlineEdge(vertexIndex, vertexB)) { + return vertexB; + } + } + } + } + + return -1; + } + + bool IsOutlineEdge(int vertexA, int vertexB) { + List<Triangle> trianglesContainingVertexA = triangleDictionary [vertexA]; + int sharedTriangleCount = 0; + + for (int i = 0; i < trianglesContainingVertexA.Count; i ++) { + if (trianglesContainingVertexA[i].Contains(vertexB)) { + sharedTriangleCount ++; + if (sharedTriangleCount > 1) { + break; + } + } + } + return sharedTriangleCount == 1; + } + + struct Triangle { + public int vertexIndexA; + public int vertexIndexB; + public int vertexIndexC; + int[] vertices; + + public Triangle (int a, int b, int c) { + vertexIndexA = a; + vertexIndexB = b; + vertexIndexC = c; + + vertices = new int[3]; + vertices[0] = a; + vertices[1] = b; + vertices[2] = c; + } + + public int this[int i] { + get { + return vertices[i]; + } + } + + + public bool Contains(int vertexIndex) { + return vertexIndex == vertexIndexA || vertexIndex == vertexIndexB || vertexIndex == vertexIndexC; + } + } + + public class SquareGrid { + public Square[,] squares; + + public SquareGrid(int[,] map, float squareSize) { + int nodeCountX = map.GetLength(0); + int nodeCountY = map.GetLength(1); + float mapWidth = nodeCountX * squareSize; + float mapHeight = nodeCountY * squareSize; + + ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY]; + + for (int x = 0; x < nodeCountX; x ++) { + for (int y = 0; y < nodeCountY; y ++) { + Vector3 pos = new Vector3(-mapWidth/2 + x * squareSize + squareSize/2, 0, -mapHeight/2 + y * squareSize + squareSize/2); + controlNodes[x,y] = new ControlNode(pos,map[x,y] == 1, squareSize); + } + } + + squares = new Square[nodeCountX -1,nodeCountY -1]; + for (int x = 0; x < nodeCountX-1; x ++) { + for (int y = 0; y < nodeCountY-1; y ++) { + squares[x,y] = new Square(controlNodes[x,y+1], controlNodes[x+1,y+1], controlNodes[x+1,y], controlNodes[x,y]); + } + } + + } + } + + public class Square { + + public ControlNode topLeft, topRight, bottomRight, bottomLeft; + public Node centreTop, centreRight, centreBottom, centreLeft; + public int configuration; + + public Square (ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft) { + topLeft = _topLeft; + topRight = _topRight; + bottomRight = _bottomRight; + bottomLeft = _bottomLeft; + + centreTop = topLeft.right; + centreRight = bottomRight.above; + centreBottom = bottomLeft.right; + centreLeft = bottomLeft.above; + + if (topLeft.active) + configuration += 8; + if (topRight.active) + configuration += 4; + if (bottomRight.active) + configuration += 2; + if (bottomLeft.active) + configuration += 1; + } + + } + + public class Node { + public Vector3 position; + public int vertexIndex = -1; + + public Node(Vector3 _pos) { + position = _pos; + } + } + + public class ControlNode : Node { + + public bool active; + public Node above, right; + + public ControlNode(Vector3 _pos, bool _active, float squareSize) : base(_pos) { + active = _active; + above = new Node(position + Vector3.forward * squareSize/2f); + right = new Node(position + Vector3.right * squareSize/2f); + } + + } +} \ No newline at end of file diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..8679a0b68a9fdc8ee9cb8d68f1b2cc1bef2f2cfb --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/MeshCreator.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cfa29abaf61b04b0094cdd9a671722d5 +timeCreated: 1506112585 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..c5f876862c4a441a787aac326cebe846f682f212 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs @@ -0,0 +1,263 @@ +using UnityEngine; +using System.Collections.Generic; + +namespace NG +{ + public class SceneGenerator : MonoBehaviour + { + /// <summary> + /// The number of iterations the generator should go through. + /// </summary> + public int iterations = 5; + + /// <summary> + /// the AreaData templates that will be used in generating the scene. + /// </summary> + public AreaData[] areaDatas; + + /// <summary> + /// The areas generated by Generate(). + /// </summary> + public List<AreaData> generatedAreas { get; set; } + + public Material material; + public GameObject levelMesh; + + public int dungeonHeight; + public int dungeonWidth; + + public GameObject startPoint; + public GameObject doorPrefab; + + void Generate() + { + generatedAreas = new List<AreaData>(); + + // Select a random area to start with. + int randomAreaIndex = Random.Range(0, areaDatas.Length); + AreaData randomArea = areaDatas[randomAreaIndex]; + + // Create a copy of the AreaData. + AreaData newArea = new AreaData(randomArea.name, randomArea.availableTransitions); + + for (int i = 0; i < iterations; i++) + { + // Iterate through this area's transitions and add connections + // however, we'll also need to check for existing areas blocking the way or that should be connected + for (int j = 0; j < newArea.availableTransitions.Length; j++) + { + Direction transition = newArea.availableTransitions[j]; + + if (transition == Direction.None) + continue; + + Direction opposite = transition.GetOpposite(); + + Coordinates adjacentAreaCoordinate = newArea.coordinates.GetAdjacentCoordinate(transition); + AreaData adjacentArea = GetGeneratedAreaByCoordinate(adjacentAreaCoordinate); + + // if there's an area in the way check if it has an available transition opposite of this transition. + if (adjacentArea != null) + { + if (!adjacentArea.GetIsTransitionAvailable(opposite)) + { + // The adjecent area cannot be transitioned to from this area. + adjacentArea = null; + + // We should actually now flag this direction as no longer viable. + newArea.availableTransitions[j] = Direction.None; + } + } + // otherwise create a new area + else + { + adjacentArea = CreateRandomAreaWithTransition(opposite); + + if (adjacentArea == null) + { + Debug.LogErrorFormat( + "Could not GetRandomAreaWithTransition({0}). " + + "Please ensure areaDatas has available transitions on all sides", + opposite); + } + else + { + adjacentArea.coordinates = adjacentAreaCoordinate; + generatedAreas.Add(adjacentArea); + } + } + + if (adjacentArea != null) + { + // assign the connection between the two areas. + newArea.SetTransitionUsed(transition, adjacentArea, opposite); + adjacentArea.SetTransitionUsed(opposite, newArea, transition); + } + } + + // check to see if we assigned any transitions to this new area, if so add it to the generatedAreas list. + if (newArea.GetTransitionCount() > 0) + { + if (!generatedAreas.Contains(newArea)) + generatedAreas.Add(newArea); + } + // otherwise did something go wrong? + else + { + Debug.LogWarning("No transitions assigned to area: " + newArea.ToString()); + } + + // Now we need to get the next area to work on. + newArea = null; + foreach (var item in generatedAreas) + { + if (item.HasAnyAvailableTransition()) + { + newArea = item; + break; + } + } + + if (newArea == null) + { + Debug.Log("Can't find any generated areas with avilable transitions. Quitting."); + break; + } + } + } + + + /// <summary> + /// Checks the list of generated areas to see if one exists at the supplied coordinates. + /// </summary> + /// <param name="coordinates">Coordinates to check if an area exists at.</param> + /// <returns>An area from the generated areas list matching the supplied coordinates. + /// If none is found, then null is returned.</returns> + private AreaData GetGeneratedAreaByCoordinate(Coordinates coordinates) + { + foreach (var item in generatedAreas) + { + if (item.coordinates.x == coordinates.x && item.coordinates.y == coordinates.y) + return item; + } + + return null; + } + + + /// <summary> + /// Creates a new random area with the indicated position available. + /// </summary> + /// <param name="transition">The transition that needs to be available on the area.</param> + /// <returns>A new AreaData with matching transition. If none can be found then null is returned.</returns> + private AreaData CreateRandomAreaWithTransition(Direction transition) + { + int areaDatasIndex = Random.Range(0, areaDatas.Length); + + //Debug.Log("transition to look for: " + transition); + + for (int i = 0; i < areaDatas.Length; i++) + { + bool isTransitionAvailable = areaDatas[areaDatasIndex].GetIsTransitionAvailable(transition); + //Debug.LogFormat("areaDatasIndex: {0} areaData {1} available: {2}", areaDatasIndex, areaDatas[areaDatasIndex], isTransitionAvailable); + + if (isTransitionAvailable) + return new AreaData( + areaDatas[areaDatasIndex].name, + areaDatas[areaDatasIndex].availableTransitions); + + areaDatasIndex++; + if (areaDatasIndex == areaDatas.Length) + areaDatasIndex = 0; + } + + return null; + } + + + void Awake() + { + Generate(); + + CreateRepresentation(); + } + + + /// <summary> + /// Creates cubes for each generated area and cubes to show the transitions between each. + /// Transitions are offset so that we can see 1 exists in each direction (to/from). + /// </summary> + void CreateRepresentation() + { + for (int i = 0; i < generatedAreas.Count; i++) + { + GameObject section = new GameObject(); + GameObject newMesh = Instantiate (levelMesh); + // Attach an Area component so we can easily inspect the AreaData in the editor. + section.AddComponent<LevelGenerator>(); + section.AddComponent <MeshCreator>(); + section.AddComponent<MeshRenderer>(); + + section.GetComponent<LevelGenerator> ().door = doorPrefab; + section.GetComponent<MeshRenderer> ().material = material; + section.GetComponent<LevelGenerator> ().randomFillPercent = Random.Range (40, 45); + section.GetComponent<LevelGenerator> ().width = dungeonWidth; + section.GetComponent<LevelGenerator> ().height = dungeonHeight; + section.GetComponent<LevelGenerator> ().useRandomSeed = true; + section.GetComponent<MeshCreator> ().cave = newMesh.GetComponent<MeshFilter>(); + newMesh.transform.Rotate (-90, 0, 0); + newMesh.transform.SetParent (section.transform, true); + + //section.GetComponent<LevelGenerator> ().startPoint = startPoint; + + Area area = section.AddComponent<Area>(); + + generatedAreas[i].name = i + " - " + generatedAreas[i].name; + area.areaData = generatedAreas[i]; + section.transform.position = generatedAreas[i].coordinates.ToVector2(); + section.transform.localScale = 0.75f * Vector3.one; + section.name = generatedAreas[i].name; + + foreach (var item in generatedAreas[i].transitions) + { + Vector2 transitionPostion = + 0.5f * (generatedAreas[i].coordinates.ToVector2() + item.Value.Key.coordinates.ToVector2()); + + GameObject transition = GameObject.CreatePrimitive(PrimitiveType.Cube); + Vector3 scale = 2f * Vector3.one; + transition.name = item.Key.ToString() + " to " + item.Value.Value.ToString(); + + switch (item.Key) + { + case Direction.N: + transitionPostion.x += 10f; + scale.y = 2f; + section.GetComponent<LevelGenerator> ().doorPicker ("N"); + break; + case Direction.E: + transitionPostion.y += 0f; + scale.x = 2f; + section.GetComponent<LevelGenerator> ().doorPicker ("E"); + break; + case Direction.S: + scale.y = 2f; + transitionPostion.x -= 10f; + section.GetComponent<LevelGenerator> ().doorPicker ("S"); + break; + case Direction.W: + transitionPostion.y -= 0f; + scale.x = 2f; + section.GetComponent<LevelGenerator> ().doorPicker ("W"); + break; + default: + break; + } + + transition.transform.position = transitionPostion; + transition.transform.localScale = scale; + transition.transform.SetParent(section.transform, true); + } + } + } + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs.meta b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..568461ffa72d5053f8387f670cc492511e0c6d69 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/Procedural2dMap/SceneGenerator.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 10a34cba4651e944f8dca3c077f92db2 +timeCreated: 1477423487 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: