Sharpening skills
Recently I started a new project. It will be something like “Space Invaders”. I thought it’s not that hard to make it and I might give it a shot. So here I’m making prototype of classic space game.
Progress: I’ve made an background that slowly slides down and made small particle-like stars to slide down ( imitation of passing stars? ).
Background sliding was the easy part, however making passing stars took some time. At first I tried to use arrays for storing each star object it all went okay until I came to part where I had to check star’s position and if it went beyond limits remove it. At first it looked like it is working but after few tests I realized that it is not even close to what I want so the endless struggle began. The code began to look messy, lots of useless dummy-variables and endless debugging. After a lot of failures I realized that looking for bug is pointless and I need to find another way to solve this problems.
And this is where I instantly remembered “List” library from Unity scripting tutorials and so I started to implement List! The whole script looked very similar to previous one with arrays. I managed to script the whole thing and, well, it worked but in the same time it didn’t. The stars were appearing, passing and disappearing but the console was flooded with errors: “InvalidOperationException Collection was modified”. After spending some time googling I found out that “foreach” loop in C# doesn’t like to edit List that it is currently looping through ( it sounds logic enough ). So after research and bit of thinking I came up with idea to make secondary list to store star-objects for later destruction. Currently, passing star script contains two main loops: first one who checks passing star position and if it is out of boundaries it gets stored to second list, where the second loop is responsible for deleting elements from first list.
Why arrays at first point? Well, from codding in LUA I was pretty comfortable with arrays that don’t have determined size, it was very convenient and useful but before I started learning C# I didn’t knew that there are languages that require set size for array.
For those who are interested how my script look like:
https://github.com/siauras/Small-Projects/blob/master/Space_shooting_source/backgroundBehaviour.cs










