Introducing Speech API

Application programming interfaces APIs are present all over the Windows environment, offering high-level interfaces that allow applications to access device features. By device, we mean not only physical devices, such as joysticks or graphics acceleration boards, but also logical devices, like the ODBC or OLE DB devices for data access, or the focus of this section, the interface for speech engines. Speech engines are special drivers that control speech recognition and or speech generation...

Reward

There are many different levels of rewarding, and they are related to one another. If you achieve the right balance of rewarding, depending on your game goal and type, you will succeed in capturing the player. Now that, my friend, is a bold statement. Let's look at this as some rules within a specific time span, say between two character levels, or between the first upgrade and the second. First the different aspects, and then some more comments on each. The player needs to be rewarded often...

The Sprite Class

Here we'll attempt to create a generic Sprite class, which can be improved upon as needed, and can be use lt to create derived classes that can hold specific properties and methods according to the game being created. We can use the basic interface for sprites defined in Chapter 2, with the New,Draw, and Load methods, and some simple properties. Looking back at Chapter 3, we can list some suggestions for other interface elements values for the translation, scaling, and rotation operations in...

Presenting the DirectX TopLevel Objects

When programming DirectX 9.0 or earlier with nonmanaged pre-.NET languages, we have to create a maste object of type DirectXn where n is the main number of the DirectX version, for instance, DirectX8 for the 8.1 version , and everything can be created from this object. In the managed version of DirectX 9.0, we can directly create the second-level objects, as listed here Direct3D for access to the 3-D acceleration layer. Direct3DX for access to utility functions to make coding easier such as...

Creating the Mouse and Keyboard Initialization Code

TheKeyboard class interface is shown in the next code listing the interface for the mouse devices is very similar, with a few differences discussed later. Imports Microsoft.DirectX.DirectInput Imports Microsoft.DirectX Imports System.Threading ' General use properties and enumerations Private InputDevice As Device Nothing Private InputThread As Thread Nothing Public Shared keyboardState As keyboardState Public Event Keypress Keycode As Keys Public Sub New Parent As Window.Control.Forms Public...

Creating the Class Diagram

In our project we'll ose the base classes for the vame engine1 svrite, and mouse control, and then create derived classes according to our garnet specific needs. Well also create a new class to control DirectShow sreaming media paying features. Using the experience we gained in the last chapter, wet ran devire three new classes a game control class, derived trom clsGameEngine, that will be called clsKinderEngine an active objects control class, derived from clsSprite, named clsActiveObj ect and...

D Coordinate Systems and Projections

Even if we have no interest in creating 3-D games, we must understand the basic concepts of a 3-D coordinate system, because everything we do in Direct3D is defined by points and images in a 3-D world. Of course we can ignore the z axis and pretend that we are in a 2-D world and we'll see how to do this but the z zeroed value will still be there. When we are dealing with three Cartesian dimensions, there are two types of coordinate systems left-handed and right-handed. These names refer to the...

Adding the Final Touches Dbz

Given the sample game's simplicity, there is little room for improvement in this chapter, but we can always add some extra touches to our games to improve payability. In this chapter's sample game, after playing a few dozen times, we feel that using the Pocket PC buttons interface is not as simple as using a keyboard, since on a keyboard we can use more than one finger at once on the navigation keys to control the blocks. We can't solve this issue, but we can increase the game rewards so...

fiit

Figure 7-6 The same bouncing movement, without squash and stretch We must use this same idea when animating characters, especially in jumping sequences and when hitting or being hit by an obstacle. Figure 7-7 shows the same concept used for a jumping rabbit character. Figure 7-7 A squashing and stretching jumping rabbit Figure 7-7 A squashing and stretching jumping rabbit Although we can create a jump by just moving a character up and down, including squashing and stretching will make that...

Proximity Algorithms

Another type of algorithm commonly used to calculate object overlapping is the proximity algorithm. Proxy algorithms are somewhat similar to the bounding boxes algorithm, depending on the formula used. The basic idea behind such algorithms is to calculate the distance between the centers of two objects, and then check the value against a formula that describes approximately the objects' shapes. This method is as p recise as the formula used to approximate the object shape for example, we can...

The Netterpillar AI Class

As we decided in the game proposal a net in thu game project, we only need to use a simple form of artificial intelligence. Just avoid walls and eat mushrooms if they are near, that's all. Public Class clsAINetterpillar Inherits clsGameEngine Private andomfercent As Integer 5 Function As Point, _ CurrentDirection As clsSprite.enDirection As clsSprite.enDirection Function RandomDirection CurrentLocation As Point, _ ChoosenDirection As clsSprite.enDirection As clsSprite.enDirection End Class...

The Netterpillar Class

TheNetterpillar class will control the drawing of the netterpillar characters on screen, both for human-controlled and computer-controlled ones. It'll have some methods for making the netterpillar bigger when it eats a mushroom and to store the bitmaps and current status for the character. Table 2-7 lists the initial suggestion for the members of this class, along with a short description. Table 2-7 The Members of the Netterpillar Class Table 2-7 The Members of the Netterpillar Class We'll have...

Overview Ixl

In this chapter, we'll improve the .Netterpillars game created in Chapter 2 to include multiplayer features seeFigure 8-1 . We'll create two new options Host a Death Match and Join a Death Match, which will respectively set up a DirectPlay session to receive connections from other computers and connect to a DirectPlay session on a remote computer, allowing two players to compete against one another across the network. Figure p-1 .Netterpillars I this chapters fample gam In the coming sections,...

The Sprites New Method

As for the constructor of the class, we can define many different overloaded functions for it a method that receives no parameters to be implemented by the derived classes, if needed , a method that receives the sprite image name, and two others that receive the initial position of the sprite and the color code to be used as a transparent color. If we need more overloads, we can create them as the project evolves. Observe that, in order to simplify the New code, we create a private Load method,...

Creating Nonrectangular Windows

Creating nonrectangular windows can help usto come up with customized window shapes that may improve the visual appearance of our game. Perhaps the most common example of a program that uses this resource is Windows Media Player, in which each skin we choose implies in a different window shape. To change a window's shape, all we need to do is to set the Region to a previously created graphics path. We talked about graphics paths when introducing GDI in Chapter 1, and used them to draw...

Create Border Tiles

To create border tiles, we must separate the tiles into groups that will have connections with each other, and then create the borders for the tiles in each group. We must do this because usually some tiles won't need to have borders with some of the others for example, the tiles that will create internal parts of a building don't need to have any special border with the outside tiles. Within every group, create the border tiles between each type of terrain. There are basically three types of...

Understanding Devices

DirectX offers a special object type, Device, which allows us to have access to the 3-D acceleration layer. We can choose up to three types of devices for each adapter Hardware Hardware Abstraction Layer When creating HAL devices, we have direct access to the hardware acceleration features and increased speed . If we try to create a device of this type but have no 3-D acceleration board, DirectX will raise an error and won't create the device. Reference Reference Rasterizer This type of device,...

E

bcrJc-r -i .yjg IwiderS.hp boidciiHU.t j boiSciiill. Hp OnUlcr .H ti rie c Si J bcrJtcihl . ip bo df .b-p baTdcrSwj.bifj Figure 4-12 The names of the border tiles The N, S, W, and E borders are used as island borders and as lake borders by just exchanging positions. We can remake the screen from Figure 4-10 to add the borders, resulting in the screen shown in Figure 4- Figure 4-13 A second screen, based on a larger set of tiles Initially it may seem as toou these are the only tiles we'll ever...

Texturing and Coloring with Flexible Vertex Formats

Direct3D gives us the power to choose how we can define the vertices that will compose our drawing primitives, using the so-called flexible vertex formats FVF . Before creating a vertex buffer explained in the previous section , we must specify which kind of information each vertex will hold, creating a custom vertex structure and using it when creating a new vertexBuffer object, as presenUed in t he next code sample Vbuffer New VtrtexBuffer VertSize, VertNum, Deviue, Usage, VertexFormat, Pool...

Polling the Devices

As we saw earlier in the section Defining the Input Classes, the initialization code for each device must start a new thread, which will be responsible for gathering data from the device in a continuous loop. On the polling loop, shown later in this section, we'll go through the following steps 1. Poll the device to check if we have access to it using the Poll method of the inputDevice object . 2. If we dont have access, try to acquire it using the Acquire method of the inputDevice object . 3....

Processing the Joystick Input

The last input device method, GetJoystickState, will deal with the JoyState structure. As mentioned before, this structure has many attributes that will be filled according to the joystick type. In order to guarantee that our class will work even with the simplest joysticktype peripheral, we'll keep it as simple as possible but some processing will still be needed. We'll generate the JoystickPressed event according to the Buttons array, simply by passing the button index to the application and,...

Adding Support for ForceFeedback Joysticks

When dealing with joysticks, an interesting feature is to include force-feedback control in our games, so the user can enjoy a more interactive experience. When creating force effects, there are two basic approaches loading the effects from a previously created effect file, or creating the effect from scratch for our program. The effect files are created with the Force Editor, a tool that comes with the DirectX SDK for creating and testing force-feedback files. It saves the effects into files,...

Creating a Speech Generation Game Class

To add extra functionality to our speech generation class, besides the speech generation and events we saw in theprevious section, we'll create a method that translates the viseme codes into actual player images, chosen among predefined mouth positions stored as images. To generate these images, we'll simply apply the mouth positions we saw in Figure 7-15 to our character's head. Since the speaking head won't move its shown in a square at the bottom of the screen , we won't have to deal with...

The Game Proposal Iav

In this chapter, we'll create a very simple adventure game named Magic Kinder-garteN. While our adventure is simple, it must still address some of the most common problems encountered when coding a complex adventure Choosing verbs, or actions, with the mouse pointer right button changes the mouse pointer icon . We'll use the verbs Walk to, Use, Talk, Take, and Examine. Controlling an inventory to show the objects carried by the player. Using objects from the inventory with other objects on...

Further Improvements 1

We saved the best fot 'ast What about creatiug new intelligent characters for our game, maybe some opposition like a spider who eats the netterpiliars In the code for this chapter on the ramples CD-ROM, you will find an almost fully working spider character. We already did all the dirty work the Spider and AISpider class interfaces, the call to the moving functions at th MoveComputerCharacters routine and at the Render and Redraw method of the objGameEngine almc everything is there. The code...

Updating the Game Form

After updating the game classes, we'll seed to modify the game form to adapt to these updates. We'll need to update the form Load event, the Click event of the Start button, and the Tick event of the timer. Besides these changes, we'll have to add code for the extra interface buttons we created for the Pocket PC version. Let's look at each os these updates in detaN. Starting with the norm's LoaM event, we need to include a call to the initialize method of the GameEngine class so the back...

Include Extra Transition Tiles

For those transitions fhat w ll be presented most of the time to the player, include some different tiles for each transition and for the basic pet1 which will be used sparingly to brea k down the feeling of patterns of repetition. For example, when creating tiles between water and land, include some rocks, a bay, or a larger beach, so you can use them eventually to give more variation to the game visual. Examples of simple variations are shown in Figure 4-4. .hnji .hnji

First Step Coding the Main Window

Let's start coding the main window, which will allow us to see our hardware capabilities, and then we can code the tests one by one, from the simpler to the most complex ones. After creating the main window, as shown in the visual prototype in the project phase, we need to know the functions that list the adapters, devices, display modes supported, and capabilities. A quick look in SDK help shows us these methods and properties of the Manager object s Adapters. Count l Returns the number...

API for Converting Text to Speech

To control text-to-speech TTS devices, after setting the proper reference to the speechLib reference, all we need to do is to create an spVoice object and call the speak method to generate the speech from text data. The complexity of the speech generation is so well hidden from the application that we can create a Hello World speaking application with only three lines, as shown in the next code sample Dim voice As SpeechLib.SpVoice Set voice New SpeechLib.SpVoice voice.Speak Hello World,...