So, I am a bit behind in my schedule but I spent yesterday working on the ECS Movement System and making these temporary sprites for everything.
These sprites I will add colors to later on but for now they are just the possible outlines. I may want to modify the asteroid to make it a bit more asteroid-y in the future.
For the ECS Movement System, the implementation is quite simple. Since my Part 2 post Unity’s ECS has had a few updates which greatly increased my pain yesterday. If you update Entities you may need to change your .NET compiler version to .NET Standard 2.0 in Player -> Other Settings. That was the thing giving me all the headaches. Beyond that they did add something great which made me able to move away from having a MonoBehaviour to a IComponentData struct without any work and that is sort of a free performance upgrade because using IComponentData allows us to take better advantage of the CPU Data cache. The final code for the MovementSystem became this instead of the examples shown in post 2:
There are multiple nice things about this:
And I also took the liberty of adding RelativeMovementDirection to the MovementComponent so we can decide which rotation relative to itself it will move. This is really just to make it so we don’t have to rotate each entity and it can just move in any direction.
After working on the ECS Systems I moved on to player movement. Using the new Input System I was able to quickly set up Movement handled by the PlayerMovement component. Movement is not dependant on the direction you are facing which means pressing the W key will always move you up on the screen even if you are facing down, I did this because it felt a bit more natural and makes it so you can do cooler moves with predictable movement.
With both player movement and the enemy movement working I made an AsteroidSpawner with a few settings that I can tweak for spawning asteroids.
Most of these should be quite self explanatory except for Rotation Normalization Weight at the bottom. What it does is nudge rotations closer to 0 so whilst we have some asteroids that go 35 degrees sideways most of them will go more straight.
Next step was making the player able to shoot and destroy Asteroids. For this we have the PlayerWeapon MonoBehaviour. It takes in a bullet prefab and when you press SPACE it spawns a bullet in front of you in the direction you are facing.
These bullets also use the Movement System to move but have a component(BulletTrigger) that handles destroying asteroids when they collide with it.
So almost a week later. I have done a lot. Besides what I have written above I have made a System for handling when an entity leaves the playspace (it is deleted), updated the sprites and cleaned up some of the code and did a ton more.
First, I added a score system so every time you shot an asteroid you got a few points. The amount of points is determined by the ScoreRewards ScriptableObject and is then stored in the ScoreKeeper ScriptableObject. I really got into using ScriptableObjects for this and it works quite well.
This score system wasn’t quite enough though so I expanded to a GameKeeper which has the current state of the game, it has references to the ScoreRewards and ScoreKeeper and it also handles ending the round when the player dies.
Secondly, I worked on UI and the graphical presentation of the game. Right now as I am writing this the game looks like this
I changed up the sprites, added a bit of color and added a way to display text that fades away in the world. This is used to display points earned when you shoot an asteroid. I genuinely like the graphics right now, it has a sort of retro feeling. I am not sure I will keep the colors the same though. One thing missing from the UI right now is the player’s health and I am working on figuring out the best way to handle it.
Thirdly, I added a very simple main menu. That is missing a lot of things. This is how it currently looks:
I am planning on adding some graphics for the background, links to my social media and then we’ll see what I do. It is a bit too empty right now but it works. When the player dies you get thrown back to the main menu.
I am gonna need to cut this post off now because I am already quite far behind in my posting and need to get something out. The next post will likely talk about polish and general fixes and I might finally get around to mobile controls ;)
All this progress is up on my github repo already so check it out here
Written 02 Mar 2020 by Grim