The Slippy Flippy Penguin Challenge: A Tutorial on Sprite Kit

I stuck my foot in my mouth.

I’m now chewing vigorously and that is why you are reading this.
Photo Mar 19, 9 52 47 AMFor those who never heard of Flappy Bird, it was the game sensation nobody expected. It was a game that was very simple: a little bird moves up if you tap the screen, and falls due to gravity if you don’t. The game play is also simple: fly between two pipes without touching them and get a point. If you touch the pies or the ground, the game ends. While that seems easy, game play is very difficult.
The programming world was outraged when this jumped into #1 slot in iTunes and the developer began making $50,000 a day, far more than much slicker games with intensely realistic graphics. Then suddenly, the author pulled it from the stores. There was controversy. Not only was it simple, the graphics used  went out of style before the Gameboy. How did such a cheap game added to the store almost a year ago suddenly have such a meteoric rise? Apple’s App Store and Google Play hunkered down for an invasion of clones to the now defunct Flappy Bird, (which since I first wrote this is being resurrected ) and the author now says he pulled it because it was so addictive.
I was explaining the Flappy Bird controversy to a Friend. I claimed I could, actually anyone could, write Flappy Bird in a week. My friend dared me to try, and so I had ended up with a week-long challenge — write a Flappy Bird clone in a week then get it into the App store, with a variation or two.
Thus Slippy Flippy Penguin was born. If it gets into the App Store is another thing.
I didn’t want to write a clone – I prefer originality, like the game I’ve been working months to finish and is still under development. Besides Apple throwing it into a garbage heap in a second with the rest of the cheap knockoffs of the originall, I want to teach how to write games and how to program. I’m an educator at heart. Apple also last year made game programming a lot easier by introducing Sprite Kit to Xcode, the suite of programs used to write apps for iPhone and iPad. So a bigger challenge looms — can anyone write not just a clone but any game similar within a week’s time? If you have a Mac and can load Xcode, you are certainly welcome to follow along and write your own game. If you don’t, you may learn something too about a lot of what goes on behind the touchscreen of your iPhone.
The game itself is simple, which is what makes it such a great educational tool, and I’m not the only one doing this.

So Let’s see how to do this one part at a time.

From Apple to Raspberry Pi: Look ma! No Braces!!

I recently found a Post on Google Plus from Codelect.net that only a programmer would love:

Of course this is an endless debate of where to put the braces of a block of code.  C, C++, Java, JavaScript, Objective-C and even CSS uses those lovely curly braces.

Python does something totally mind tripping to me: it doesn’t use them. Here’s the same if statement in Python:

if condition:
    Statements
    #a comment ...

In Python there is no braces:only white space. By convention there are four spaces. When there is no more indent, no more block.

Of course I do a lot of indentation in Xcode. But that is just documentation. In Python it’s syntax — and you can nest them too!

Another thing for me to swallow.

From Apple to Raspberry Pi: Variables and Types

RaspiI’m trying to learn Python for my new Raspberry Pi — though with all the app development I do that is not so easy. I need to wrap my head around some very different concepts.

The first concept that is obvious is the dynamic typing of Python. If you’ve used Objective-C or C, those are static typed languages. At compile time We set the variable  for life of the variable that type.   I’m used to writing in Objective C:

float number = firstNumber + secondNumber;
BOOL isThisTrue = 5 > 6;
NSInteger count = 0;

In Python that same declaration would be:

number = first_number + 1.23
is_this_true = 5>6
count = 0

It doesn’t matter if you want a integer, float, boolean or even string, that works. Also notice the lack of semicolon. There are no termination characters in Python like C, C++, or Objective C. Finally, the variable convention is underscores instead of capitalization.

While just missing a declaration is no big deal, in Python this is acceptable code:

number = first_number + 1.23
number = 5>6
number = 0
number = 'My number is 0'

The variable number  is successively a float, bool, integer and a string. For new programmers, this is probably is nothing to care about. For someone used to typing everything, it’s really annoying and took me a minute to get used to the difference.

In particular,  while coding I have to be very careful with the type I assign a variable.  Unlike Xcode giving us warnings about type there are no warning because everything is valid. This can lead to some unexpected bugs.

Fortunately, to prevent some of these there is casting. The functions int(x),float(x),bool(x) among others will cast to a type. There is also type checking. the type(x), and isInstance(object,classInfo) will also check classes and types.

Some people like dynamic typing, some don’t. When using Python, it is something that one will have to think about.

Going from Apple to Raspberry Pi

I got a new toy this week at work:  A Raspberry Pi.

Raspi

It’s a small computer the size of a mint tin that costs about $35. I comes just as a board, but I invested in a nice case for it. Instead of a hard drive you  use a SD card for storage of the operating system and you main drive.  My aim is to use it as a controller for other devices.  As you can see on the upper left of the board in the photo, there is a set of pins called the GPIO, (General Purpose Input/output) which you can connect directly to and control or sense stuff from. The programming language directly controls these pins. You can then programmatically  make the pins either input or output.

I got it up and running on Friday, and Monday I’ll start to do some stuff with it. However, the  primary programming language is far from Xcode. Instead, it’s Python.

Python is different. It’s dynamically typed so no declaring variables. It’s also interpreted, so no compiling and building. It’s also a lot more universal.  I even have it running on my iPad.

And looking at some books I bought on Python and Raspberry Pi, there is some things I need to wrap my head around between Raspberry Pi and Xcode.

I’ll post some of those this week.

 

Keeping things short.

I have a problem. I write too much. 

It’s not a new problem. In graduate school the words “This is not a dissertation” was found next to the grade on any paper I wrote.  While professors might dread reading 100 page papers, I usually ended up with A’s since I was immensely complete and still compact with my writing. My problem is  I plan big projects,  and want to finish the project before I present it.

I just finished Show Your Work!: 10 Ways to Share Your Creativity and Get Discovered by Austin Kleon and it got me thinking about this problem. Kleon’s Tip #3 was “share something small every day,” which I neither share small or everyday.  He points to my problem of not posting with this encouragement:

We’re all terrified of being revealed as amateurs, but in fact today it is the amateur the enthusiast who pursues her work in the spirit of love(in french the word means “lover”), regardless of the potential for fame, money, or career — who often has the advantage over the professional.

I write for grad school or a finished read-to publish book.  When I was writing Shlomo’s Drash in its heyday, it was almost always over 1100 words. It’s just a blog post.  Blogs are short, small sharings. If they are more human, even better.

So I’m giving myself a 300-word limit. but I will post content every day. I have two projects on the burners, and both are very easily posted here.

Time to start the adventure. Time to keep it going.

(Word count: 258)

 

The Making App Pie Tutorial: The Adventure Begins

I’ve been at Xcode and cocoa Touch for over a year. I’ve had over  1,400 downloads of my apps from the app store and learned a lot about programming in Xcode.

I’ve realized something during this time: Programming in OOP is not like programming in C or Basic. When you have a graphic environment like Xcode, with storyboards to help you, the entire game if different, and it’s more about the rules you unlearn than learn as a programmer.

So I asked myself a question: What if someone who knows enough to handle Microsoft Word  or Pages would be taught Xcode from the ground up?

So we begin an adventure the Making App Pie tutorials will be regularly posted tutorials on how to make apps for the iPhone at first , and eventually the iPad as well.

You will need the following to play along at home:

  • The latest version of Xcode
  • A Macintosh computer ( since Xcode only runs on a mac)
  • A Developer’s license. There are two varieties of these, the free one and the $99/yr one. The big difference is the paid license lets you put your apps on a real phone, the free one restricts you to the simulator. I strongly suggest getting the paid developer’s license, but it will be months before we will do anything the requires you to upload an app to a phone. You can begin the registration process here: https://developer.apple.com/register/index.action

What we will do over the course is create an adventure game. The idea of this game is to learn Xcode, not to write games. Those of you interested in productivity apps will learn the fundamentals for those types of apps as well. Some of the parts of this adventure will be components for many types of non-game apps. I’m just making a conceptual framework that will help everyone think correctly about Object Oriented Programming.

Hope you join me in a great adventure.

 

 

 

 

How to get a string with the Date and time in XCode / Cocoa Touch

There are times  you look for something simple, and get very frustrated. One of those for me was getting a freaking time stamp on my app.

After a bit of chasing around, I did find this in Apple’s documentation, in case you are looking for it.

// code to get the date and time  in a string.
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    NSDate *date = [NSDate date];
    NSString *formattedDateString = [dateFormatter stringFromDate:date];

Note there are other constant you can use besides NSDateMediumStyle.

Check out the NSDateFormatter Class Reference for the whole story

Adventures in Swift and iOS App Development