Finally, we import all the JavaScript code we need. The jQuery
very popular tool for creating dynamic web applications. It makes it very easy
to manipulate HTML elements, and it ll make our life much easier.
You already know the
is more interesting because it contains the actual game logic. It starts with
the definition of a few data structures holding the game s most important
status information:
BrowserGame/Arduinoid/js/arduinoid.js
const
MAX_LIVES = 5;
var
GameStates = {
RUNNING: 'running',
PAUSED: 'paused',
LOST: 'lost',
WON:
'won'
}
var
Game = {
lives: MAX_LIVES,
score: 0,
state: GameStates.PAUSED,
paddle: {
speed: 15,
width: $("#paddle").width(),
height: $("#paddle").height()
},
playfield: {
width: $("#playfield").width(),
height: $("#playfield").height(),
rows: 4,
columns: 10
},
ball: {
diameter: $("#ball").width(),
vx: 5 + Math.random() * 5,
vy: -10
},
controller:
new
GameController('/dev/tty.usbmodem24321')
}
5.
http://jquery.com/
Chapter 7. Writing a Game for the Motion-Sensing Game Controller
serial_device.js
and
game_controller.js
www.it-ebooks.info
116
5
library is a
files. The
arduinoid.js
file
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?