2D Fighter/Arcade game

From Valve Developer Community
Jump to navigation Jump to search

THIS CODE IS OBSOLETE!

This page is for Archive purposes. None of the tutorial below is working as of 2022. The links are dead - do not try clicking them.

But you can still download the source code here

Antfarm Source

The basic idea and code for such a mod can be found here. (If link is offline: Link ;) Be aware, Antfarm: Source is in no way complete. For example, to have an online lag-free third person experience one must create all local player animations on the client. Notes for potential improvements are listed at the end of this page.

For those that wish to create a top-down 2D game, after making the corrections to the Antfarm patch below, you can try applying the Overhead Patch. It may not patch cleanly, but with some analysis of the straight-text .patch file it should not be difficult to manually enter anything that doesn't work automatically.

Corrections to Antfarm Patch

The current status of the Antfarm project is unknown, but only about half of the source code replacements in the patch provided by Antfarm actually work with the current SDK. If you understand a little about what a diff output tells you, which is used by the patch utility to convert the mod to 3rd person, then take a look at the .patch file. You'll see clearly that it's just the output of a diff. From there you can make all the source code modifications by hand, or you can attempt to run the patch utility and then view the contents of any .rej files (such as in_camera.cpp.rej) that are created in the process. These will tell you which file changes encountered errors, and where, making the process of correcting the patch not a difficult one.

There is one bug, however, that is not included in the .patch file that you must fix with the following modification:

In the client_dll, the file in_camera.cpp, roughly line 225, you'll see this block of code:

// If cheats have been disabled, pull us back out of third-person view.
if ( sv_cheats && !sv_cheats->GetBool() )
{
	CAM_ToFirstPerson();
	return;
}

Comment out the entire if block like so:

// If cheats have been disabled, pull us back out of third-person view.
/*if ( sv_cheats && !sv_cheats->GetBool() )
{
	CAM_ToFirstPerson();
	return;
}*/

That combined with the patches provided in the Antfarm patch file should have your bare-bones 2D platform game up and running.


Suggested improvements to barebones Antfarm: Source patch

After applying the patch there are still several small problems:

  • By default you may find the game is still loaded in first person (forcing an execution of the thirdperson command), and that the camera distance can be changed on the fly. It's recommended that in the file in_camera.cpp, you change the cam_command, cam_snapto cam_idealdist ConVar define to the type FCVAR_REPLICATED if you are creating a multiplayer game. This will force these values to be sent out by the server when the game is loaded, and will not be able to be altered by the player.
  • If you decide to keep ducking enabled, there are several bugs that come up in third person view:
    • First, there is no third-person animation for duck jumping; when a player duck-jumps, the view will leap, with no animation change. To fix this, in gamemovement.cpp, find the method void CGameMovement::Duck( void ). After bool bInAir is defined, check if( bInAir) return;, making duck-jumping impossible.
    • Ducking animation appears very slow in third person. This is because the animation is only played after the duck is successful, and meanwhile the camera position also lowers. To fix both of these issues, in the same Duck method above, find where the method FinishDuck() is referenced. Comment out the entire if-else statement in which it is contained, and in its place put FinishDuck();. This will cause the player to go into a duck instantly as the button is pressed, without any camera movement. This is much more in keeping with a third person game. Now find a call to FinishUnDuck() in the same method, and perform the exact same operation on its surrounding if-else statement to complete the fix.
    • With in-air ducking disabled, if a player holds down the duck button before landing, they do not go into a duck. A fix for this has not yet been devised.
Loop check for the duck key while in the air? Set flag if duck is pressed while in the air, then send the duck command when the player lands? --Welsh Mullet 17:43, 4 December 2010 (UTC)
  • As mentioned above, for fluid, lag-free animations, all local player animations must be made on the client. Those who have done such modifications may wish to provide additional information here.

See also