{"id":283,"date":"2008-11-07T23:24:04","date_gmt":"2008-11-07T22:24:04","guid":{"rendered":"http:\/\/t-machine.org\/?p=283"},"modified":"2008-11-07T23:24:04","modified_gmt":"2008-11-07T22:24:04","slug":"tilt-sensitive-game-using-macbook-macbook-air","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2008\/11\/07\/tilt-sensitive-game-using-macbook-macbook-air\/","title":{"rendered":"Tilt-sensitive game using Macbook \/ Macbook Air"},"content":{"rendered":"<p>This is a tiny game we made more than 2 years ago as part of <a href=\"http:\/\/perplexcity.com\">Perplex City<\/a>. Many people are unaware that the tilt-sensors inside the iPhone are also available (or something very similar) inside every apple laptop (all Macbooks\/most Powerbooks\/some iBooks); we made a game that made use of this.<\/p>\n<p>Unfortunately, this feature of the laptops is undocumented, and so Apple has changed the specs a few times, so the original files no longer work. With a small bit of mangling, I&#8217;ve fixed the very simple input script, and it all works fine on my Macbook Air.<\/p>\n<p>Links:<\/p>\n<ul>\n<li>Info on <a href=\"http:\/\/perplexcitywiki.com\/wiki\/Pietros_maze\">how this tiny minigame fitted-in to the overall Perplex City<\/a> game\n<li>(mirror of) The <a href=\"http:\/\/wayback.perplexcitystories.com\/?url=www.salkfamily.com&#038;season=1\">original in-game website that holds the original download files<\/a> (note: Mindcandy is hosting this for now, but I don&#8217;t know for how much longer they&#8217;ll keep this stuff up)\n<li><a href=\"http:\/\/www.osxbook.com\/software\/sms\/amstracker\/download\/AMSTracker-0.34.dmg\">UPDATED version (0.34) of the hardware driver that you need<\/a> on Macbook \/ Macbook Air to make this work (current homepage for that software is <a href=\"http:\/\/www.osxbook.com\/software\/sms\/amstracker\/\">here<\/a>)\n<\/ul>\n<p>Instructions:<\/p>\n<ol>\n<li>Download the file &#8220;maze-inertial.zip&#8221; from the second link above, and unzip it\n<li>Download the AMStracker dmg from the third link above, and open it, and put all the contents in the Maze subdirectory of wherever you just unzipped to; it will want to overwrite a file &#8211; say &#8220;yes&#8221;\n<li>Make a new file in that directory using a text editor, call it e.g. &#8220;start.pl&#8221;, and copy\/paste the lines below (bottom of this post)\n<li>Run the file start.pl; you might be able to double click on it, you might have to go to the directory in Terminal and type &#8220;.\/start.pl&#8221; to make it run\n<li>Wait for the java app to load, you should see a ball on a chequered background\n<li>Pick up your laptop and start tilting it to make the ball roll around\n<li>NB: the lack of graphics was deliberate! the idea was to close your laptop lid and play just using the sound (this requires you to disable OS X&#8217;s auto-suspend feature though)\n<li>You will get cryptic messages as you complete levels; there are hundreds of levels, and no save feature (!). Read the website links above to find out why&#8230;\n<\/ol>\n<p>PS: if you read the source and think &#8220;ugh, what a brutal and inelegant way to make this work&#8221; then congratulations &#8211; this whole game was done start to finish in something like 2 weeks (part-time; if we&#8217;d all been working full-time on it it was probably more like 4 days). We had to cut a lot of corners&#8230;<\/p>\n<p>Source of file start.pl &#8211; copy\/paste everything below this line<\/p>\n<blockquote><p>\n#!\/usr\/bin\/perl -w<\/p>\n<p>use IO::Socket::INET;<br \/>\nuse Getopt::Long;<\/p>\n<p>$| = 1;<\/p>\n<p>my $flipx = 0;my $flipy = 0;my $port = 5399;my $ams = &#8220;.\/amstracker&#8221;;my $maze = &#8220;.\/maze.jar&#8221;;my $scale = 5;<\/p>\n<p>GetOptions(&#8220;flipx&#8221; => \\$flipx,      # &#8211;flipx                   flip x axis<br \/>\n           &#8220;flipy&#8221; => \\$flipy,      # &#8211;flipy                   flip y axis<br \/>\n           &#8220;port=i&#8221; => \\$port,      # &#8211;port 5399               port to talk to<br \/>\n           &#8220;ams=s&#8221; => \\$ams,        # &#8211;ams .\/amstracker        location of amstracker<br \/>\n           &#8220;maze=s&#8221; => \\$maze,      # &#8211;maze .\/tiltmaze.jar     location of tiltmaze.jar<br \/>\n           &#8220;scale=f&#8221; => \\$scale);   # &#8211;scale 3.0               tilt scaling factor<\/p>\n<p># Needs AMStracker v0.34 or above, currently at:<br \/>\n# http:\/\/www.osxbook.com\/software\/sms\/amstracker\/<\/p>\n<p>print STDERR &#8220;Starting amstracker ($ams)&#8230;\\n&#8221;;<br \/>\nopen AMS, &#8220;$ams -s -u 0.1 |&#8221; or die &#8220;Can&#8217;t start amstracker: $!&#8221;;<br \/>\nmy $line = <AMS>;<br \/>\nprint &#8220;$line&#8221;;<\/p>\n<p>if ($line =~ \/software\/) {print STDERR &#8220;No tilt sensor found.\\n&#8221;;exit 1;}<\/p>\n<p>print STDERR &#8220;Starting maze ($maze)&#8230;\\n&#8221;;<br \/>\nsystem &#8220;open $maze&#8221;;<\/p>\n<p>print STDERR &#8220;Connecting to game&#8230;&#8221;;<br \/>\nmy $sock;my $count = 0;<\/p>\n<p>while (1){<br \/>\n    $sock =  IO::Socket::INET->new(PeerAddr => &#8216;localhost&#8217;,PeerPort => $port,Proto => &#8216;tcp&#8217;);<br \/>\n    last if defined $sock; # success!<br \/>\n    $count++;<br \/>\n    if ($count > 20){die &#8220;Can&#8217;t connect to game: $!&#8221;; }<br \/>\n    print &#8220;.&#8221;;sleep 2;}<br \/>\nprint &#8220;\\n&#8221;;<\/p>\n<p>while (<AMS>) {<br \/>\n    my ($x,$y,$z) = split;<br \/>\n    next unless $x =~ \/\\d+\/;<br \/>\n    $x = -$x unless $flipx; $z = -$z if $flipy; $x = int($x * $scale); $z = int($z * $scale);<br \/>\n    last unless $sock->print(&#8220;[$x,$z]&#8221;); }\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This is a tiny game we made more than 2 years ago as part of Perplex City. Many people are unaware that the tilt-sensors inside the iPhone are also available (or something very similar) inside every apple laptop (all Macbooks\/most Powerbooks\/some iBooks); we made a game that made use of this. Unfortunately, this feature of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/283"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}