Rohaizan Roosley
Posted on June 8, 2018
Hello everyone. This is my first post. So, please bear with me. Here’s a story of how I made a game and published it on Apple store.
TL;DR
Gyro Snake App store
Source code on Github
It started a year back when I was looking for something to publish on the App Store. In the beginning, I got this idea of tracking monthly expenses and make use of the Floating Action Button(FAB) to memorize the most frequent type of expenses. At that time, I was playing around with Swift and started to research on how to do the FAB on Swift. Back then, I have no knowledge of hybrid frameworks to build a mobile app, somehow one of the StackOverflow answers got me looking into the Apple SpriteKit.
It was a new thing for me. A game engine with build in physics and all the other cool stuff. Then it led me to a Youtube video on how to make a simple Pong game. I successfully followed the tutorial, and I thought it would be cool if I could control the ball using the Gyroscope. At this time, I have already scrapped the original idea of making a money tracker and decided to make a crazy snakelike game.
ORIGIN
The idea of this game originated from the game that was famous among those in the elder generation. In the process of creating this game, I reminisced the times when I used to play this game all day. By recreating the game so that it could be played only by tilting your smartphones, it would most likely attract many to play.
THE LOGIC
The logic behind it was actually really simple. I created Snake object that is having a subobject of type head and body which resides in an array. Remember the Pong game I mentioned earlier? Yes, I made it become the snakehead. Since the movement of the head is already controlled by the Gyroscope, so, therefore, that part is done. The body will move according to its predecessor object that was in the array [n-1], and it will give a snake-like movement when you tilt the phone. Each time the snake hits an apple, a new snake-body is pushed to the array. Thus, when more snake-body is pushed to the array, it gets more and more challenging to control the snake.
If you have been reading up until here, you are in luck. Here is the link to the Promo Code.
THE HARDEST PART
The hardest part of developing this game I guess was to make the snakehead look to the direction it was going. Luckily, I found an algorithm to do that by using this code below.
action1 = SKAction.moveTo(x: destX, duration: snake.snakeSpeed)
action2 = SKAction.moveTo(y: destY, duration: snake.snakeSpeed)
v1 = CGVector(dx:0, dy:1)
v2 = CGVector(dx:destX - snake.snakeHead.position.x, dy: destY - snake.snakeHead.position.y)
angle = atan2(v2.dy, v2.dx) - atan2(v1.dy, v1.dx)
body.zRotation = angle
body.run(action1)
body.run(action2)
GRAPHICS
Well, I’m not a graphics expert, so I just salvage anything I found in Google Image that has something to do with a green snake. With a few GIMP tricks, I successfully made it.
SOUND FX - THIS PART WAS FUN
I decided to give the old 8-bit SoundFX to the game and that was my Youtube keyword. I found a lot of samples. You can see it here. To download the sounds from Youtube, I’m not sure this is legal or not, I used a little tool called youtube-dl.
IT'S NOT ABOUT THE MONEY
I hope that you have enjoyed reading this. Up until today, no one has ever mastered the game and made it to the final level. Let me know if you can get to level 21. :)
Posted on June 8, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
April 2, 2020