Post

Relentless Attack

This is the new game inspiration The Army - Idle Strategy Game.

Scriptable Objects

For this project rather than creating the spawning grid each time the game starts, I thought I would rather create a Scriptable Object. This way I was able to draw the grid out side of play time which was helpful for scaling to fit the screen. This was mostly done without tutorials which I am really proud of.

Unit Testing

Following this tutorial Unit Tests in Unity I set up very basic unit testing. Currently just checking if the init() function of my EnemyBase class is behaving as expected. But is has gotten me thinking more about what I should and shouldn’t be testing.

With the help of Chat, I have further expanded the Unit tests to include the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class GameManagerTesting
{
    [UnityTest]
    public IEnumerator ASoldierSetup_Test()
    {
        GameObject mGameObject = new GameObject();
        GameManager mGameManager = new GameManager();

        SceneManager.LoadScene("Soldier");

        yield return new WaitForSeconds(2);

        Assert.IsTrue(mGameManager.SetUpGameScene(), "Failed to set up the scene correctly");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class EnemyBaseTesting
{
    [Test]
    [TestCase(10, true, 10)]
    [TestCase(28, true, 100)]
    [TestCase(1, false, 1)]
    public void AInit_Test(int setHealth, bool isEnemy, int setSpeed)
    {
        GameObject mGameObject = new GameObject();
        EnemyBase mEnemy = mGameObject.AddComponent<EnemyBase>();
        Assert.IsNotNull(mEnemy, "Failed to create soldier");

        mEnemy.Init(setHealth, isEnemy, setSpeed);
        Assert.AreEqual(setHealth, mEnemy.HitPoints, "Failed to set health");
        Assert.AreEqual(isEnemy, mEnemy.IsEnemy, "Failed to set enemy");
        Assert.AreEqual(setSpeed, mEnemy.Speed, "Failed to set speed");
    }

    [Test]
    [TestCase(10)]
    [TestCase(-50)]
    public void BAttacked_Test(int attackAmount)
    {
        GameObject mGameObject = new GameObject();
        EnemyBase mEnemy = mGameObject.AddComponent<EnemyBase>();
        mEnemy.Init(100, true, 5.0f);

        mEnemy.Attacked(attackAmount);

        if (attackAmount > 0)
        {
            Assert.AreEqual(100 - attackAmount, mEnemy.HitPoints, "Failed to reduce hitpoint by accacking amount");
        }
        else
        {
            Assert.AreEqual(100, mEnemy.HitPoints, "Failed to filter incorrect attack amounts");
        }
    }
}

This Medium Article was a fantastic resource I found to add the [TestCase(X,X)] which just allows you to pass in variables to the testing functions. Even more than one! So far this has successfully found 2 issues with code changes I have made. This was really cool! The tests only pass on as much information as you give them, so the more detail the better!
Successfullunittests

itch

Git

CommitsMessage
1Initial commit
2Adding the game
3Continue working on enemy class
Implemented simple movement and fixed sprites not colliding.
To do:
Stop jittering when the enemies bunch up
Implement attacking
4Code clean up
5Adding Boundaries
Boundaries and continue work on enemy movement.
6Cont. work on enemies
7Trying a character controller for movement
8IT WAS CHARACTER CONTROLLER
9Player spawn and improved code
10Adding player movement
11ATTACKING
Implemented a very simple attack! But needs lots of work!
12Fixed attacking
13Building and fixed editor scripts
14Create main.yml
15Testing updated actions
16Fix Ui and implement score
17Added a very simple game loop
18Testing Android build method
19Merge branch ‘build’
20Closing untiy
21Removing Android as it broke
22Local Android build
23Update main.yml
24Merge branch ‘main’ of https://github.com/ConnorY97/RelentlessAttack
25Merge branch ‘main’ into build
26Cleaning up the workflow
27Setting up Unit Testing
Created a simple test for enemy set up.
Making sure all the member variables are being set correctly. Currently only testing the attack func.
I need to look into how I can make sure editor variables are being set as well. Very cool!
28Adding test runner action
29Merge branch ‘main’ into build
30Testing as a project not as a package, duh
31Purposely failing unity test
32Merge branch ‘main’ into build
33Trying to improve logs
34Fixing test break
35Lots of work!
1. Fixed the Game over UI
2. Improved attack: there is now a delay between each attach so it doesn’t seem so funky
3. Added some more tests
36Merge branch ‘main’ into build
37Fixing hanging test
38Merge branch ‘main’ into build
39Trying to fix itch upload and android build
40Trying to solve windows build
41Maybe missing the matrix?
42Improving Testing and code clean up
43Changed sprites to circles
So the sprites should have been circles the whole time. Lol
44Merge branch ‘build’
45Merge branch ‘main’ into build
46Alex and Chat suggested code improvement
47Merge branch ‘build’
48Fixing issue found but tests
49Lots of work!
1. Cleaned up the EnemyBase class more. Trying to encapsulate everything all of it inheritors may need.
2. Added the Sniper class. This is just a ranged enemy but it will be difficult to work this into the game play.
3. Improved on the unit testing but have not set any up for the sniper yet
50Creating a Main menu and levels
Removed some magic numbers and continued to work on different enemies
51Main menu main issues
Need to figure out how to assign all the required variables when the required scene loads. Lots of work to do.
52Fixed scene loading and added test
UI will still be broken on some resolutions though
53Closing Unity
54Updated readme and did some work
55Bullet improvements and colours
Added Alex’s suggested changes to the bullet and changed the background colour for the main camera to get rid of the terrible blue.
56Fixing UI and Scaling issues… Hopefully
57Build action set resolution
58Trying a different template
59Trying to copy more settings
60Removing hard code resolution
61Downgrading Unity version
62Removing test runs for the time being
63Stop publishing to itch and just run tests
64Adding bullet tests and improving movment
65You can now spawn snipers
This post is licensed under CC BY 4.0 by the author.