Game Center Source Code: multiplayer Pong client

Discussion in 'Public Game Developers Forum' started by Menneisyys, Nov 6, 2010.

  1. Menneisyys

    Menneisyys Well-Known Member

    Dec 12, 2008
    1,594
    0
    0
    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.
     
  2. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    Thanks for sharing this. Open source makes the world go round. :)
     
  3. Zincous

    Zincous Well-Known Member

    Dec 23, 2008
    4,567
    0
    0
    Sacramento, CA
    Yes please do.
     
  4. gammabeam

    gammabeam Well-Known Member

    Wow this is so nice!
    Great initiative! ;)

    Hope you find the time to post that tutorial!
     
  5. Deth4U2

    Deth4U2 Well-Known Member

    Aug 19, 2009
    116
    0
    0
    Wow, thanks for this! Can't wait to check out your example. :)
     
  6. Sinecure Industries

    Sinecure Industries Well-Known Member

    That's really cool! Thanks for sharing!
     
  7. Menneisyys

    Menneisyys Well-Known Member

    Dec 12, 2008
    1,594
    0
    0
    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.
     
  8. simplymuzik3

    simplymuzik3 Well-Known Member

    Aug 12, 2009
    342
    0
    0
    Can't wait for the full tutorial! Great work with this :) Really appreciate it!
     
  9. lazypeon

    lazypeon Well-Known Member

    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.
     
  10. Voley

    Voley Well-Known Member

    Aug 23, 2010
    58
    0
    0
    It refuses to compile for me - says Base SDK missing, tho I tried picking iOS in project settings, still won't help
     
  11. HandheldGames

    HandheldGames Well-Known Member

    Nov 15, 2008
    307
    0
    0
    CEO & Founder, Creative Director, Producer, & Desi
    Lynnwood, Washington
    sounds like you forgot to configure your active target.
     
  12. kahanejosh

    kahanejosh Well-Known Member

    Mar 10, 2009
    154
    0
    0
    Student - Game Developer
    England, UK
    Would be great to see a sample of it working across views, say a main menu witch moves to a multiplayer view with invites and making use of the GKMatchmakerViewController.
     
  13. YOMANx

    YOMANx Well-Known Member

    Nov 18, 2009
    500
    2
    18
    Game Developer
    #13 YOMANx, Jan 10, 2011
    Last edited: Jan 10, 2011
    Thanksssssssssss for the sourceeeeeee code!!!!!!!!!!!

    GC:
    ps why my ipad with i os 4.2 say: this game is not recognized by Game center and then game closes
    and my ipod 2g with i os 4.2 load game center and then game closes too
     
  14. mr.Ugly

    mr.Ugly Well-Known Member

    Dec 1, 2009
    1,675
    0
    36
    Berlin, Germany

    you need to update the source to point your own gc setting i assume.. at least the bundle identifier should be changed.. and you need to logo into gc with your test account..

    maybee i forgot something..
     
  15. YOMANx

    YOMANx Well-Known Member

    Nov 18, 2009
    500
    2
    18
    Game Developer
    thanks, works:)
     
  16. YOMANx

    YOMANx Well-Known Member

    Nov 18, 2009
    500
    2
    18
    Game Developer
    #16 YOMANx, Jan 11, 2011
    Last edited: Jan 11, 2011
    thanks for the code, very helpful
     
  17. cgencer

    cgencer New Member

    Jan 12, 2011
    1
    0
    0
    its really a nice gift from you, to share your source code, which probably can help a few coders like me... thanks a lot... will digg into it now.
     
  18. Menneisyys

    Menneisyys Well-Known Member

    Dec 12, 2008
    1,594
    0
    0
    Thank you all :)

    Unfortunately, I still haven't had the time to write a complete tutorial. I've been given the task to learn Samsung bada programming for future lectures and other bada work and I've spent all my time doing so...
     
  19. simfrontier

    simfrontier Well-Known Member

    Jan 7, 2010
    179
    0
    0
    Thanks for the great tutorial.
    How about the game center speed in real time multi-player game?
    For example is the bandwidth enough for a car racing game?
    Can they be implemented by game center,
    without any 3rd party dedicate server?
     
  20. Menneisyys

    Menneisyys Well-Known Member

    Dec 12, 2008
    1,594
    0
    0
    I was positively suprised by how fast and lag-less communication over GC was - actually, I had much better results most of the time as through local(!) GameKit Bluetooth.

    Also, most current car racer games (e.g., Real Racing) also solely use GC for multiplayer.
     

Share This Page