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 #140 background imageLoading...
Page #140 background image
Eventually, we set the balls position to the new values in line 30.
Moving the paddle is similar, but it depends on the current state of the game
controller. If the player wants the paddle to move left, we subtract the paddles
current speed from the paddles x-coordinate. We also make sure that the
paddle doesnt leave the screen. Movement to the right works nearly the same.
We only have to add the paddles current speed.
A difficult problem in video games is collision detection. Youve probably
played a game or two and yelled No, that thing didnt hit me! or Im sure I
killed that alien first! In most cases inexact collision detection is the cause
of your frustration.
Even for our simple game, exact collision detections arent easy. The blocks
have rounded corners, so checking whether the ball overlaps one of the corners
or has actually touched the block isnt trivial. For a good game experience
this isnt necessary, so Ive simplified the collision detection.
BrowserGame/Arduinoid/js/arduinoid.js
function checkCollisions() {
Line 1
if (ballDropped()) {
-
Game.lives = Game.lives - 1;
-
if (Game.lives == 0) {
-
Game.state = GameStates.LOST;
5
} else {
-
Game.state = GameStates.PAUSED;
-
resetMovingObjects();
-
}
-
}
10
if (!checkBlockCollision()) {
-
Game.state = GameStates.WON;
-
}
-
}
-
15
function ballDropped() {
-
var ball_y = $("#ball").position().top;
-
var paddle_y = $("#paddle").position().top;
-
return ball_y + Game.ball.diameter > paddle_y + Game.paddle.height;
-
}
20
-
function inXRange(ball_left, block_left, block_width) {
-
return (ball_left + Game.ball.diameter >= block_left) &&
-
(ball_left <= block_left + block_width);
-
}
25
-
function inYRange(ball_top, block_top, block_height) {
-
return (ball_top + Game.ball.diameter >= block_top) &&
-
(ball_top <= block_top + block_height);
-
}
30
Chapter 7. Writing a Game for the Motion-Sensing Game Controller 122
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