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 #141 background imageLoading...
Page #141 background image
-
function checkBlockCollision() {
-
var block_width = $(".block").first().width();
-
var block_height = $(".block").first().height();
-
var ball_left = $("#ball").position().left;
35
var ball_top = $("#ball").position().top;
-
var blocks_left = false;
-
$(".block").each(function() {
-
if ($(this).css("visibility") == "visible") {
-
blocks_left = true;
40
var block_top = $(this).position().top;
-
var block_left = $(this).position().left;
-
var in_x = inXRange(ball_left, block_left, block_width);
-
var in_y = inYRange(ball_top, block_top, block_height);
-
if (in_x && in_y) {
45
Game.score += 10;
-
$(this).css("visibility", "hidden");
-
if (in_x) {
-
Game.ball.vy *= -1;
-
}
50
if (in_y) {
-
Game.ball.vx *= -1;
-
}
-
}
-
}
55
});
-
return blocks_left;
-
}
-
The
checkCollisions
function first checks whether the player has dropped the
ball. In this case we decrease the number of lives. Then we check whether
the player has lost all of his lives. If yes, we set the games state to
GameS-
tates.LOST
. Otherwise, we pause the game and set the ball and paddle positions
to their defaults.
ballDropped
compares the y-coordinate of the balls bottom with the y-coordinate
of the paddles bottom. If the balls bottom is greater, the ball has been
dropped.
Next we define two helper functions named
inXRange
and
inYRange
. They check
whether the ball overlaps with a block horizontally or vertically. We use these
functions in
checkBlockCollision
to see whether any visible block has been hit by
the ball.
Therefore, we need a few more jQuery methods. In line 33, we select all ele-
ments belonging to the class
block
using
$(".block")
. If you pass a selector to the
$
function that selects more than one element, the function automatically
returns a list of objects. We select the first object using the
first
method; then
report erratum discuss
Creating the Game 123
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