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 #138 background imageLoading...
Page #138 background image
function handleMessageState(message) {
$("#" + message).show();
if (Game.controller.buttonPressed) {
$("#" + message).hide();
initGame();
}
}
The
gameLoop
function is surprisingly simple, because it only checks the games
current state and then delegates its work accordingly. If the game is paused
currently, it checks whether the player has pressed the game controllers
button. If yes, it changes the games state to
GameStates.RUNNING
.
If the game is running already,
gameLoop
moves all game objects, checks for
potential collisions, and updates the games statistics. If the game was won
or lost, it calls
handleMessageState
to display a corresponding message.
handleMessageState
displays a message by manipulating an HTML elements
content. It also checks whether the game controllers button was pressed. If
yes, it hides the message and initializes the game so the player can start a
new round. After a player has won or lost a game, he or she can start a new
game by pressing the button on the game controller.
Moving the objects on the screen is the most important part in many video
games. Thanks to jQuery, its not that difficult.
BrowserGame/Arduinoid/js/arduinoid.js
function moveBall() {
Line 1
var ball_pos = $("#ball").position();
-
var ball_x = ball_pos.left;
-
var ball_y = ball_pos.top;
-
var next_x_pos = ball_x + Game.ball.vx;
5
var next_y_pos = ball_y + Game.ball.vy;
-
-
if (next_x_pos <= 0) {
-
Game.ball.vx *= -1;
-
next_x_pos = 1;
10
} else if (next_x_pos >= Game.playfield.width - Game.ball.diameter) {
-
Game.ball.vx *= -1;
-
next_x_pos = Game.playfield.width - Game.ball.diameter - 1;
-
}
-
15
var paddle_y = $("#paddle").position().top;
-
if (next_y_pos <= 0) {
-
Game.ball.vy *= -1;
-
next_y_pos = 1;
-
} else if (next_y_pos + Game.ball.diameter >= paddle_y) {
20
var paddle_x = $("#paddle").position().left;
-
Chapter 7. Writing a Game for the Motion-Sensing Game Controller 120
report erratum discuss
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