Game Development Reference
In-Depth Information
m/s
v
=θ = =
v
1 cos
8cos 30
6.93
(6.21a)
1
p
x
m/s
v
=−
v
1 sin
θ=−
8sin 30
=−
4
(6.21b)
1
n
x
v
=
0
(6.21c)
2
p
v
=
0
(6.21d)
2
n
Step 3 in the process is to compute the post-collision velocities for the two spheres according
to Equation (6.14).
mem
10
4.5 6.93
m/s
v
=
v
mm
1
2
=
=
2.54
(6.22a)
1
p
1
p
+
15
1
2
(
)
1
+
em
19 6.93
m/s
v
=
v
mm
1
=
=
8.78
(6.22b)
2
p
1
p
+
15
1
2
The final step in the process is to rotate the post-collision velocities back to the standard
Cartesian coordinate system using Equation (6.20) to obtain the post-collision x- and y-
components of velocity.
m/s
=θ −θ =
v
v
cos
v
sin
2.54 cos 30
+ =
4 sin 30
4.2
(6.23a)
1
x
1
p
1
n
v
=θ = =
v
1 cos
8cos 30
6.93
m/s
=θ +θ =
v
v
sin
v
cos
2.54 sin 30
4 cos 30
2.19
(6.23b)
1
p
x
1
y
1
p
1
n
m/s
=θ −θ =
v
v
cos
v
sin
8.78 cos 30
=
7.60
(6.23c)
2
x
2
p
2
n
m/s
=θ +θ =
v
v
sin
v
cos
8.78sin 30
=
4.39
(6.23d)
2
y
2
p
2
n
After the collision, both spheres are moving in the positive x-direction, but sphere 1 has
slowed down because part of its momentum was transferred to sphere 2 during the collision.
Sphere 2 is traveling in the positive y-direction and sphere 1 is traveling in the negative y-direction.
A Paddle Game
Let's use what we know about two-dimensional linear collisions to create a paddle game. A black
ball bounces around inside an open-ended box. Your job is to use a paddle to hit the ball and
keep it inside the box. If the ball gets past the paddle and reaches the open end of the box (the
left-hand side), you lose. If you're old enough to remember, the Paddle Game is essentially a
one-person version of the video game Pong.
The only force that will affect the motion of the ball will be the force due to collision with
the three walls of the box and with the paddle. All other forces (gravity, drag, wind, etc.) will be
ignored. The GUI framework for the Paddle Game is similar to that for the games previously
presented in the topic, so very little time will be spent describing the GUI aspects of the code.
One new feature of the Paddle Game GUI is a slider component that can be moved up or down
to change the location of the paddle. A sample screen shot of the Paddle Game is shown in
Figure 6-9.
Search WWH ::




Custom Search