EasyManuals Logo

Arduino uno User Manual

Arduino uno
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 #135 background imageLoading...
Page #135 background image
First of all, it defines a constant named
MAX_LIVES
that contains the maximum
number of lives in the game. This is the place to go for cheaters. The
GameStates
map defines the games possible states. This is a very common pattern in
game programming, and youll see later how easy it is to write the games
main loop when you identify the game states properly.
The
Game
object defines all of the games properties, such as the current score,
the number of lives left, and the games current state. It also contains all
information about the games object, such as the balls current velocity in all
directions or the paddles speed. Of course, it also defines a
GameController
object, and you have to adjust the path to the Arduinos serial port.
Most of the
Game
objects are constants at the beginning; we set only the balls
velocity in the X direction to a random value. This way, the ball wont always
go into the same direction each time you start a new round.
Note that we use jQuery functions for the first time when we determine the
width and height of the game objects. Look at the following piece of code:
width: $("#paddle").width()
It looks cryptic at first, but it should be obvious that it somehow determines
the paddles width. Therefore, it uses jQuerys most important method. Its
name is
$
(yes, you can actually define a JavaScript function named
$
), and
its a versatile method you can use for various purposes.
The
$
function expects a single argument you can use to specify a certain
element in your current HTML page. To identify the element, you can use the
usual CSS selectors. In our case, wed like to get the element with the ID
paddle
, and in CSS you can look up elements specified by an ID by inserting
the
#
character before the ID.
After weve retrieved the element were looking for, we use jQuerys
width
method
to read its width. jQuery offers many more methods for accessing all possible
CSS attributes. Using these methods for getting and setting CSS attributes
is much easier than using JavaScripts native functions for looking up and
manipulating elements on the current HTML page.
Now that weve set up the games data structures, we can implement the
games main logic. We start by defining a few methods for initializing and
resetting the game.
BrowserGame/Arduinoid/js/arduinoid.js
function initGame() {
Line 1
Game.state = GameStates.PAUSED;
-
Game.lives = MAX_LIVES;
-
report erratum discuss
Creating the Game 117
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals