DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Auditing Tools for Kubernetes
  • The SPACE Framework for Developer Productivity

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Auditing Tools for Kubernetes
  • The SPACE Framework for Developer Productivity
  1. DZone
  2. Data Engineering
  3. Data
  4. Blast Aliens in Your Browser with Your iOS Trigger Device

Blast Aliens in Your Browser with Your iOS Trigger Device

Chris Smith user avatar by
Chris Smith
·
Mar. 21, 12 · Interview
Like (2)
Save
Tweet
Share
16.35K Views

Join the DZone community and get the full member experience.

Join For Free
The guys over at WebDigi, a London-based web application development company, has released a demo of Space Invaders Spaceship Pilot, a pretty amazing application that uses iOS devices as the controller for a web browser-based game on your desktop or laptop.  No application is required on the iOS device, you simply scan the QR code with the device and the controller code reads the accelerometer values and sends the movements to the node.js server.

WARNING: This demo may cause a significant decrease in productivity around the workspace, as it almost did here at DZone.




Here are the key parts of the iOS device controller code:
//Detect if the browser supports DeviceMotionEvent
if (window.DeviceMotionEvent != undefined) {
//ondevicemotion is fired when iOS device detects motion
  window.ondevicemotion = function(e) {
//ax is the movement on the x axis.
//This motion is used to move the ship in the game
  ax = event.accelerationIncludingGravity.x * 5;
  ay = event.accelerationIncludingGravity.y * 5;
 
//Status 0 is start, 1 is left, 2 is right, 3 is stay
if(status == 0){ //initial condition
  status = 3; //stay
  socket.emit('spaceChange', {'ax': 3});
  statusmsg = 'Waiting for movement';
}
if(ax > 14 && status != 2){ //move right on device
  status = 2;
  socket.emit('spaceChange', {'ax': 2});
  statusmsg = 'Moving ship right';
}
if(ax < -14 && status != 1){ //move left on device
  status = 1;
  socket.emit('spaceChange', {'ax': 1});
  statusmsg = 'Moving ship left';
}
if(ax > -14 && ax < 14 && status != 3){ //device held steady
  status = 3;
  socket.emit('spaceChange', {'ax': 3});
  statusmsg = 'Ship held steady';
}

Only changes in direction on the iOS device are pushed to the node.js server, reducing the amount of data pushed between phone and server.  The node.js server is coupled with Socket.IO, making it easier to deliver data in realtime using most web browsers.  Since Socket.IO code is run on both the server and client sides, pairing it with node.js allows accelerometer values to be pushed instantly from mobile safari to your browser.

After testing (read: playing) the demo for a few minutes, I couldn't help but be impressed with the speed at which the accelerometer data was sent to the browser.  As pointed out on the WebDigi Blog:

Current space invaders game uses only X axis movement on the iOS device.  However, all three dimension values are available on iOS Safari ondevicemotion method.  It is technically possible to do much more with the iOS device.

-- webdigi

So if you have an iOS device, and you miss playing Space Invaders, be sure to give this demo a try.

Also, special thanks to Roshan Abraham (DZone username: rabraham) for sending us a link to this information.  If you know of any cool demos, useful tips, etc. be sure to submit them to DZone using this button:



which is located near the top of each page.

Aliens (novel series) BLAST (protocol) mobile app Node.js Browser-based Web application QR code Data (computing) Space (architecture)

Opinions expressed by DZone contributors are their own.

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Auditing Tools for Kubernetes
  • The SPACE Framework for Developer Productivity

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: