Gravity Propulsion Bomb

gpbOne of the things I did this week was to program our new power up. I came up with it during last week. It’s called GPB (Gravity Propulsion Bomb). It replaces our older power up; Meteor Shower. The GPB is shot from the player’s cannon and explodes in the sky. It then becomes looks like a black hole and behves like a magnet that pulls in and sucks up all the nearby enemies. One of the alien ship types will drop the power up and you will have to click it to get the power up. This is so you can choose if you want to replace your current power up or keep the your current one. You can see the GPB in the image above.

All alien ships are effected by the GPB, but the closer the ships are to the GPB the stronger they’re pulled. To do this, the PBS iterates through all the alien ships. For each ship, the distance between the ships and the GPB are then calculated using the Pythagorean theorem (distance = ((x1 – x2)2 + (y1 – y2)2). The new position for the alien ships that frame is calculated by subtracting the position of the alien ships with the position of the GPB, then normalizing it ( {x/distance, y/distance} ), then multiply it by how far it should move that frame, which is calculated by using a large constant and subtracting that constant with the distance, and then multiply it by the delta time and a speed constant. If that all results in a number less than zero, then there’s no additional movement to be applied to the alien ships. If it was allowed to be less than zero, then far away ships would move away from the GPB. Both the pull effect and the alien ships’ usual movement are applied each frame so that they continue to do their movement patterns while being pulled.

A fade-in and fade-out is applied to the GPB sprite while active. The GPB has a countdown for how long the exists. During the first half of the countdown it does 255 – ( 255 / 2.5 ) * (countdown – 2.5) to control its transparency. It’s 255 when it’s not at all transparent, and 0 when it is. The number 2.5 is half of the countdown. To make it disappear again, the following is done: ( 255 / 2.5 ) * (countdown – 2.5).

I think the outcome seems pretty good, but it could probably be improved more if we want to. It was a bit difficult to get the numbers right for it to be really good, but I think it turned out well.

Leave a comment