Controlling Players and Characters

Controlling Players and Characters

Controlling Players and Characters(41)      摘要: All your hard work is about to pay off with a demonstration of the character and
spell controllers seen in this chapter.

Upon executing the program, you see the scene shown in following snap. 
 
Controlling Players and Characters(40)      摘要: Things are winding down with the controller at this point. You use the following
functions to equip, use, and drop an item: 
 
Controlling Players and Characters(39)      摘要: Once characters take enough damage, they die, and when that happens, the following
function is called: 
 
Controlling Players and Characters(38)      摘要: Coming up is a huge collection of functions you use to retrieve and set the specific
information about a character (related to the artificial intelligence functionality or
actions): 
 
Controlling Players and Characters(37)      摘要: Whenever a character needs updating, rendering, or what have you, a pointer to
the linked list of characters is needed in order to iterate the list. Either that or
maybe your application needs access to the character data. Either way, the following
functions will help you out:  
 
Controlling Players and Characters(36)      摘要: Notice that I keep talking about removing characters from the list. What about all
the hard work you’ve put into your PCs—how are you ever going to store their
achievements for later loading? With the following set of saving and loading functions,
of course!  
 
Controlling Players and Characters(35)      摘要: You're coming to the end of the long haul. You’ve finished the private data and
functions, and the public functions are left:  
 
Controlling Players and Characters(34)      摘要: Once it is determined what action each character wants to perform, that action
must be validated. Characters moving around can’t walk through other players
(except for PCs, who can walk through other PCs). Also, depending on your levels,
you use a function to determine character-to-map collisions. These two validation
functions are as follows:  
 
Controlling Players and Characters(33)      摘要: The next two functions to come along work in conjunction with the update functionality
of the class. At every frame that a character needs updating, a specific
function is called to update the character’s actions. This specific function is dependent
on the type of character being updated; for PCs, that specific function is
pc_update (which is overridden by you in order to control your player).  
 
Controlling Players and Characters(32)      摘要: The brains of the character operation is the cCharController class,
which is probably the biggest non-game core class you’ll work with.

The cCharController class maintains a list of active characters, each character
being stored within a sCharacter structure. For each type of character, there is a
matching entry into an array of sMeshAnim structures (and a matching sCharAnimInfo structure).  
 
Controlling Players and Characters(31)      摘要: To start, each character needs a definition, which is pulled from the master character
list. You store this definition value in the def variable. To tell similar
characters apart, you assign a unique identification number (ID) to each one.
Think of using identification numbers as you use names. Instead of adding a character
named “George” into the game during play, you refer to that same character
as character 5. 
 
Controlling Players and Characters(30)      摘要: The character definitions are templates by nature, so you really need to load up the
definitions and work with them on a per-instance basis. This means that you need
to come up with a controller that loads the definitions and tracks each instance of
a character in your game. What you need is a character controller class. 
 
Controlling Players and Characters(29)      摘要: master character list edit source: 
 
Controlling Players and Characters(28)      摘要: You create and use a master character list (MCL) much like you use the master
item list (MIL) to define objects in your game. Before using them in your game,
you need to design every character, complete with appearance (3-D mesh) and
functionality (abilities and attributes). This character information is stored in the
sCharDef structure.  
 
Controlling Players and Characters(27)      摘要: Now, you can put all the neat spells that your game has to offer to good use. You
know how spells work, but you need to know how the spells affect the characters.
Remember that the spell controller tracks only the meshes that create the visual
side of spells; the character controller determines the effects of the spells.  
 
Controlling Players and Characters(26)      摘要: When a character takes a swing at another character, this action triggers the
process that determines whether the blow hit the target. Determining whether the
attack hit involves an attacking character’s to-hit ability and a defending character’s
agility ability. Remember that the higher the ability values, the better the chance to
hit or dodge the attack.  
 
Controlling Players and Characters(25)      摘要: After a spell triggers and the effects are processed, what happens? As I’ve previously
mentioned, spells only affect characters, so only the character controller engine
should modify the character’s data. In the section “Creating a Character Controller
Class,” later in this chapter, you find out how to process spells in regard to characters.  
 
Controlling Players and Characters(24)      摘要: Because the spell controller is needed only for tracking the spell meshes and
animation, the class definition is relatively small  
 
Controlling Players and Characters(23)      摘要: Controlling spells is a matter of tracking the meshes and animations that represent
the spell and then processing the spell’s effects on their intended targets. Because
the spell’s effects are really related to the characters, it’s best to let the engine that
controls the characters handle the spell effects and leave the spell animation up to
a spell controller class object. 
 
Controlling Players and Characters(22)      摘要: Creating MSL edit

main window design: 
 
Controlling Players and Characters(21)      摘要: Defining your game’s spells by manually constructing a bunch of sSpell structures
can quickly become tedious. Instead, you need an editor that is better suited to
quickly change every aspect of your game’s spells. Welcome to the MSL Editor!
 
Controlling Players and Characters(20)      摘要: Spell effects usually target a single player, but this is not always the case. At times,
the spell is either targeted at the spell caster or all the characters within an area.
Also, not all characters can be affected by a spell. A spell cast by a monster, for
example, should not hurt other monsters, just PCs. In the same vein, spells cast
by PCs should be directed only toward monsters. 
 
Controlling Players and Characters(19)      摘要: The functional component of a spell does the real work. Once a spell runs through
its animation and reaches its intended target, the damaging or beneficial effects
need to be dealt with. 
 
Controlling Players and Characters(18)      摘要: Resources are commodities, so characters will want to buy and sell their wares from
and to each other. Only specific characters in a game are open to bartering. These
characters are commonly called “shopkeepers” because they tend to appear only in
stops. You know the drill—enter a shop, approach the counter, and begin dealing.  
 
Controlling Players and Characters(17)      摘要: Resource management plays a major role in your game. For characters to really get
anywhere or achieve anything, they may need the aid of the items, spells, and other
objects you’ve constructed for your game.  
 
Controlling Players and Characters(16)      摘要: I’m going to assume that you are comfortable working with action templates and
scripts at this point. The following action template provides an example of using a
derived script class:  
 
Controlling Players and Characters(15)      摘要: Scripting keeps popping its head up throughout these last few chapters, and true
to form, scripting plays a major role when dealing with characters. Scripts work
with conversations, spells, character movement, and much more. 
 
Controlling Players and Characters(14)      摘要: To get things rolling, take a look at the following cTextWindow class definition:  
 
Controlling Players and Characters(13)      摘要: Ever get the feeling you aren’t in control? With your role-playing game that just
might seem like the case. However, when scripting comes into play, you want to
control the PCs at times—for example, to advance the story in some way. This
involves automatic control.  
 
 
Controlling Players and Characters(12)      摘要: Although following another character might seem complicated at first, don’t worry
too much. Remember that keeping it simple is the solution. Following a character
is as easy as walking a route. Because a character already knows its own coordinates
and the coordinates of the character it is following, you can use previously seen
functions to move the character toward another one.  
 
Controlling Players and Characters(11)      摘要: To determine the distance away from a route point, you can use the standard
Pythagorean Theorem, but in order to speed things up, you can toss the sqrt
operation out the door and use the sum of the squares of the lengths instead.
To see what I mean, take a look at the following two lines of code:  
 
Controlling Players and Characters(10)      摘要: As you’ve been able to surmise from the past few sections, controlling the player is
relatively simple. Now comes the tough part—controlling the game’s NPCs. This
section shows you the various methods of navigating your game’s NPCs.


Although games might trick you into thinking some elaborate scheme is moving
the NPCs around the world, that just isn’t the case.  
 
Controlling Players and Characters(9)      摘要: Rotational control allows the player to rotate the character using the left and right
arrow keys and forward and backward using the up and down arrow keys.

Rotational control is better than directional control is some aspects, because the
movement calculations are more basic. Characters need to store a directional value
now, however, that represents the direction they are facing (with 0.0 pointing along
the positive Z-axis, 1.57 pointing along the positive X-axis, 3.14 p  
 
Controlling Players and Characters(8)      摘要: Your player is the most important character in the game, so you need complete control
of him. Typical games utilize a simple directional control scheme, similar to the
scheme you read about in the section “Player Navigation.” 
 
Controlling Players and Characters(7)      摘要: Up to this point, only the functionality of a character has been discussed. The reality is that functionality is the only part that really matters, but game players will want some sort of visual representation of their digital alter ego. With the power of a 3-D modeler and the Graphics Core, you’ll have no problem tackling the graphics portion of your characters.  
 
Controlling Players and Characters(6)      摘要: You contend with NPCs much as you contend with PC controls, except that the
game engine handles all aspects of an NPC’s controls. This difference creates some
tough design and programming situations, and you must develop an artificial intelligence
system that can mimic believable behavior.  
 
Controlling Players and Characters(5)      摘要: The world revolves around your PC, so most of your game development will go into
controlling him. PCs have the most actions and options available to them. Other
than those character actions previously mentioned, PCs have the option of managing
their game resources, which includes items and magic spells. In addition, character
building is used to build up the strength of the character.  
 
Controlling Players and Characters(4)      摘要: Characters come in all shapes and sizes—big ones, little ones, even short and furry
ones. The fact is that some characters have different attributes that make them special.

For every different type of character in your game, there is a matching character
class. You can think of character classes as being a way to differentiate the different
species of characters in your game. Going even further, classes can determine a
specific type of character in a species.  
 
Controlling Players and Characters(3)      摘要: Character’s attributes are much like abilities, except that attributes define a different
aspect of a character. Your physical health is an attribute, for example; it varies
depending on how much injury a character sustains. These injuries can be healed
and, as such, the health of the character is increased.  
 
Controlling Players and Characters(2)      摘要: Employing characters into your game is one of the most difficult jobs you’ll face.
Even at a basic level, the code needed to control gaming characters can be convoluting.
What’s a lowly programmer to do? Just take it slow, work from the begin-ning, and all will be well.

In this section, I introduce you to some basic concepts common to most roleplaying
games. These concepts include defining a character’s basic abilities (which
include strength, intelligence, agility, and   
 
Controlling Players and Characters(1)      摘要: A gaming world is nothing without players and monsters running around.
Nevertheless, creating them can be a little daunting at first. But don’t worry.
In this chapter, you can find the basic information you need to create characters
and give them a life of their own in your game—all in an easy-to-follow format.
In this chapter, you learn how to do the following:  

你可能感兴趣的:(Controlling Players and Characters)