is to move the paddle along the
bottom of the screen in order to
deflect a ball into a set of bricks at
the top of the screen. If all of the
bricks are eliminated before your five
plays have been expended, then you
win the game.
Another action game is Aliens in
which you use your ground-based
phasers to blast the alien ships out of
the sky. Watch out, because they
shoot back. You must destroy all of
the alien ships before they destroy all
of the buildings in the city.
When writing games for the
Seeed Studio Touch Shield involving
movement, you should remember
that only the opaque portion of each
character is drawn on the screen by
the drawString function. Any
background color behind the
transparent portion of a character is
not overwritten. To erase a character,
simply draw it in the background
color.
For example, when moving the
ball in the Bricks game, the previous
position of the ball is drawn in the
background color. The new position
of the ball is then drawn in the
specified foreground color. To the
player, this will give the appearance
of a moving ball.
For an object that is going to be
moved, you can also use the
fillScreen function to fill the object’s
area using the background color,
then draw the object in its new
location in the specified foreground
color. Either way, you will accomplish
the same purpose.
For arcade-style games, you may
want to use the touchPosition
function because you can read the
position of a finger (or stylus) press
very rapidly and respond accordingly.
To discover additional functions
not described here, do the following:
Start the Arduino IDE. Click the File
option. Mouse over the Examples
option. Mouse over the TFTscreen
library folder. Open each of the files
in the TFTscreen folder and examine
the code.
You will discover the following
functions: Tft.drawChar,
Tft.drawCircle, Tft.drawFloat,
Tft.drawHorizontalLine,
Tft.drawNumber, Tft.drawVerticalLine,
Tft.fillCircle, and Tft.fillRectangle. Be
sure to run the example code on
your system to see how each of the
functions work.
In game programming, you
should always try to consider every
possible scenario and design your
system accordingly. Programmers
should pay heed to Spencer’s Rule
of Engineering Design: Leave nothing
to chance because chance is a lousy
engineer.
I hope you have lots of fun
writing games for the Arduino. NV
;;;
;;;;;;;;;;;
;;; ;;;;;;;;;;;
---; &&"&"!,*)(%!+;!)'
;-'(-; ,**;;-((; ;;;;;;;;;;;;
;;;;$;; ;;;;;;; ;;
;;;#;;;;#;;;;;;;
;;;; ;;;; ;;;#)*;;;;;;;
'-:A;;<:76/;.7:;1<;;;1B-;;
;; ;/)=;;;;
;::-/= 4):4A;;0)8-,;;
;;;;@;;;;;;;@;;;;;;;;;;;
;;;;;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