Click here to Skip to main content
6,633,937 members and growing! (19,796 online)
Email Password   helpLost your password?
Multimedia » DirectX » General     Intermediate

Multiplayer Snake in 3D using C# and Managed DirectX

By Cr@zyIv@n

A new version of the old game.
C#, Windows, .NET 1.0, .NET 1.1, DirectX, VS.NET2003, Dev
Posted:12 Aug 2004
Views:86,287
Bookmarked:31 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 3.38 Rating: 4.00 out of 5
1 vote, 14.3%
1
1 vote, 14.3%
2

3

4
5 votes, 71.4%
5

Sample Image - screen.jpg

Introduction

Probably, everyone knows the game Snake. However, the Snake from this article is a multiplayer version and fully in 3D. It�s written in C# using Managed DirectX. A little knowledge of C# is necessary. And some (Managed) DirectX or other Graphics programming experience would be useful. I advise you, if you haven't already done so, to read Craig Andera's tutorial first.

You�ll need a C# compiler (Visual Studio .NET if possible). And the DirectX 9.0c SDK [Download it from Microsoft.]

For the code to run, you�ll also need a 3D card. But some adjustments in the code would enable it to run on older machines, decreasing its performance.

The Game Class

This is where initialization happens. Also, this is where user input is processed, using the EventKey class (all it does is check if a keystate is changed).

The Player Class

This class processes the input for the movement of one of the players. It holds a collection of Vectors for the trail. It has a Render method that will do the rendering. It also holds a reference to the Level class, the class that implements level functionality: a square array of Booleans so that the snakes can�t move through each other; it also has a couple of predefined levels to make the game a little less boring.

The Intro Class

Here, two Meshes are created for some sort of intro movie.

The Arena Class

This class renders the box in which the snakes move. It also renders the boxes which initially are already occupied by the Level class.

The Plane Class

This is a class I built quite some time ago. It creates a textured box. And allows choosing the sides you want to render.

Conclusion

I do not expect this code to be efficient. A lot of things could�ve been done better and faster. But it works, and when you�ve got nothing to do, this game can be quite fun.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Cr@zyIv@n


Member

Location: Netherlands Netherlands

Other popular DirectX articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
GeneralHow to run without 3D card PinmemberNhilesh B19:25 11 Oct '07  
GeneralRe: How to run without 3D card PinmemberMember 340188514:56 22 Aug '09  
GeneralThis is very nice PinmemberMashadow18:36 2 Aug '07  
GeneralSuggestion PinmemberDFU2312:12 18 Aug '04  
GeneralMy Experience PinsussPeterK_9:33 18 Aug '04  
GeneralRe: My Experience PinmemberPeterK_10:27 18 Aug '04  
GeneralRe: My Experience PinmemberCr@zyIv@n23:06 18 Aug '04  
GeneralRe: My Experience PinmemberNejat Özsu17:10 8 Sep '04  
GeneralQuestion for the author Pinmemberhacey5:45 28 Jul '05  
GeneralSystem.IO.FileNotFoundException PinmemberChris Sells15:23 14 Aug '04  
GeneralRe: System.IO.FileNotFoundException PinmemberCr@zyIv@n23:08 14 Aug '04  
GeneralRe: System.IO.FileNotFoundException PinmemberChris Sells9:05 15 Aug '04  
GeneralRe: System.IO.FileNotFoundException PinmemberCr@zyIv@n9:42 15 Aug '04  
GeneralRe: System.IO.FileNotFoundException Pinmemberjmw10:59 16 Aug '04  
GeneralRe: System.IO.FileNotFoundException PinmemberCr@zyIv@n23:07 16 Aug '04  
GeneralRe: System.IO.FileNotFoundException PinmemberFBKK12:55 11 Jul '05  
GeneralRe: System.IO.FileNotFoundException Pinmembermicr0chip12:35 26 Nov '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Aug 2004
Editor: Smitha Vijayan
Copyright 2004 by Cr@zyIv@n
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project