Missiles: Phase 2

Yesterday I got myself to cracking on adding the missile spawning system… Rudimentary and working. I have a generic maxMissiles variable, but I realized that I need a few variables to keep track.

int curMissileBaySize
int maxMissileBaySize
int numOfMissiles
int maxNumOfMissilesOnScreen
boolean spawnMoreBays

maxMissileBaySize will be the largest the missilebay can be.
curMissileBaySize is the current size of the missilebay.

When I get the missilepowerup, I’ll do 2 things:

1) Add a certain number of slots to the curMissileBaySize, and then fill it up with missiles. If the curMissileBaySize == maxMissileBaySize then I set the spawnMoreBays boolean to FALSE. That way I won’t keep adding more slots for the missiles.

2) Increase the maxNumOfMissilesOnScreen by 1. This way I won’t need a separate “increase missile bay size” and “increase number of missiles on screen” powerups. That said, I will have these as separate functions, in case I do need to have them as separate concerns.

If I do this 3 times, I’ll have 4 missiles on screen at a time, and a max bay size of 13. I think this will work fairly well.
My next goals after this are implementing the base beam weapon and a nuke that destroys all asteroids on the screen (and will damage your ship slightly in the process, I think)… White hole and anti-matter field will round out the basic weapon systems, I think.

The beam weapon will require an energy meter that has to recharge over time, as will the white holes, anti-matter field and shield system.

I’m thinking of making a powerup for the shields that if you get hit, it transfers the energy into your energy meter instead of just absorbing the damage as the base shield would do.

Once I get the base weapons systems setup, I think I am going to refactor it all. I would refactor now, but I think I have the basic systems down and it’s easy to copy/paste code, so I do that now, then refactoring once it’s all there.

Once refactoring is done, I’ll start to implement the system to manage death screens and scores. I have a rudimentary system now, but want something more complete. One of my visions is to have little sayings at various levels of scoring. Right now I have one quote: “From stardust you came to stardust you must return”, but hope to have a large variety of things, as part of the process of exploration, so as players get higher and higher scores, new quotes will be revealed. Some will be philosophical some will some will be science, some will be religious, who knows, maybe a math equation or two 😛 Really tap into that whole scheme of experience of being in our universe. I even plan for at least one easter egg with the scoring system.

The achievement system, the tech tree, interstitial menus (to level up the tree), more audio effects, more visual effects to round out everything… I really have to stop slacking so much on this thing if I ever want it to see the light of day!


So, my friend who does development professionally (and got me to dive back into this whole process) told me that he thought I now had a solid prototype (and here I thought I was at the point of finally getting to a game!)

He suggested that I start to consider refactoring. I agree with him on a certain level. I may not be capable of fully implementing his large scale vision (it seems a bit like overkill for a first project), but I am going to take some of his tips and ideas into consideration.

The first issue is how I’m setting certain attributes. I thought I was doing it properly, but I think what I’m doing is accessing the gameobject properties within the update loop, and that is a very expensive process. I should only be doing this once I wake up the object and set it into action. I have a feeling that is the culprit with my performance issues that I noticed on computers that aren’t even that bad, but they’re just not gaming computers. A 2d overhead style shooter should not have any issue on a somewhat modern machine that isn’t a full gaming gamin machine.

The second issue is we discussed my larger vision (beyond the merely apparent shooter aspect) and powerups and such, and one of his ideas I liked was having the achievements system be a (the?) way to access the research points to spend on the powerup tech tree. I think I still want to have some in-game spawns from the black hole (i.e. hawking radiation) that the player collects, and possibly some spawns from asteroids. But having the achievements be part of the research would be cool. Since it was going to originally be a standalone system, having it be part of the mechanic makes it kind of fun. And you can level it up, so for instance maybe the base achievement is “you get a research point for hitting 3 asteroids of the same type in a row”. But if you can do that multiple times, future occurrences might give more or different points.

Once you do something like that, you start thinking about weapons systems, and how an individual’s choice of playing can affect what they want to do, and how what they want to do is affected by research and achievements, and a feedback loop can occur. Do you plow points into bombs and missiles? Research that, and new achievements based upon bombs and missiles will happen, which will open more bomb/missile powerups, etc…

Anyways, the next point is that beyond this, working towards having managers to deal with the various components of the game.

For instance, you would have a weapon manager (which could be a set of small weapons managers), a score manager (calculating score, saving score to a table, etc…), a scene manager (to load scenes as they are needed). I believe one of the benefits of a strong manager system would be putting in some tools to help the designer of the game (as opposed to me as the programmer, even though I am also acting as the designer, right now, as well) be able to modify aspects of the game without having to open a code editor.

So, to balance things like score, I could hit a button to bring up a menu that can let me set the values of asteroids, spawn rates of powerups, and other similar aspects of the game. Then I wouldn’t necessarily have to go back into the code if I wanted to tweak, play with it and try to modify how it works. Playtesting and refinement can happen much quicker that way. Certainly an interesting concept, but it almost seems like overkill for this project.

Now that the Easter holiday is over, I am going to try to get back into digging into the programming again.

Homing Missiles and Rocket Flames

I finally got the rocket flames working. As I believe I previously noted, I had the missiles able to do homing/heat-seeking, and my goal was to get a flame effect trailing it. I finally got it working.

I created a separate “thruster” game object and attached it to the rocket. I then played with Unity’s built in particle effects. I got it to look like I wanted in the preview/editor, but when I pressed the play button to run it, for some reason all I got was a red dot. After playing with it for some time, I realized that I had to update the thruster particle locations and rotations each frame (maybe I’m doing that wrong, but it seemed to be the only way to get it to work).

What was happening, was that the narrow source of the flames was moved up into the center of the object (instead of the bottom, as I had set in scene editor). They were also rotated 90 degrees away from the camera, which is why it looked like a dot. Once I realized that, I simply set the z-position of the thruster to -.50 (half a unit, to get it to move down from the center of the rocket to the bottom). I was mostly confused by this at first, because, technically down is -y not -z… But, I realized that this was due to a previous issue with how unity deals with what’s called UV maps.  That is how the program wraps a square image around a non-square object.  Unity does something that flips it around and makes it strange.  I had to rotate the rocket cube in order to get the ship to look right, but this reoriented it’s local axis, apparently (even though it moves properly and looks right, I guess Y and Z are switch in the local space).

So that was the first tricky thing. Then I was trying to figure out why it was a circle/dot, and not a long jet, and I panned around the scene and saw the long jet trail was moving away from the camera. For the same reason it was all disoriented for location (and why I had to place it on the -z instead of -y) I had to rotate it 90 degrees on the x axis, this moved it from going away from the camera to face down (relatively speaking, when the rocket starts, the software is smart enough to know when I am firing from a different angle, but this is the local orientation of things, so it’s a little weird).

Anyways, I got it working and here’s the video! I have to implement the scoring mechanism for rockets, as well as add the rocket powerup. I just adjusted the size of the rocket and flame so it’s a little more realistic sizewise in comparison to the ship. It looks like a little fish swimming upstream, I think. I’m gonna have to name it something after a fish. Maybe I’ll call it Koi Homing Rockets.

After playing just now and firing off a whole heck of a lot, I’m noticing some bug where it flies off screen and isn’t destroyed or killing any nearby asteroid, so I can’t fire another. I’ll have to make it so if it’s not visible for a period of time, then destroy it.