Hardware Reference
In-Depth Information
The time the delay provides is the amount of time that any one LED is on before going to the next LED in the
display; this is also the amount of time the player has to react to stop the LED sweep. The time for the delay is set
by subtracting the level times 6 from 100. With the first level being equal to 0, the delay will be 100 ms, and every
subsequent level shortens the time by 6 ms. the big win occurs after level 11 has been passed; that level has a time of
40 ms between LEDs. This delay sets the difficulty of getting a win a larger delay make the game easier and smaller
is more difficult. The difficulty needs to be balanced for the intended audience, and is usually determined by age for
arcade games. Games that are for children are often really easy for adults.
It is important that the delay never goes negative; otherwise, the program will freeze up. Stop it allows a level
up to 15 before resetting at a delay 10 ms; at this delay time, it is unlikely that a human player can achieve a win.
Note
Listing 11-1. Stop It's Code, Part 11 of 11
void loop() {
detachInterrupt(0);
if (button == true) {
checkWin();
}
moveLED();
attachInterrupt(0, Button, LOW);
delay ( 100 - (level*6));
}
Verifying the Code
Stop it is ready to play after an Arduino is connected to the LEDs and button, as per Figure 11-1 (shown previously
in the chapter). Upload all 11 parts of Listing 11-1 as a single Arduino sketch. Once the upload is finished, the game
should start sweeping one LED from one side of the display. Depending on the color of the LEDs used, the display
may be reminiscent of the front of a certain black 1980s sports car with artificial intelligence.
Begin the game by testing your skill, and try to Stop It on the center LED by pressing the button when the center
LED is ON. The code should react as describe earlier. Since it may not be easy to test all the way to a big win, this game
has a developer (or cheat mode) built in. To enter developer mode and ensure that the code is behaving properly,
connect the ground side of the switch to the cathode side of the winning LED. Developer mode will make the button
only trigger the interrupt when the center LED is on. Developer mode makes it possible to cycle though all of the
levels and back to the first one.
Dirty Little Tricks,
Not to detract from the excitement of developing arcade games, but it is worth mentioning the unfair advantage
known as rigging that some arcade games might have built into them. Such rigging only allows prizes to be won
after certain conditions are met other than those presented within the game (some games never allow prizes to be
won at all). This is like the belief that slot machine will only pay out a jack pot when it has received a certain dollar
amount. Because arcade games are not regulated the same way as gambling machines, the possible use of rigged
mechanisms has led to some controversy about legalities. Rigging is an unfortunate practice that takes away from a
game's entertainment value and in some places can be illegal. Rigging may come up when developing a redemption
or merchandiser game for a client.
 
 
Search WWH ::




Custom Search