Lecture Notes Six: Building a Video Game
How are we going to do this?
| |
We need a plan.
|
Let's divide the game into two parts:
- the aliens
- the turret (with missile)
| |
I propose that we build two functional units:
- a
UFOManager , and
- a
GunManager
|
The UFOManager will control the aliens.
| |
The GunManager will control the defense.
|
A third unit controls them both: this is not real
stuff, it's a simulation, it's our game.
| |
Let's call this third functional unit GameManager .
It acts as a referee more or less.
|
GameManager has three roles:
- initializes
GunManager
- initializes
UFOManager
- receives user input
| |
Any user input detected by GameManager
(perhaps a mouse move, or a mouse click) is passed to
GunManager , which interprets it, and takes
action (if need be).
|
Indeed, we need to have at least three kinds:
- we need to show a turret
- we need to show a missile
- we need to show a UFO
| |
So I suggest three classes:
-
GunSprite
-
MissileSprite
-
UFOManager
|
Can I draw a picture?
| |
Go for it!
|

| |
Control classes in blue,
sprite classes in red.
|
Six classes. Let me show them to you.
| |
Be my guest.
|
OK, I start with GunSprite .
| |
|

| |
And with another picture.
|
Now the code:
| |
Actually I need to rework this!
|
Can you do it a little bit later, not now?
| |
OK, here's what we have:
|
Sprite
|
|
Moveable BitmapSprite
* |
+------+--------+
|
|
Intersect BitmapLoop
* |
+-----+------+
|
UFO
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/Sprite.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/Moveable.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/BitmapSprite.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/Intersect.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/BitmapLoop.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/UFO.html
UFOManager
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/UFOManager.html
Applet Runnable
+ *
| |
| |
| |
+----GameManager-----*
http://java.sun.com/products/jdk/1.2/docs/api/java/applet/Applet.html
http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Runnable.html
Moveable Sprite
* |
Intersect | BitmapSprite---+
| | |
*-------GunSprite---+
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/BitmapSprite.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/GunSprite.html
GunManager
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/GunManager.html
Sprite
|
+----Sprite2D
|
+---RectSprite
|
+---MissileSprite
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/Sprite2D.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/RectSprite.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/MissileSprite.html
Well, at least we get an idea.
| |
Yes, we get an idea.
|
Images:
gun.gif,
ufo0.gif,
ufo1.gif,
ufo2.gif,
ufo3.gif,
ufo4.gif,
ufo5.gif.
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/gun.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo0.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo1.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo2.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo3.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo4.gif.html
http://www.cs.indiana.edu/classes/a348/t540/lectures/six/image/ufo5.gif.html
Last updated: Jan 21, 2002 by Adrian German
for T540 NGD