Skip to content

Commit b98af9c

Browse files
authored
[HP-23] Completed feature 'Entity Management' with tests
* [HP-24] Completed task 'Clear entities' with tests * [HP-25] Completed task 'Player freezes' with tests * [HP-26] Completed task 'Enemy spawning' with tests
1 parent 32c5169 commit b98af9c

22 files changed

+1337
-4
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using NUnit.Framework;
2+
using System.Collections;
3+
using UnityEngine;
4+
using UnityEngine.SceneManagement;
5+
using UnityEngine.TestTools;
6+
7+
public class EntityManagerTests
8+
{
9+
[SetUp]
10+
public void Setup()
11+
{
12+
SceneManager.LoadScene("Overworld", LoadSceneMode.Single);
13+
}
14+
15+
[UnityTest]
16+
public IEnumerator EntitiesClearOnCameraMovement()
17+
{
18+
// Ensures there are items and enemies in the scene.
19+
Assert.NotZero(GameObject.FindGameObjectsWithTag("Item").Length);
20+
Assert.NotZero(GameObject.FindGameObjectsWithTag("Enemy").Length);
21+
22+
// Gets the camera component.
23+
var cameraObj = GameObject.Find("Main Camera");
24+
CameraFollowSnap camSnap = cameraObj.GetComponent<CameraFollowSnap>();
25+
26+
// Gets the player and moves it outside the camera bounds.
27+
var playerObj = GameObject.Find("Player");
28+
playerObj.transform.position = cameraObj.transform.position +
29+
Vector3.right * camSnap.HalfAreaSize.x;
30+
31+
yield return new WaitForSeconds(0.1f);
32+
33+
// Checks that there's no longer any items or enemies in the scene.
34+
Assert.Zero(GameObject.FindGameObjectsWithTag("Item").Length);
35+
Assert.Zero(GameObject.FindGameObjectsWithTag("Enemy").Length);
36+
}
37+
38+
[UnityTest]
39+
public IEnumerator PlayerFreezesOnCameraMovement()
40+
{
41+
// Gets the camera component and sets the initial values.
42+
var cameraObj = GameObject.Find("Main Camera");
43+
CameraFollowSnap camSnap = cameraObj.GetComponent<CameraFollowSnap>();
44+
camSnap.secondsPerPan = 0.5f;
45+
46+
// Gets the player and moves it outside the camera bounds.
47+
var playerObj = GameObject.Find("Player");
48+
playerObj.transform.position = cameraObj.transform.position +
49+
Vector3.right * camSnap.HalfAreaSize.x;
50+
51+
// Pauses for a fraction of a second to allow the camera to start moving.
52+
yield return new WaitForSeconds(0.1f);
53+
54+
// Gets the player position for later comparison.
55+
Vector3 previousPlayerPosition = playerObj.transform.position;
56+
57+
// Gets the player controller and tries to move right.
58+
var playerController = playerObj.GetComponent<TopdownCharacterController>();
59+
Assert.NotNull(playerController);
60+
playerController.MoveRight(true);
61+
62+
// Pauses for a fraction of a second to allow the player to react.
63+
yield return new WaitForSeconds(0.1f);
64+
65+
// Checks that the player has ignored the movement input.
66+
Assert.AreEqual(previousPlayerPosition, playerObj.transform.position);
67+
}
68+
69+
[UnityTest]
70+
public IEnumerator EnemiesSpawnOnCameraMovement()
71+
{
72+
// Gets the camera component and sets the initial values.
73+
var cameraObj = GameObject.Find("Main Camera");
74+
CameraFollowSnap camSnap = cameraObj.GetComponent<CameraFollowSnap>();
75+
camSnap.secondsPerPan = 0.5f;
76+
77+
// Gets the player and moves it outside the camera bounds.
78+
var playerObj = GameObject.Find("Player");
79+
playerObj.transform.position = cameraObj.transform.position +
80+
Vector3.right * camSnap.HalfAreaSize.x;
81+
82+
// Pauses for a fraction of a second to allow the camera to start moving.
83+
yield return new WaitForSeconds(0.55f);
84+
85+
// Checks that there's spawn smoke in the room.
86+
Assert.NotZero(GameObject.FindGameObjectsWithTag("SpawnSmoke").Length);
87+
88+
// Gets the entity manager and waits for the enemy spawn time.
89+
var entityManagerObj = GameObject.Find("EntityManager");
90+
EntityManager entityManager = entityManagerObj.GetComponent<EntityManager>();
91+
yield return new WaitForSeconds(entityManager.enemySpawnSeconds);
92+
93+
// Checks that there's no spawn smoke and there is enemies.
94+
Assert.Zero(GameObject.FindGameObjectsWithTag("SpawnSmoke").Length);
95+
Assert.NotZero(GameObject.FindGameObjectsWithTag("Enemy").Length);
96+
}
97+
}

Assets/GameTests/EntityManagerTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/EnemyMaterial.mat

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: EnemyMaterial
11+
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords: _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 0.64
64+
- _Glossiness: 0.446
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 1
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 1, g: 0.25943398, b: 0.25943398, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/Materials/EnemyMaterial.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/ItemMaterial.mat

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: ItemMaterial
11+
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords: _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 0.64
64+
- _Glossiness: 0.446
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 1
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 1, g: 0.737308, b: 0.2588235, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/Materials/ItemMaterial.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: SpawnSmokeMaterial
11+
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords:
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 1
64+
- _Glossiness: 0.5
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 0
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 0.6037736, g: 0.6037736, b: 0.6037736, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/Materials/SpawnSmokeMaterial.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)