Challenge: Write Your Own Mod

Challenge: Write Your Own Mod!

As the final challenge for this book it is now your task to create your own game modification for the Racing Game. You can implement your own game idea or follow the process of coding the Speedy Racer mod.

As you saw at the very beginning of this chapter, there are quite a lot of mods available for the Rocket Commander game. More than 12 mods were written in 2006 alone and many more game projects were started and I bet more games and mods were made, but the people involved in that were either too shy to share their games or they did not want to mention that they used the Rocket Commander engine. It is of course also possible that I’m just not aware of more game modifications out there, which might be floating around somewhere on the Internet.

The racing game and the XNA Shooter have great potential for modding. Not only are these games less specific than the Rocket Commander game, but they also have more reusable engines, which allows for creating new games more quickly than starting from scratch, even if some of the used technology is not really required for the new game.

If you want to create your own mod and if you already have a certain idea you don’t need to read ahead about the Speedy Racer; go ahead and try to implement your own game idea first. In this chapter you learned enough to make incisions into the classes and change whatever you need to make your new game idea work.

Example Game: Speedy Racer

The Speedy Racer mod is not completely described here; it is still your challenge to create such a mod yourself, but I will give you everything you need to get started. If you are really lazy and don’t want to code your own mod or Speedy Racer yourself right now you can also just go ahead and install the game from the book CD, but I recommend trying to make the changes to the racing game yourself first before looking at the existing Speedy Racer code.

Step 1: Changing the Car Model

Because the mod had to be created quickly and I could not afford to pay a 3D modeler to make me a nice new car, I searched a little bit on the Internet for 3D models than can be used freely. I found a couple of nice cars, but most of them had too many polygons and others were in strange formats and I found no converters for them. After a while I gave up and just used one of the older 3D models I found earlier. Figure 14-21 shows an early version of this new Speedy Racer Car, which has about 21,000 polygons (compared to the 25,000 polygons of the original car in the Racer Game), but no material data set. I just added some boring red and black materials and the model was good enough to be exported and tested in the game. Later I added normal maps and a little texture mapping to the car model to make it look a little bit better. If you have more time for your project, try to do it better than me.

image from book
Figure 14-21

Step 2: Menu Changes

Changing the menu often involves a lot of textures and was always quite a bit of extra work on the Rocket Commander mods. The Racing Game is no different. Changing the menu did take some time, but only background textures and the used colors were changed; all the code could remain the same. Some of the menu logic was even simplified a little bit to avoid having to re-create certain textures again for the new mod.

If you would like to add more game screens, add more buttons to the main menu, or handle more options, and so on, it would probably help the most if you read the part about the game screens in this chapter again and try to figure out where the best place is to put any new code into the game.

Step 3: New Landscape and Objects

The Speedy Racer mod still uses the same landscape data as the original game, but I changed the landscape shader a little bit to make the game a bit more colorful and I changed everything into the blue color range. The shadow mapping and the post-screen shaders were also changed to make the game look a little bit different. See Chapter 8 for more details about the post-screen shaders and how to change them, especially the color correction shader part in PostScreenMenu.fx and PostScreenGlow.fx.

The following code is from the final post-screen rendering technique of the PostScreenGlow shader. You should be able to easily change the code for other visual effects and resulting colors. A good tip with shaders is always to go crazy first and then settle with more decent values. For example, if you want to test a blue look of the game, try adding 25% or even 50% to the blue color value and check the result. Maybe it does not look cool with blue or you like the craziness and settle with a value like 10% (which is a lot) for the blue color component. Or try playing around with the contrast values; there are always some variables you can tweak in most used shaders. The main goal of Speedy Racer was not to make it look highly realistic; it just should look different from the original Racing Game.

  float4 PS_ComposeFinalImage20(   VB_OutputPos3TexCoords In,   uniform sampler2D sceneSampler,   uniform sampler2D blurredSceneSampler) : COLOR {   float4 orig = tex2D(sceneSampler, In.texCoord[0]);   float4 blur = tex2D(blurredSceneSampler, In.texCoord[1]);   float4 screenBorderFadeout = tex2D(screenBorderFadeoutMapSampler,     In.texCoord[2]);   float4 ret =     0.75f*orig +     GlowIntensity*blur+     HighlightIntensity*blur.a;   ret.rgb *= screenBorderFadeout;   // Change colors a bit, sub 20% red and add 25% blue (photoshop values)   // Here the values are -4% and +5%   ret.rgb = float3(     ret.r+0.054f/2,     ret.g-0.021f/2,     ret.b-0.035f/2);   // Change brightness -5% and contrast +10%   ret.rgb = ret.rgb * 0.975f;   ret.rgb = (ret.rgb - float3(0.5, 0.5, 0.5)) * 1.05f +     float3(0.5, 0.5, 0.5);   return ret; } // PS_ComposeFinalImage20(...) 

Step 4: Driving Faster

To drive faster with the car in the game and still have a playable and enjoyable game you need to make two major changes to the game logic:

  • Make the roads much wider; this way you can drive faster through them. Also try to adjust the up vector for straight roads in a way that makes it easier to drive around curves.

    The code to change the basic road width can be found in the TrackVertex class of the Track namespace; just change the RoadWidthScale value to something crazy like 50 for testing and then settle for some reasonable value.

      /// <summary> /// Minimun, maximum and default road width for our track. /// </summary> public const float MinRoadWidth = 0.25f,   DefaultRoadWidth = 1.0f,   MaxRoadWidth = 2.0f,   RoadWidthScale = 13.25f; // [The constants are then used to generate the left and right track // vertices ...] /// <summary> /// Left side track vertex generation, used for the GuardRail class. /// </summary> /// <returns>Track vertex</returns> public TrackVertex LeftTrackVertex {   get   {     return new TrackVertex(       pos - RoadWidthScale * roadWidth * right / 2,       right, up, dir,       new Vector2(uv.X, 0),       roadWidth);   } // get } // LeftTrackVertex // [etc.] 

  • Make the car drive much faster. This can be done directly in the CarPhysics class by changing the following code. Constantly use the unit tests of this class to test out the new values. If they look ok try them in the real game.

      #region Constants /// <summary> /// Car is 1000 kg /// </summary> const float CarMass = 1000;//1000.0f; /// <summary> /// Gravity on earth is 9.81 m/s^2 /// </summary> const float Gravity = 9.81f; /// <summary> /// Max speed of our car is 275 mph. /// While we use mph for the display, we calculate internally with /// meters per sec since meter is the unit we use for everthing in the /// game. And it is a much nicer unit than miles or feet. /// </summary> public const float MaxSpeed =   275.0f * MphToMeterPerSec; /// <summary> /// Max. acceleration in m/s^2 we can do per second. /// We have also to define the max and min overall acceleration we can /// do with our car (very car specfic, but for this game always the same /// to make it fair). Driving backwards is slower than driving forward. /// </summary> const float MaxAccelerationPerSec = 5.0f,//120.0f,//1000.0f,   MaxAcceleration = 10.0f,//70.0f,//250.0f,   MinAcceleration = -6.0f;//-35.0f;//250.0f;//-40.0f; /// <summary> /// Friction we have on the road each second. If we are driving slow, /// this slows us down quickly. If we drive really fast, this does not /// matter so much anymore. The main slowdown will be the air friction. /// </summary> const float CarFrictionOnRoad = 17.523456789f;//15.0f;//2.5f; /// <summary> /// Air friction we get if we drive fast, this slows us down very fast /// if we drive fast. It makes it also much harder to drive faster if /// we already drive at a very fast speed. For slow speeds the air /// friction does not matter so much. This could be extended to include /// wind and then even at low speeds the air friction would slow us /// down or even influence our movement. Maybe in a game mod sometime. /// </summary> const float AirFrictionPerSpeed = 0.66f;//0.225f;//0.33f;//0.42f; /// <summary> /// Max air friction, this way we can have a good air friction for low /// speeds but we are not limited to 190-210mph, but can drive faster. /// </summary> const float MaxAirFriction = AirFrictionPerSpeed * 200.0f; /// <summary> /// Break slowdown per second, 1.0 means we need 1 second to do a full /// break. Slowdown is also limited by max. 100 per sec! /// Note: This would not make sense in a real world simulation because /// stopping the car usually needs more time and is highly dependant /// on the speed resulting in longer stopping distances. For this game /// it is easier and more fun to just always brake the same. /// </summary> const float BrakeSlowdown = 1.0f; // [etc.] 

Step 5: Adding Items and New Sounds

This part was actually the most work. To make the game more fun I added several items (more speed, focus view, road widener, and so on) and new sounds for them. Check out the files in the mod itself for more information about the new items. The code changes were also a bit of work, but not as much work as creating the items themselves and testing them.

Professional XNA Game Programming
Professional XNA Programming: Building Games for Xbox 360 and Windows with XNA Game Studio 2.0
ISBN: 0470261285
EAN: 2147483647
Year: 2007
Pages: 138

Similar book on Amazon
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer) © 2008-2017.
If you may any questions please contact us: