Support our Sponsors:

Go Back   Touch Arcade > Developer Discussion > Public Game Developers Forum

Reply
 
Thread Tools Display Modes
  #1  
Old 11-06-2010, 04:22 PM
Menneisyys Menneisyys is offline
Senior Member
 
Join Date: Dec 2008
Posts: 1,594
Default Game Center Source Code: multiplayer Pong client

As some of you may know, I, among other things, also lecture on iOS programming. Due to the request of my students, I've spent some days on discovering the secrets of Game Center, which has been added to iOS in version 4.1 and is, consequently, pretty new and, apart from Apple's own documentation, very scarcely documented, let alone stand-alone, full demo application sources, of which I only know of GCPing, which is, for some reason, pretty much buried in the Apple developer forums. (I don't provide a link to GCPing because I don't know whether the developer wants to keep it pretty much private. Now that there's no NDA over Game Center any more, he may want to publish it to the public.)

First, the sources. They're here:
http://www.winmobiletech.com/sekalaiset/Pong.zip

The contents of the ZIP file are ordered in three directories in the root: Local, GameKit and GC. All versions support, from ground up, all screen confgurations and are Universal. (The latter is needed if you want to play multiplayer games over Game Center between an iPhone and an iPad.) Apart from the four-player GC version, all remote capable games support coordinate transformation and rescaling between the iPhone (iPod Touch; of course, also ones with the Retina screen) and the iPad. The only exception is the 4-player GC versions, where I didn't want to bother with implementing this to keep the code (relatively) small and clean.

The more advanced GC-capable versions also support voice transfer. There are two of them: "v3-4playersPlusAudio" only has a broadcast mode (everyone-to-everyone), while the most advanced one, "v4-UtilityApp", also supports private channels on top of the public (broadcast) one. You can set the target of your private channel in the flip view (by tapping the info icon) and can, after this, quickly switch between the two channels by using the newly introdued UISwitch in the gaming screen. If you do establish a private channel, make sure you tell the passive target of the channel to also select the other party so that his/her voice also gets thorugh the channel.

The local version allows for 1, 2 and 4 players. I've "only" written these versions to demonstrate how easy it is to write a local multiplayer Pong under iOS. The one-player version has a slightly more advanced version, "1player-with shift", which allows for handling offset in controlling the paddle. As it makes the paddle coordinate computation considerably less easy to read (particularly with two or four remote players, particularly when the iPad and iPhone screen size difference must also be taken into account), I haven't implemented this in other versions. Also note that the skew computation is very simple: based on the distance between the center point of the pad and the ball, I simply add a computed movement x (with vertical paddles, y) offset to the original one. A somewhat more dedicate algorithm would have been needed to avoid the ball gradually speeding up.

The GameKit version only supports two players and nothing fancy, except for rescaling when an iPad and an iPhone plays each other. The latter is also supported in the two-player GC version, but, to keep the code readable, not in the 4-player one.

Note that I use GC auto-mathcing as I will only later teach GC achievements/invites/leaderboards etc.

Have fun with the sources and let me know if you'd like to see a full step-by-step tutorial much easier to digest than Apple's own documentation on all these questions. When I have some free time (highly unlikely before 22/Nov), I will definitely publish one.
Reply With Quote
  #2  
Old 11-07-2010, 02:05 AM
kohjingyu's Avatar
kohjingyu kohjingyu is offline
Developer
iPhone 4, iOS 6.x
 
Join Date: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Default

Thanks for sharing this. Open source makes the world go round.
Reply With Quote
  #3  
Old 11-07-2010, 02:59 AM
Zincous's Avatar
Zincous Zincous is offline
Senior Member
iPhone 6 Plus, iOS 8.x
 
Join Date: Dec 2008
Location: Sacramento, CA
Posts: 4,569
Default

Quote:
Originally Posted by Menneisyys View Post
Note that I use GC auto-mathcing as I will only later teach GC achievements/invites/leaderboards etc.

Have fun with the sources and let me know if you'd like to see a full step-by-step tutorial much easier to digest than Apple's own documentation on all these questions. When I have some free time (highly unlikely before 22/Nov), I will definitely publish one.
Yes please do.
Reply With Quote
  #4  
Old 11-08-2010, 08:03 AM
gammabeam gammabeam is offline
Senior Member
iPod Touch (3rd Gen), OS 4.x
 
Join Date: Aug 2010
Posts: 207
Default

Wow this is so nice!
Great initiative!

Hope you find the time to post that tutorial!
Reply With Quote
  #5  
Old 11-10-2010, 02:07 PM
Deth4U2 Deth4U2 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 113
Default

Wow, thanks for this! Can't wait to check out your example.
Reply With Quote
  #6  
Old 11-11-2010, 09:05 AM
Sinecure Industries's Avatar
Sinecure Industries Sinecure Industries is offline
Senior Member
iPhone 4
 
Join Date: Oct 2009
Location: NJ
Posts: 603
Default

That's really cool! Thanks for sharing!
Reply With Quote
  #7  
Old 11-15-2010, 07:21 AM
Menneisyys Menneisyys is offline
Senior Member
 
Join Date: Dec 2008
Posts: 1,594
Default

Glad you liked it My this year's last lecture is on Thursday / Friday this week; after that, at last, I'll have some free time to publish the full tutorial. In the meantime, feel free to play with the sources - they all work and are pretty clean.
Reply With Quote
  #8  
Old 11-15-2010, 08:34 AM
simplymuzik3 simplymuzik3 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 341
Default

Can't wait for the full tutorial! Great work with this Really appreciate it!
Reply With Quote
  #9  
Old 11-26-2010, 01:38 AM
lazypeon's Avatar
lazypeon lazypeon is offline
Senior Member
iPhone 4, iOS 6.x
 
Join Date: Feb 2009
Location: San Jose, CA
Posts: 543
Default

Very interested, I'll have to try the source. I'd really like to do a game with multiplayer. One point of resistance for me has been the need for a central server, though I suppose this isn't necessary. With Game Center, do you simply use GC to help two clients find each other, than just talk directly to one another, without a central server?

I've always been curious about sync issues for multiplayer games, but I suppose that's a more general networking question.
Reply With Quote
  #10  
Old 11-26-2010, 04:42 AM
Voley Voley is offline
Member
iPhone 3GS, OS 4.x
 
Join Date: Aug 2010
Posts: 51
Default

It refuses to compile for me - says Base SDK missing, tho I tried picking iOS in project settings, still won't help
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Copyright 2012, TouchArcade.com, LLC.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Copyright 2008 - 2011, TouchArcade.com. Privacy Policy / DMCA Copyright Agent