First

So. . .most of the introductory stuff that I might put in a first blog post is already over on the info page.  All my interests and what I do and what I'm going to blog about are all over there.  With that out of the way, let's dive in.

I figured I'd start off with the development progress I've made towards the new game we are working on.  If you don't know, the game is basically going to be a tower defense game with two kinds of game play.  The player will be able to build towers with upgrade paths and all the usual tower defense game stuff, but in addition to that, you'll be able to change to the point of view of a tower and shoot the on coming enemies one at a time, man to man, sort of like a 1st person shooter tower defense game.  The player takes control of a tower by holding the device in a portrait orientation and when they do, they are able to scan the horizon by sweeping the device from left to right, almost like taking a panoramic picture.  Except instead of taking a picture you're looking for enemies to kill.

My job was to basically do that.  Access the gyro readings from the phone and make them move the background.  At first I thought this was going to be a kind of daunting task because the gyro values would have to be integrated to get the position and nobody likes integration.  But upon further research I found that in the CoreMotion framework there is already attitude values, yay!  What that means is that Apple has already done the hard part for you and integrated the three gyros to give you a position vector in three space defined by  roll, pitch, and yaw values in radians.  For the purposes of sweeping the background all I was interested in were the yaw values.  So with a little (a lot) of help from stack overflow I built a gyro object which would give the yaw values at a variable time interval.  Then, after realizing that the values were pretty noisy I put in a low pass filter to help smooth out the readings.  Now it was time to go back to Cocos2D.

The last part of this was pretty simple.  I had an angle value of how far off center I was.  So then I assumed that the background was going to sweep a total of say 90 degrees.  Then, knowing the total horizontal pixels in the background image I could divide by 90 and get a pixel per degree scalar.  Then I just had to multiply by the angle given by the gyro and poof, I had a number of pixels to move my image to.  Then there was some fiddling with coordinate systems and switching some signs but in the end I got it all working pretty well. 

There are some minor issues that may need to get worked out later on down the road but for now I'm happy with what I've got.  The next step now is to paste the enemies and the background in one layer so that when you sweep the device you not only change the background position but also the enemies lateral position so that it's in the view of the screen.  I want to talk to Austin about how that's going to happen since it has a large impact on how the rest of the game is going to be coded. 

So yeah.  That's my first blog post.  Longer than I was expecting and a lot of words.  I'll try to keep things more interesting with pictures and videos and stuff.  I hope this gave you and idea of the game we're working on and what kind of progress we've made so far.  My next post will probably be about the quadcopter.  That one will probably be kind of mathy as well, but I'll try and add a video to keep it interesting.  

Thanks for reading! 

-Matt.