Main image of article Code Your Own 'Star Wars' Lightsaber
As part of its intensive promotion for the new “Star Wars” movie, Google just launched a browser game called “Lightsaber Escape.” At first glance, it’s very much a standard action title, tasking the player with escaping from a Star Destroyer filled with white-armored troopers. You can swipe at enemies with a lightsaber, controllable not with a mouse or joystick but the player’s real-life smartphone. According to Google’s corporate blog posting on the game’s development, syncing a smartphone with a PC browser took a lot of coding work. Developers used WebGL to render graphics within the browser, and WebRTC and WebSockets so mobile devices and PCs could communicate with a minimum of latency. Adding to the complexity of the effort: the game needed to work on different kinds of browsers without plugins. Those who want to take a look at Google’s code can head over to the company’s Developers page, which details how to set up a high-framerate WebGL project with Polymer. “Polymer is a library that allows a lot of power over how your project is built from reusable custom elements,” the page explains. “It allows you to use standalone, fully functional modules contained in a single HTML file. They contain not only the structure (HTML markup) but also inline styles and logic.” Google believes Polymer is powerful enough to build everything from a UX button to a full application, and the step-by-step breakdown of building “Lightsaber Escape” certainly backs that point. Whether you’re interested in gaming or hardware interactions, the walkthrough (complete with diagrams and code snippets) is well-worth the read; if you want to build your own lightsaber game, though, prepare for a good deal of sophisticated rendering and graphics work.