Hardware Reference
In-Depth Information
LINK
- +
ETHERNET
SHIELD
L
RX
ON
100M
MADE IN ITALY
WWW.ARDUINO.CC
ICSP
Figure 5-15
The balance board client
circuit laid out on a per-
forated circuit board.
Figure 5-16
The circuit board
layout showing where
the solder joints are
connected underneath
the board.
The Server
The server's tasks can be divided into two groups: those
related to the game play, like animating the paddles and
the ball and scoring; and those related to tracking new
clients. To manage it all most effectively, you're going to
use an object-oriented programming approach. If you've
never done this before, there are a few basics you need to
know in advance.
and height, and it has a location, which you can express in
terms of its horizontal and vertical positions. In your game,
the paddles will have another important property: each
paddle will be associated with a client. Of course, clients
have properties as well, so each paddle will inherit an IP
address from its client. You'll see all of these in the code
that defines a paddle as an object.
A paddle also has a characteristic behavior: it moves left
or right. That behavior will be encoded into the paddle as a
method called movePaddle() . This behavior will update the
properties of the paddle that define its location. A second
behavior called showPaddle() will actually draw the paddle
in its current location. You'll see later why these are kept
separate.
Anatomy of a Player Object
The most important thing to know is that all objects have
properties and behaviors. You can think about an object's
properties in much the same way as you think about
physical properties. For example, a pong paddle has width
To define an object in
Processing (or in Java for
that matter), create a code block called
a class . Here's the beginning of the class
that defines a player in the pong server.
Code It
public class Player {
// declare variables that belong to the object:
float paddleH, paddleV;
Client client;
Search WWH ::




Custom Search