|
Second Summer 2002
|
Lecture Notes Thirty-One: A Video Game in Java:
The Alien Landing Game
What do we do today?
|
We build a computer game.
|
Why do we do that?
|
It's exciting, and we want to write such a game ourselves by the end of the semester.
|
A simpler one.
|
Yes, but seeing a slightly more complicated one first would
help us in getting the prototype clear in our minds.
|
Alright, let's go for it.
|
Very good. The mechanics is simple, as you will see.
|
The understanding of it is less trivial.
|
Trivial here (and in mathematics, in general) means "relating
to or being the mathematically simplest case". Or commonplace.
|
You need five files:
|
You will also need a directory of images, called image ). Here's a
list of the images:
|
In terms of URLs we have (for the source code)
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/GameManager.java
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/GunManager.java
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/Sprite.java
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/UFO.java
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/UFOManager.java
As for images their addresses are:
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack0.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack1.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack2.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack3.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack4.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/attack5.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/explode0.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/explode1.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/explode2.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/explode3.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/gun.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo0.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo1.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo2.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo3.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo4.gif
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/image/ufo5.gif
Copy each file to your desktop, then compile them, one by one. Use emacs
(installation
notes indexed in the main page).
|
Bring each Java file in emacs, look at it, compile it. Or do it from the command line.
|
http://www.cs.indiana.edu/classes/a202-menz/lib/emacs.html
Why do we need so many files?
|
The game we'll write in class before the end of the semester
will be much simpler, but I want you to see what a reasonably
nice game looks like.
|
And you also need an HTML file like this:
|
Yes, this loads the applet in the browser.
|
<html>
<head>
<title>Alien Landing</title>
</head>
<body bgcolor=white>
<applet code=GameManager.class width=240 height=300>
</applet>
</body>
</html>
Then what you do?
|
Run it.
|
How does it look?
|
It should look like this.
|
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/alien.html
By the way, you also need an audio file.
|
Oh, here it is:
|
http://www.cs.indiana.edu/classes/a201-dger/spr2001/labs/nine/explosion.au
For a thorough understanding of this program I recommend the following sequence of notes:
Basic Java
- Java Fundamentals. A Bit Outdated.
http://www.cs.indiana.edu/classes/a348/t540/lectures/One.html
Animation
- Using Objects for Animation
http://www.cs.indiana.edu/classes/a348/t540/lectures/Two.html
Sprites
- Animating Sprites
http://www.cs.indiana.edu/classes/a348/t540/lectures/Three.html
Interactivity
- Adding Interactivity
http://www.cs.indiana.edu/classes/a348/t540/lectures/Four.html
Bitmap Loops
- Creating Birmap Loops
http://www.cs.indiana.edu/classes/a348/t540/lectures/Five.html
A Video Game
- Building a Video Game
http://www.cs.indiana.edu/classes/a348/t540/lectures/Six.html
After this, the next logical step is the program presented above.
Last updated: Jul 31, 2002 by Adrian German for A201