Playing Intro Movies and Cut-Scenes

Animated movie sequences have become a standard feature of computer and video games, so much so that introductory movies and cut-scenes for games are often used as demo reels and trailers before the game is finished. If a high-end game is released without an introductory movie or narrative of some kind, it is possible that the game will make a poor first impression on reviewers and consumers alike. A two-minute game "teaser" trailer or introductory movie can take up to a year and cost upwards of a million dollars to produce, due to the excruciating detail put into the 3D animation sequences that are rendered for the movie. Game studios often hire 3D animators and concept artists to use programs such as Maya and LightWave for both game artwork and movies.

This chapter teaches you how to add intro movies and cut-scenes to your DarkBASIC programs. As you will learn, you can use DarkBASIC for the sole purpose of playing movie files, which can be embedded inside an executable. If you are an animator or a 3D modeler learning DarkBASIC to enhance your portfolio, you might use this feature to make your demos into self-running programs!

Introduction to Movies

In the early days of video games, an intro movie was usually a paragraph of text on the screen with perhaps a single-channel soundtrack. As games became more complex and budgets were increased, intro movies and cut-scenes became more elaborate, moving from text to game engine cinematics. Wing Commander II: Vengeance of the Kilrathi was one of the first games to feature cut-scenes, and later games in the Wing Commander series followed suit to much acclaim, with custom movie-quality sets and popular actors reprising the roles of lead characters in the game.

Game Cinema

Wing Commander II was a trend-setting game featuring extraordinary movies that told the story within the game. Keep in mind that when this game came out, the average PC was a 486/33 with 8 MB of memory and an Adlib or Sound Blaster card. Windows 3.0 was not even around yet. That the game had movie sequences and voiceovers was extraordinary. Granted, the speech kit was an add-on for the game, sold separately. The game wasn't even distributed on a CD-ROM. Actually, CD-ROM technology had not hit the mainstream yet, so games were still being put on 5′′ or 3′′ floppy diskettes (1.2 MB and 1.4 MB, respectively). The movie sequences in Wing Commander II were recorded on video and then digitized using a video capture card. In other words, the movies were not rendered in 3D as they are today.

Video capture movies were used in the follow-up Wing Commander games, but they dropped in popularity as the game industry became flooded with video-capture games in the great multimedia revolution. As a result, movies are almost always rendered in 3D today. If you are looking for ideas for how to create intro movies for your own games, consider recording a video of your game actually running (perhaps in demo mode), adding a catchy soundtrack, and using the demo trailer for your game as the intro movie.

What Is a Movie File?

Movie files store the video frames and audio streams that make up a movie sequence. The AVI (Audio-Video Interleaved) format was a standard for Windows multimedia PCs at the start of the multimedia revolution in the early 1990s, and it is still the most popular movie file format for Windows. However, there are many competing video formats, such as Apple's QuickTime (.mov), RealNetwork's RealMedia (.rm), and the somewhat more professional and platform-independent MPEG (.mpg) formats. Since that time, AVI has been expanded with multiple compressor-decompressor (codec) formats, making it extremely versatile at the expense of complexity. When encoding or decoding to or from an AVI, it can be confusing to figure out which codec to use. Despite the growing list, two formats are compatible with most AVI players—Indeo and Cinepak. If you have ever played around with a video capture card or video mastering software, you have likely come across these codecs.


Loading and Playing Movie Files

Despite the confusing plethora of audio-video formats and codecs, DarkBASIC makes loading and playing AVI files as simple as loading and displaying a bitmap image. Not only does DarkBASIC let you load and play a movie file with only a couple of lines of source code, you can also play several movies on the screen at the same time!

Basic Movie Playback Commands

There are quite a few commands to help you get the most out of your movie-going experience, but only a couple of those commands are absolutely necessary. This section will show you the commands that simply load and play a movie, along with some helper commands. First, I want to introduce you to the command to load a movie file.

The LOAD ANIMATION Command

You can use the LOAD ANIMATION command to load an AVI movie file into DarkBASIC. The syntax of the command is LOAD ANIMATION Filename, Animation Number.

The first parameter is the name of an AVI file, which is relative to the current folder in which the program was run. The second parameter is a number from 1 to 32, representing the position in which to store the movie in DarkBASIC. You can load up to 32 movies at a time and play any or all of them at any time. However, keep in mind that movie files can be large, and you might extinguish available memory by trying to load them all at once. It is usually better to load a movie, play it, and then delete it from memory (using the DELETE ANIMATION command, which I will cover later).

The ANIMATION EXIST Command

After you have loaded a movie file into DarkBASIC, there are several helper commands available to tell you about the movie. One such command is ANIMATION EXIST, which has the syntax Return Value = ANIMATION EXIST (Animation Number).

If the animation has been loaded, then the ANIMATION EXIST command will return a 1; otherwise, it will return a 0. You can use this command to determine whether a movie file loaded correctly. Another way to make sure the movie was loaded correctly is to check its dimensions, as the next two commands demonstrate.

  Note

In DarkBASIC, the term animation is synonymous with the term movie.

The ANIMATION WIDTH Command

The ANIMATION WIDTH command returns the horizontal resolution of a movie after it has been loaded by referencing the animation number parameter. The syntax for the command is Return Value = ANIMATION WIDTH (Animation Number).

This command comes in handy when you want to resize or reposition the movie. As I'll show you later in this chapter, you can scale the movie or center it on the screen.

The ANIMATION HEIGHT Command

The ANIMATION HEIGHT command returns the vertical resolution of a movie after it has been loaded by referencing the animation number parameter. The syntax for the command is Return Value = ANIMATION HEIGHT (Animation Number).

The PLAY ANIMATION Command

After you have loaded and verified a movie file, you can play it using the PLAY ANIMATION command. The syntax for this command is PLAY ANIMATION Animation Number, Bitmap Number, Left, Top, Right, Bottom.

The first parameter is required, but the others are optional. By specifying the bitmap number, you can send playback to a specific bitmap. The last four parameters (Left, Top, Right, and Bottom) resize and reposition the movie on the screen. This is demonstrated in the PlayAnim program, which I will cover shortly.

The ANIMATION PLAYING Command

Some movie files are short, and others can be very long. In fact, some games have high-resolution intro movies that weigh in at several hundred megabytes. You can use the ANIMATION PLAYING command to determine when a movie is done playing. The syntax is Return Value = ANIMATION PLAYING (Animation Number).

The DELETE ANIMATION Command

After you have finished playing a particular movie that you might not need again, you should consider deleting it to free up memory and make room for other movies. You can delete a movie using the DELETE ANIMATION command. The syntax is DELETE ANIMATION Animation Number.

The PlayAnim Program

All right, how about a demonstration of loading and playing a movie file? Nothing beats a little source code to see how something works. I wrote the PlayAnim program just for that purpose. It is simple enough that you can see how easy it is to load and play a movie file. Take a look at Figure 16.1, which shows a movie file playing with the default resolution. Figure 16.2 shows a movie playing in fullscreen mode, which is possible by simply changing the size parameters of the PLAY ANIMATION command.

click to expand
Figure 16.1: The PlayAnim program loads and plays an AVI movie file using the default width and height of the movie.

click to expand
Figure 16.2: The PlayAnim program can be set to run full screen by changing the Right and Bottom parameters to the resolution of the screen.

Note that the PlayAnim program (and all other programs in this chapter) runs at 640480 in 32-bit color mode. Although all of the sample programs run at this screen resolution, the color depth is not quite as important. Although 32-bit color is higher quality than 16-bit color, and special effects such as transparency are possible with 32-bit color mode, feel free to use either 32-bit or 16-bit color (using the third parameters of the SET DISPLAY MODE command). If your video card is unable to run in 32-bit color mode (or if it runs slowly), change the display mode command so it uses 16-bit color instead. DarkBASIC Pro supports this command, but it is preferable to use the Project Manager to configure the video mode instead.

'---------------------------------
'Beginner's Guide To DarkBASIC Game Programming
'Copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
'Chapter 16 - PlayAnim Program
'---------------------------------

'initialize the program
SET DISPLAY MODE 640, 480, 32
HIDE MOUSE
CLS

'load background bitmap
LOAD BITMAP "background.bmp", 0

'load the animation file
LOAD ANIMATION "congrat2.avi", 1

'play the animation
PLAY ANIMATION 1, 0, 0, 320, 240
'wait for keypress
WAIT KEY

'remove the movie from memory
DELETE ANIMATION 1
END

Looping Movie Playback

One thing you probably noticed right away was how short the movie was in the PlayAnim program. It was only a few seconds long! That file, like many of the others in this chapter, is one of the movie files that comes with DarkBASIC. You can use those animated movies to enhance your game, such as by playing the Congratulations movie when the player wins or the Game Over movie when the game ends.

The LOOP ANIMATION Command

The animation in the PlayAnim program doesn't last long because that particular movie file simply is supposed to display the Congratulations message on the screen. But what if you want to repeat the movie after it has stopped? For example, you can use the LOOP ANIMATION command to loop the movie to play until the player presses a key or clicks a mouse button. The syntax for this command is LOOP ANIMATION Animation Number, Bitmap Number, Left, Top, Right, Bottom.

The last four parameters (Left, Top, Right, and Bottom) are optional, as is the Bitmap Number parameter. I will explain movie scaling shortly, but for now I'll focus on looping.

The ANIMATION LOOPED Command

When a movie is playing in loop mode, the ANIMATION LOOPED command returns a 1 for that movie; otherwise, it returns a 0. The syntax for the command is Return Value = ANIMATION LOOPED (Animation Number).

The STOP ANIMATION Command

Because a looping movie will continue to loop indefinitely, you need a way to stop the playback at some point (such as at the end of the program). You can stop playback of a movie using the STOP ANIMATION command. The syntax is STOP ANIMATION Animation Number.

The PAUSE ANIMATION Command

Now for some support commands, as promised. There are several handy commands you can use while a movie file is playing. For example, to pause playback at the current position, you can use the PAUSE ANIMATION command. The syntax is PAUSE ANIMATION Animation Number.

The ANIMATION PAUSED Command

When a movie has been paused, you can check the status of the paused property using the ANIMATION PAUSED command. The syntax is Return Value = ANIMATION PAUSED (Animation Number).

The RESUME ANIMATION Command

Another useful command is RESUME ANIMATION, which resumes playback after a movie has been paused. The syntax for this command is RESUME ANIMATION Animation Number.

Keep in mind that although these commands are all similar in syntax, you can use any animation number from 1 to 32 when calling them, which gives you the ability to manipulate multiple movies at the same time. I would think that playing just one movie on the screen would be enough to ask of DarkBASIC, but it goes a step further by allowing you to play several at a time!

The MultiAnim Program

The MultiAnim program plays four movies on the screen at the same time. By pressing the number keys 1 to 4, you can pause and resume playback of each of the four movies. The Esc key ends the program. Figure 16.3 shows the output of the MultiAnim program. This program is very demanding of your PC, so if it doesn't respond immediately to the number keys, just hold the key down for a second and you should see something happen.

click to expand
Figure 16.3: The MultiAnim program plays four movie files at the same time and allows the user to pause and resume playback of each video stream.


'---------------------------------
'Beginner's Guide To DarkBASIC Game Programming
'Copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
'Chapter 16 - MultiAnim Program
'---------------------------------

'initialize the program
SET DISPLAY MODE 640, 480, 16
HIDE MOUSE
DISABLE ESCAPEKEY
CLS

'load background bitmap
LOAD BITMAP "background.bmp", 0

'load and start each of the movies
LOAD ANIMATION "youwin1.avi", 1
LOOP ANIMATION 1
LOAD ANIMATION "congrat2.avi", 2
LOOP ANIMATION 2, 0, 320, 0, 640, 240
LOAD ANIMATION "gameover2.avi", 3
LOOP ANIMATION 3, 0, 0, 240, 320, 480
LOAD ANIMATION "loading3.avi", 4
LOOP ANIMATION 4, 0, 320, 240, 640, 480
'loop until ESC key pressed
REPEAT
 FOR N = 1 TO 4
 IF VAL(INKEY$()) = N
 IF ANIMATION PAUSED(N)
 RESUME ANIMATION N
 ELSE
 PAUSE ANIMATION N
 ENDIF
 ENDIF
 NEXT N

 'update the screen
 SYNC
UNTIL ESCAPEKEY()

'delete the movies
FOR N = 1 TO 4
 DELETE ANIMATION N
NEXT N
END


Changing the Position and Size of a Movie

Now that you've had a little experience playing and looping movie files, I'd like to explain some advanced playback features. This section will explain how to change the scale and position of a movie during playback, with some interesting results.

Changing the Position of a Movie

Although you can simply play a movie using the full resolution of the screen, it is far more likely that you will want to use DarkBASIC's fantastic movie-playing capabilities for many small animations in a game or program. To do this, you will need a way to reposition the playback to anyplace on the screen, and then return the position of the movie. Following are some commands that will help you to do just that.

The PLACE ANIMATION Command

PLACE ANIMATION is one of the most versatile movie playback commands in DarkBASIC. The syntax is PLACE ANIMATION Animation Number, Left, Top, Right, Bottom.

Using this command, you can reposition and scale a movie during playback. That is the significant phrase—during playback. You can set the scale and position using the PLAY ANIMATION command. However, after the movie has started, you must use PLACE ANIMATION to make changes during playback. The MoveAnim and ScaleAnim programs, which are featured later in this chapter, demonstrate how to use this command.

The ANIMATION POSITION X Command

When you are using the PLACE ANIMATION command, it is convenient to be able to return the position of the movie on the screen. There are two commands for determining the position of the movie. The first command, ANIMATION POSITION X, returns the X position of a movie. The syntax is Return Value = ANIMATION POSITION X (Animation Number).

The ANIMATION POSITION Y Command

The other command for determining the position of a movie is ANIMATION POSITION Y, which returns the Y position of a movie. The syntax is Return Value = ANIMATION POSITION Y (Animation Number).

The MoveAnim Program

I must admit, I just flew through those position commands! Here's a little something that will help explain the subject in more detail—a complete program called MoveAnim (see Figure 16.4). This program loops a movie while moving it around on the screen and bouncing it off the walls. If this program resembles a sprite demo, it's because the program has a game loop and it updates the movie's position and velocity, just like the sample programs in Chapter 11.

click to expand
Figure 16.4: The MoveAnim program moves the position of a movie on the screen while it is playing.


'---------------------------------
'Beginner's Guide To DarkBASIC Game Programming
'Copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
'Chapter 16 - MoveAnim Program
'---------------------------------

'create some variables
X = 0
Y = 0
SPEEDX = 3
SPEEDY = 2

'initialize the program
SET DISPLAY MODE 640, 480, 32
HIDE MOUSE
DISABLE ESCAPEKEY
SYNC ON
CLS

'load background bitmap
LOAD BITMAP "background.bmp", 1
COPY BITMAP 1, 0

'load the animation file
LOAD ANIMATION "youwin1.avi", 1
'play the animation
LOOP ANIMATION 1

'loop until ESC key pressed
REPEAT
 'restore background under the movie
 COPY BITMAP 1, X, Y, X + 319, Y + 239, 0, X, Y, X + 319, Y + 239

 'update the X position
 X = X + SPEEDX
 IF X < 1 OR X > 315
 SPEEDX = SPEEDX * -1
 ENDIF

 'update the Y position
 Y = Y + SPEEDY
 IF Y < 1 OR Y > 235
 SPEEDY = SPEEDY * -1
 ENDIF

 'reposition the movie
 PLACE ANIMATION 1, X, Y, X + 320, Y + 240

 'update the screen
 SYNC
UNTIL ESCAPEKEY()
DELETE ANIMATION 1
END

Changing the Scale of a Movie

Moving the position of a movie is pretty impressive, but it is nothing compared to real-time scaling! Scale refers to not only the size of something, but also the ratio of width to height. Although you could scale the horizontal dimension of a 2D object to stretch it left to right, and you could likewise scale the vertical dimension to stretch it top to bottom, that is not true scaling (and it is not particularly useful). Scaling involves resizing both dimensions (horizontal and vertical) by the same amount. That is really the only way to get clean results with a movie.

To change the scale of a movie, you use the same command that you used earlier to reposition a movie—PLACE ANIMATION. For reference, the syntax for this command is PLACE ANIMATION Animation Number, Left, Top, Right, Bottom.

The key to scaling a movie lies with the last two parameters: Right and Bottom. To change the scale of a movie, you simply modify the Right and Bottom values by a set percent, and the output will either shrink or grow by that percent.

The ScaleAnim Program

To demonstrate movie scaling, I have written a program called ScaleAnim. Figure 16.5 shows a movie with a very small scale, and Figure 16.6 shows the same movie at 165% of its normal size, nearly filling the screen.

click to expand
Figure 16.5: The ScaleAnim program changes the scale of a movie during playback. Here, the movie is reduced to a very small size.

click to expand
Figure 16.6: The ScaleAnim program loops the animation while changing the scale from 10% to 200%.


'---------------------------------
'Beginner's Guide To DarkBASIC Game Programming
'Copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
'Chapter 16 - ScaleAnim Program
'---------------------------------

'create some variables
scale# = 1.0
change# = 0.05
SX = 0
SY = 0
X = 0
Y = 0

'initialize the program
SET DISPLAY MODE 640, 480, 32
HIDE MOUSE
DISABLE ESCAPEKEY
SYNC ON
CLS

'load background bitmap
LOAD BITMAP "background.bmp", 1
COPY BITMAP 1, 0
SET CURRENT BITMAP 0

'load the animation file
LOAD ANIMATION "gameover2.avi", 1

'play the animation
LOOP ANIMATION 1

'loop until ESC key pressed
REPEAT
 'redraw background
 COPY BITMAP 1, 0

 'change the scale
 scale# = scale# + change#
 IF scale# < 0.1 OR scale# > 2.0
 change# = change# * -1
 ENDIF

 'reposition the movie
 SX = INT(320 * scale#)
 SY = INT(240 * scale#)
 X = 320 - SX / 2
 Y = 240 - SY / 2
 PLACE ANIMATION 1, X, Y, X + SX, Y + SY

 TEXT 0,0,"Scale: " + STR$(scale#)

 'update the screen
 SYNC
UNTIL ESCAPEKEY()
DELETE ANIMATION 1
END


Movie Trailers

So you can really get a feel for what an introductory movie is like, I recommend that you download some movie or video game trailers from http://www.apple.com/trailers or http://www.ifilm.com. However, some movie files are not in a format supported by DarkBASIC. The three most popular movie formats are Windows Media, Apple QuickTime, and RealPlayer. To play a movie file, it must be an AVI file in a standard format such as Indeo or Cinepak. As long as you use a standard format when converting a movie file to AVI for use in DarkBASIC, the movie will be playable. Many sample movies come with DarkBASIC, such as those used in the sample programs in this chapter.

As for converting video files, there are numerous programs on the Internet that you can download and try out or purchase. One such program that I recommend is EO Video by McGray Ltd. You can learn more about EO Video and download a trial version from http://www.eo-video.com. I like this program because it can convert from any movie format to another, and it can even combine multiple movie files into a single output file using any codec (compressor-decompressor) format.

Feel free to modify the PlayMovie program to scale the movies to fill the whole screen. However, at higher than 320240 (the most common resolution), some movies look grainy, so I prefer to watch them at their native resolution. The amazing thing about DarkBASIC is that you can compile the movies into the executable file by choosing Make Final from the File menu (or by pressing F7). Before you build the final executable, make sure that only the desired media files are in the current folder because DarkBASIC links all media files in the folder (in other words, DarkBASIC doesn't parse the source code for file names). DarkBASIC Pro, however, requires you to use the Media settings in the Project Manager. (Simply select the Media button at the bottom-right corner of the screen.)

The PlayMovie Program

The PlayMovie program is similar to the PlayAnim program with the added feature that it centers the movie on the screen. This program also shows how to check the horizontal and vertical resolution of the movie file so it can be centered properly. Previous programs in this chapter hard-coded the playback resolution.

'---------------------------------
'Beginner's Guide To DarkBASIC Game Programming
'Copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
'Chapter 16 - PlayMovie Program
'---------------------------------

'create some variables
Width = 0
Height = 0
X = 0
Y = 0

'initialize the program
SET DISPLAY MODE 640, 480, 32
HIDE MOUSE
DISABLE ESCAPEKEY
CLS

'modify the following line with the appropriate filename
LOAD ANIMATION "moviefile.avi", 1

'get resolution of the movie
Width = ANIMATION WIDTH(1)
Height = ANIMATION HEIGHT(1)
X = 320 - Width / 2
Y = 240 - Height / 2

'play the animation
PLAY ANIMATION 1, X, Y, X + Width, Y + Height

'wait for keypress
WAIT KEY

'remove the movie from memory
DELETE ANIMATION 1
END


Summary

This chapter explored the subject of playing movies for the introduction to a game and for cut-scenes within a game. DarkBASIC supports the AVI format most common on Windows PCs. It is capable of playing any Indeo, Cinepak, or similar codec in an AVI file. This chapter also showed you how to position a movie on the screen, how to move the movie during playback, and how to change the size of the movie by scaling the output rectangle. Finally, the chapter provided some exciting sneak peek trailers of popular games to use while testing the movie playback.


Quiz

The chapter quiz will help you retain the information that was covered in this chapter, as well as give you an idea about how well you're doing at understanding the subjects. The answers for this quiz can be found in Appendix A, "Answers to the Chapter Quizzes."

1.

What does codec stand for?

  1. C source code
  2. Compressor-decompressor
  3. Compound decompression
  4. Condenser-defibrillator

b

2.

Which movie file format does DarkBASIC support?

  1. MPG
  2. MOV
  3. WMV
  4. AVI

d

3.

What are arguably the two most significant video codecs for the AVI format?

  1. QuickTime and RealMedia
  2. Indeo and Cinepak
  3. Video-1 and Video-CD
  4. DVD and MPEG-2

b

4.

Which command plays a previously loaded movie file repeatedly?

  1. LOOP ANIMATION
  2. PLACE ANIMATION
  3. REPEAT ANIMATION
  4. PLAY ANIMATION

a

5.

Which movie file format has an .mov extension?

  1. RealMedia
  2. Windows Media Player
  3. QuickTime
  4. MPEG

c

6.

What is the maximum number of movies that can be played on the screen at once in a DarkBASIC program?

  1. 4
  2. 8
  3. 16
  4. 32

d

7.

Which command changes the scale or size of a movie during playback?

  1. SCALE ANIMATION
  2. PLAY ANIMATION
  3. PLACE ANIMATION
  4. SET ANIMATION

c

8.

Which command retrieves the current horizontal position of a movie?

  1. ANIMATION X
  2. ANIMATION POSITION X
  3. ANIMATION GET X
  4. GET ANIMATION X

b

9.

Which command moves a movie to another position on the screen?

  1. MOVE ANIMATION
  2. PLACE ANIMATION
  3. SET ANIMATION
  4. POSITION ANIMATION

b

10.

In what year was the game Wing Commander II: Vengeance of the Kilrathi released?

  1. 1989
  2. 1990
  3. 1991
  4. 1992

b

Answers

1.

B

2.

D

3.

B

4.

A

5.

C

6.

D

7.

C

8.

B

9.

B

10.

B






Beginner's Guide to DarkBASIC Game Programming
Beginners Guide to DarkBASIC Game Programming (Premier Press Game Development)
ISBN: 1592000096
EAN: 2147483647
Year: 2002
Pages: 203
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net