EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #134 background imageLoading...
Page #134 background image
Finally, we import all the JavaScript code we need. The jQuery
5
library is a
very popular tool for creating dynamic web applications. It makes it very easy
to manipulate HTML elements, and itll make our life much easier.
You already know the
serial_device.js
and
game_controller.js
files. The
arduinoid.js
file
is more interesting because it contains the actual game logic. It starts with
the definition of a few data structures holding the games 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 116
report erratum discuss
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino Pro Mini and is the answer not in the manual?

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals