• 沒有找到結果。

Modification Process from a Pure 2.5D Game to a Hybrid or 3D Game 33

In this chapter, we describe a process for developing hybrid or fully 3D games from existing pure 2.5D ones. The programmer can gradually replace 2.5D entities with 3D ones in a 2.5D game, and accomplish the final 3D version by entirely replacing the 2.5D scene with a 3D scene. The developing process is divided into two sections. The first section describes how to update an existing 2.5D game or a hybrid game gradually till all its 2.5D classes have corresponding virtual classes, and the second section indicates how to construct a 3D game after the above condition succeeds.

Section 5-1 Developing process from a 2.5D(2.5D) game to a hybrid game

Process Initialize_2.5D_to_Hybrid :

Input : the 2.5D classes and their instances ID(s)

Output : the 2.5D classes and the existing instance ID(s) begin

1. Add sprite3D, “method_position3D”, “method_image3D” and replacing_class into the root class.

2. Synchronize the positions and images for each 2.5D entity and its sprite3D as Section 4-5 illustrates.

3. Set the replacing_class of each class to NULL.

end

34

Based on the discussion in Section 4.5, process, “Initialize_2.5D_to_Hybrid”, adds a 3D skin to each entity in a 2.5D game to solve the rendition of depth for the 3D display. Step 1 adds two attribute, sprite3D and replacing_class, and two methods,

“method_position3D” and “method_image3D” into the root class. Step 2 synchronizes the positions and images of each 2.5D entity and its sprite3D by these two methods.

These 2.5D entities retain their functions, and each of them has a sprite3D to solve the problem for depth rendition. On the other hand, step 3 set the replacing_classes as

1. Select an appropriate 2.5D class to be the parent class of the virtual class.

2. Build a virtual class to add a 3D entity.

3. Add the method_control3Ds into the virtual class.

4. Modify the replacing_class of the class if the 2.5D class will be replaced by the 3D class of the replacing_class eventually.

end

Process, “Upgrade_Hybrid_with_a_3Dentity”, may add 3D features into a hybrid game repeatedly by adding 3D entities into the game as pervious chapter illustrates. Before adding a 3D entity, step 1 selects an appropriate 2.5D class to be the parent class of the virtual class as discussed in Section 4-3 . When the virtual class is

35

built in step 2 as discussed in Section 4-2 , step 3 adds the method_control3Ds to synchronize the attributes of the v-entity and 3D entity such as the synchronization of the coordinates. The method_control3Ds is also used to control the 3D entity for exception handling. Besides, step 4 modifies the existing value of the selected 2.5D class to be a name of entity3D if the 2.5D class will be replaced by the 3D class of its replacing_class in the following section.

36

Section 5-2 Developing process from a hybrid game to a fully 3D game

After the pervious processes, “Initialize_2.5D_to_Hybrid” and

“Upgrade_Hybrid_with_a_3Dentity”, the game under development is now a hybrid game. Once all the entities in the 2.5D scene are 3D ones, the hybrid game can be developed into an entire 3D one. However, because the scene of a hybrid game is still a plain graph, the game may not provide complete 3D features. For example, the 2.5D-3D hybrid version only uses z-axis values to simulate the depth sequence of entities as Figure 4-12 shows, and each entity actually moves on direction of x-axis and y-axis. However, the 3D entity can be moved on the direction of z-axis in the fully 3D version. Therefore, the hybrid game is replaced its 2.5D scene by a 3D stage so that it can be upgraded to a fully 3D game.

Process Modify_Hybrid_To_3D :

Input : the classes

Output : the 3D classes, the existing instance ID(s) and success : boolean Begin

0. success=true.

1. If the replacing_class of each 2.5D class is NULL, then return success = false.

2. Replace the 2.5D scene by a 3D stage.

3. Modify declaration of each existing instance from virtual class to 3D class.

4. Modify the properties of each existing instance and use the methods of its 3D specification classes.

end

Therefore, step 1 checks the replacing_class of each 2.5D class to ensure that all

37

2.5D classes can be replaced by the 3D classes. The replacement can not be done when a replacing_class of a class is null. During the replacement, step2 deletes the 2.5D scene and builds a new 3D scene by adopting the 3D class, “Plane”. It sets the properties of the 3D plane based on the ones of the 2.5D scene such as size and graph.

If there are some scenic entities in the graph of the 2.5D scene, it may put the real 3D entities like trees and rocks in the 3D plane for more reality. Figure 5-1 (1) illustrates a hybrid scene. To transform the hybrid scene into a pure 3D scene, the 2.5D scene is replaced by a 3D plane as Figure 5-1 (2) shows. Then, the properties of the 3D plane are further adjusted to be the similar ones of the 2.5D scene, such as size and 20*20 grids as Figure 5-1 (3) illustrates.

Figure 5-1 (1) The hybrid gam (2) The 3D plane replaces the 2.5D scene

(3) Adjust the properties of the 3D scene

38

Once the 3D scene is built, the 3D entities use the z-axis values in the hybrid game entirely. However, the 3D entities co-operate with the v-entities for the motion and interaction based on the framework of the hybrid game as discussed in Chapter 4 . Step 3 modifies declaration of each existing instance from the names of virtual class to the corresponding ones of its entity3D because the virtual classes are no longer needed in this modified game. Therefore, the existing instances have been the 3D class instances after this step.

Besides, these instances still work by the attributes and functions of virtual classes. Therefore, the properties of 3D entities need to be modified for running associated with the 3D plane. For example, when the programmer adopts the 3D plane in Figure 5-1 (3), he may discover that the 3D entities look weird in the scene because the properties such as angle, motion and interactions of the 3D entities are still set based on the features of the replaced 2.5D scene. Step 4 adjusts the properties of the 3D entities and uses the methods of 3D classes. Take the angle of the 3D entities as an example, after the step 4 adjusts the angles of the 3D entities, the total 3D scene displays as Figure 5-2 (1) shows. Figure 5-2 (2) shows a different viewpoint through changing the angle and coordinate of the camera.

39

Figure 5-2 (1) Adjust the properties of (2) Change the angle and coor-

the 3D entities dinate of the camera

The motion codes of the 3D entities in the hybrid version are of 2.5D motion as Figure 5-3 (1) shows, and they should be changed as 3D ones like Figure 5-3 (2) shows. The function, “motion_f3D”, makes each entity move in the 3D world based on the 3D plane and xyz-axis values.

Figure 5-3 (1)2.5D motion of the 3D entities (2) 3D motion of the 3D entities

40

The interactions of each 3D entity in the hybrid game use the interaction detection from the v-entities, but they are not enough for the 3D world. A typical example is the collision of z-axis. Because the method of interaction detection from the v-entities does not use z-axis value for interaction detection in the 2.5D scene, it is no longer used for interactions in the 3D stage. The detection methods in general 3D library is adapted instead. For example, each 3D entity receives the message from the function, “canMove”, for collision detection discussed in Chapter 4 , and it should be changed as the function, “collision_f3D”, which is used for collision detection between the 3D entities based on 3D library. As Figure 5-4 shows, “collision_f3D” compares the sum of radius and the distance between any two 3D entities. If the sum of their radiuses is greater than the distance, a collision occurs between them. It provides the collision detection not only in 2.5D plane but also in 3D world because it uses the xyz-axis value.

Figure 5-4 the function of collision detection in fully 3D game

41

After finishing this developing process, the modified game becomes a fully 3D game. This game may start to provide some 3D features like switching the angle of view and zooming for the 3D world. Therefore, the programmer may add some functions for putting additional 3D features through the 3D library. For example, we add a function for switching the angle of view in the previous example in Figure 5-2. The function, “onEnterFrame3D”, controls the position and angle, representing the viewpoint of the user as Figure 5-6 illustrates. There is a collision between the cubes, and we may see the 3D world from different viewpoints in Figure 5-5.

Figure 5-5 The game world from different viewpoints

42

Figure 5-6 The function for switching the angle of view

43

相關文件