Danh mục

3D Game Programming All in One- P9

Số trang: 30      Loại file: pdf      Dung lượng: 492.12 KB      Lượt xem: 24      Lượt tải: 0    
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

3D Game Programming All in One- P9: During the past several years while working on the Tubettiland “Online Campaign” softwareand more recently while working on the Tubettiworld game, I figure I’ve receivedmore than a hundred queries from people of all ages about how to get started makinggames. There were queries from 40-year-olds and 13-year-olds and every age in between.Most e-mails were from guys I would estimate to be in their late teens or early 20s.
Nội dung trích xuất từ tài liệu:
3D Game Programming All in One- P9 Client 147//============================================================================function Toggle3rdPPOVLook( %val )//----------------------------------------------------------------------------// Enable the free look feature. As long as the mapped key is pressed,// the player can view his avatar by moving the mouse around.//----------------------------------------------------------------------------{ if ( %val ) $mvFreeLook = true; else $mvFreeLook = false;}function Toggle1stPPOV(%val)//----------------------------------------------------------------------------// switch between 1st and 3rd person point-of-views.//----------------------------------------------------------------------------{ if (%val) { $firstPerson = !$firstPerson; }}//============================================================================// keyboard control mappings//============================================================================// these ones available when player is in gameplayerKeymap.Bind(keyboard, up, GoAhead);playerKeymap.Bind(keyboard, down, BackUp);playerKeymap.Bind(keyboard, left, GoLeft);playerKeymap.Bind(keyboard, right, GoRight);playerKeymap.Bind( keyboard, numpad0, DoJump );playerKeymap.Bind( mouse, xaxis, DoYaw );playerKeymap.Bind( mouse, yaxis, DoPitch );playerKeymap.Bind( keyboard, z, Toggle3rdPPOVLook );playerKeymap.Bind( keyboard, tab, Toggle1stPPOV );// these ones are always availableGlobalActionMap.BindCmd(keyboard, escape, , quit(););GlobalActionMap.Bind(keyboard, tilde, ToggleConsole); Team LRN148 Chapter 4 ■ Game Programming //============================================================================ // The following functions are called from the client common code modules. // These stubs are added here to prevent warning messages from cluttering // up the log file. //============================================================================ function onServerMessage() { } function onMissionDownloadPhase1() { } function onPhase1Progress() { } function onPhase1Complete() { } function onMissionDownloadPhase2() { } function onPhase2Progress() { } function onPhase2Complete() { } function onPhase3Complete() { } function onMissionDownloadComplete() { } Right off the bat, a new ActionMap called playerKeymap is created. This is a structure that holds the mapping of key commands to functions that will be performed—a mechanism often called key binding, or key mapping. We create the new ActionMap with the intent to populate it later in the module. Then we define the 3D control (TS, or ThreeSpace) we call PlayerInterface (because thats what it is), which will contain our view into the 3D world. Its not a complex definition. It basically uses a profile defined in the common code—something well explore in a later chapter. If we want to use our mouse to provide view manipulation, we must set the noCursor property of the control to 1, or true. Team LRN Server 149Then we define a method for the PlayerInterface control that describes what to do whenthe control becomes active (wakes up). Its not much, but what it does is activateDirectInput in order to grab any user inputs at the keyboard or mouse and then make theplayerKeymap bindings active.Next, we define a callback method for the GameConnection object (you know, the one wecreated back there in control/main.cs). The engine invokes this method internally whenthe server has established the connection and is ready to hand control over to us. In thismethod we assign our player interface control to the Canvas we created earlier in theInitializeClient() function in the control/initialize.cs module.After that, we define a whole raft of motion functions to which we will later bind keys.Notice that they employ global variables, such as $mvLeftAction. This variable and otherslike it, each of which starts with $mv, are seen and used internally by the engine.Then there is a list of key bindings. Notice that there are several variations of the Bind calls.First, there are binds to our playerKeymap, which makes sense. Then there are binds to theGlobalActionMap; these bindings are available at all times when the program is running, not justwhen an actual game simulation is under way, which is the case with a normal action map.Finally, there is a list of stub routines. All of these routines are c ...

Tài liệu được xem nhiều: