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 #178 background imageLoading...
Page #178 background image
The
draw_crosshairs
function actually draws the crosshairs on the screen. Instead
of using a bitmap to draw the crosshairs, we use two new TVout methods.
draw_row
outputs a horizontal line, and we use it to output the two horizontal
lines of the crosshairs. Similarly, we use
draw_column
to draw the two vertical
lines. We leave the pixel at the crossing point empty to make the crosshairs
look a bit nicer.
You might wonder why we didnt use a bitmap. The problem with bitmaps is
that they dont look nice when they overlap. Even if the bitmap looks like
crosshairs, it still is a square. If you move a crosshairs bitmap over a circle,
the bitmap will hide a big part of the circles pixels.
To complete the games source code, we need two functions for managing the
targets:
Tinkering/Pragduino/Pragduino.ino
bool target_hit() {
if (z_button)
return (target_x - chx) * (target_x - chx) +
(target_y - chy) * (target_y - chy) < target_r * target_r;
return false;
}
void check_target() {
if (target_hit()) {
hits++;
create_target();
}
int remaining_time = millis() - target_creation;
if (remaining_time >= TARGET_LIFESPAN) {
create_target();
}
int w = map(TARGET_LIFESPAN - remaining_time, 0, TARGET_LIFESPAN, 0, WIDTH);
tv.draw_rect(0, 0, w, 3, WHITE, WHITE);
}
target_hit
checks whether the player has hit the current target. This can only
happen if the player presses the Z button. If this is the case, we use a simple
distance calculation to see whether the crosshairs are in the circle.
To manage the current targets lifecycle, we use
check_target
. If the target was
hit, we increment the
hits
counter and create the next target. After that, we
calculate the time the current target will stay on the screen unless it gets hit.
If this time is greater than the targets lifespan, we create a new target. At the
end of the function, we turn the remaining time into a status bar at the top
of the screen.
report erratum discuss
Creating Your Own Video Game 161
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