Danh mục

3D Game Programming All in One- P10

Số trang: 30      Loại file: pdf      Dung lượng: 355.33 KB      Lượt xem: 15      Lượt tải: 0    
Jamona

Phí tải xuống: 20,000 VND Tải xuống file đầy đủ (30 trang) 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- P10: 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- P10 Server Control Modules 177 client = %this; // the avatar will have a pointer to its }; // owners GameConnection object %player.SetTransform(%spawnPoint); // where to put it // Update the camera to start with the player %this.camera.SetTransform(%player.GetEyeTransform()); %player.SetEnergyLevel(100); // Give the client control of the player %this.player = %player; %this.setControlObject(%player);}function GameConnection::OnDeath(%this, %sourceObject, %sourceClient, %damageType,%damLoc){ // Switch the client over to the death cam and unhook the player object. if (IsObject(%this.camera) && IsObject(%this.player)) { %this.camera.SetMode(Death,%this.player); %this.setControlObject(%this.camera); } %this.player = 0; if (%damageType $= Suicide || %sourceClient == %this) { } else { // good hit }}//============================================================================// Server commands//============================================================================function ServerCmdToggleCamera(%client){ %co = %client.getControlObject(); if (%co == %client.player) { %co = %client.camera; %co.mode = toggleCameraFly; } else { %co = %client.player; Team LRN178 Chapter 5 ■ Game Play %co.mode = observerFly; } %client.SetControlObject(%co); } function ServerCmdDropPlayerAtCamera(%client) { if ($Server::DevMode || IsObject(EditorGui)) { %client.player.SetTransform(%client.camera.GetTransform()); %client.player.SetVelocity(0 0 0); %client.SetControlObject(%client.player); } } function ServerCmdDropCameraAtPlayer(%client) { %client.camera.SetTransform(%client.player.GetEyeTransform()); %client.camera.SetVelocity(0 0 0); %client.SetControlObject(%client.camera); } function ServerCmdUse(%client,%data) { %client.GetControlObject().use(%data); } // stubs function ClearCenterPrintAll() { } function ClearBottomPrintAll() { } The first function in this module, OnServerCreated, is pretty straightforward. When called, it loads all the specific game play modules we need. After that comes StartGame, which is where we put stuff that is needed every time a new game starts. In this case if we have prescribed game duration, then we start the game timer using the Schedule function. Schedule is an extremely important function, so well spend a little bit of time on it here. The usage syntax is: %event = Schedule(time, reference, command, ) The function will schedule an event that will trigger in time milliseconds and execute com- mand with parameters. If reference is not 0, then you need to make sure that reference is set Team LRN Server Control Modules 179to be a valid object handle. When the reference object is deleted, the scheduled event is dis-carded if it hasnt already fired. The Schedule function returns an event ID number that canbe used to track the scheduled event or cancel it later before it takes place.In the case of our game timer, there is no game duration defined, so the game is open-ended, and the Schedule call will not take place. If, for example, $Game::Duration had beenset to 1,800 (for 30 minutes times 60 seconds per minute), then the call to schedule wouldhave had the first parameter set to 1,800 times 1,000, or 1,800,000, which is the numberof milliseconds in 30 minutes.OnMissionLoaded is called by LoadMission once the mission is finished loading. All it reallydoes is start up the game play, but this is an ideal location to insert code that needs toadjust its capabilities based upon whatever mission was loaded.The next function, OnMissionEnded, is called at the conclusion of the running of a mission,usually in the DestroyServer function. Here it cancels the end-of-game event that has beenscheduled; if no game duration was scheduled—as is our case at the moment—then noth-ing happens, quietly.After that is the GameConnection::OnClientEnterGame method. This method is called when theclient has been accepted into the game by the server—the client has not actually enteredthe game yet though. The server creates a new observer mode camera and adds it to theMissionCleanup group. This group is used to contain objects that will need to be removedfrom memory when a mission is finished. Then we initiate the spawning of the playersavata ...

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