Sunday, 5 May 2013

An Update

OK, so a lot has happened since I last posted here.

The game is now officially named Light Defender, because I didn't like referring to it as 'the game'. Some screenshots of the game as it was a few weeks ago can be found here.

One of my friends volunteered to create art for the game, motivating me to continue with the project. I have made a subreddit (/r/lightdefender) to post news and updates, whereas this blog and my twitter account will be used to post about development.

If you download the latest version (v0.1.1), you will notice that it is very different from the roller coaster ride from which it was created! The affect of gravity on the rider was one of the first challenges I faced, and was one of the easiest as it turns out, because I didn't need to worry about how it would fit into the rest of the game in terms of code. I essentially just calculated the amount the gravity was affecting the rider in terms of acceleration and changed the velocity based on that value:

    def updatePos(self, FPS, surface, enemy, shots, powerup, enemyBullets):
        global lineColor
       
        angle = math.atan(factors[self.posInt])
        Acc = 15*math.sin(angle) + 1.5 - self.nitro
        self.v += -Acc*5/FPS
       
        #Acceleration changes are mostly arbitrary
       
        if self.v < 20:
            self.v = 20
           
           
        distanceTraveled = 2*(self.v)/FPS
       
        self.pos += distanceTraveled*math.cos(angle)
        self.posInt = int(self.pos)
   

I have pointed out in the code itself that the changes I make to the acceleration value are there to increase the affect on the rider. If I do not increase that value, the rider will only accelerate by 9.8 pixels/second.

The code I have written so far is a bit messy, mainly because of my irrational fear of global variables, something which I will amend later. 

Another interesting code snippet is for the rotating triangles that the enemy UFOs shoot:

    s = []
                realS = []
                for j in shape:
                    # Rotates the bullets using (the equivalent of) matrix rotation
                    s.append(((j[0]*math.cos(r))+(j[1]*-math.sin(r)),(j[0]*math.sin(r))+(j[1]*math.cos(r))))
                    #Adds x and y
                    realS.append(((j[0]*math.cos(r))+(j[1]*-math.sin(r))+x,(j[0]*math.sin(r))+(j[1]*math.cos(r))+y))
               
                shape = (s[0],s[1],s[2])


The code handles the shape relative to it's center and the shape relative to the screen differently because I have used a rotation matrix to move the shape. It is easier to make them separate rather than rotation around the current x,y position of the shape which would require further calculation.

That's it for now. This blog is probably not very readable or interesting at the moment, so for the next post I will try to make it more about the game design choices I am currently making rather than the techincal aspects, all of which I am sure have been documented in a better way before.

Thanks for reading,

Oscar