Although lately i’m finding myself busier than usual, I still try to enjoy as much as I can my free time with videogames.
Here are some games that I’ve been playing these days:
Counter-Strike Source: Although a bit old today, there are still plenty of players and servers to play on. I find myself this game a really good choice to burn stress, and in my humble opinion, it has the best network code ever made for a game.
Conan: I bought this game not too much ago, and I found the game more enjoying that I though it would be. The combo system is varied and fun, combined with 3 different weapon styles. It could have more kinds of enemies, but anyway is a fun game.
Midnight Club Los Angeles: Another gem that suprised me for good. Much better than nowadays Need for Speed games, MC is a very fast street race arcade with good-looking visuals, good difficulty level and really fun. If you like racing games I totally recommend this one.
Miner Dig Deep: In this community game you take the role of a miner with the objective of going deeper and deeper into the soil to gather minerals, and sell them at the local shop to earn money that enables you to purchase better equipment, that makes it easier to goo even deeper, etc. The game is fun and it looks very polished. If i had to tell one bad thing about it, it would be that when you get to very deep stages, you still have to go down from the base after selling items, and it can take some minutes even using the fastest elevators. There are teleporters, but they are used only to teleport back to base, not in the other way. Anyway, I recommend buying it, for only 200MP it’s really a good choice.
I still have a list of pending games with more than 7 titles on it, I’m starting to get a little stressed about it. It seems I need more spare time to relax a bit :).
During development of an old prototype that never saw the light, I found the need to create some 2D geometry from a set of points that form a line.
After searching for any algorithm that could make what I needed, with no success, I decided to develop my own.
The algorithm is very simple, it just takes a rope and a width and creates a set of vertices tha form a TriangleStrip to be rendered on screen.
[sourcecode language=’csharp’]
///
/// Triangulates a line, returning a list of vertices that form a triangle strip
///
/// List of points that form the line
/// Desired with of the geometry
/// list of vertices that form a triangle strip
public static List Process(ReadOnlyCollection contour,float width)
{
List result = new List();
Vector2 normal = Vector2.Zero ;
// Generate vertices for each point in the line
for (int i = 0; i < contour.Count; i++)
{
// First and last are special cases, the normal is calculated right away
if (i == contour.Count - 1)
normal = GameMath.Normal(contour[i] - contour[i - 1]);
else if (i == 0)
normal = GameMath.Normal(contour[1] - contour[0]);
else
{
// For the rest of points, determine the normal as the middle angle between the direction of the previous and next segments.
Vector2 delta1 = contour[i] - contour[i - 1];
Vector2 delta2 = contour[i + 1] - contour[i];
if ((delta1.Length()!=0)&&(delta2.Length()!=0))
{
delta1.Normalize();
delta2.Normalize();
normal = GameMath.Normal(delta1 + delta2);
}
}
// Add two vertices to the vertex list
result.Add(contour[i] - normal * width / 2f);
result.Add(contour[i] + normal * width / 2f);
}
return result;
}
///
/// Returns one normal of the 2D vector
///
///
///
public static Vector2 Normal(Vector2 line)
{
float x = line.X; float y = line.Y;
Vector2 normal = new Vector2();
if (x != 0)
{
normal.X = -y / x;
normal.Y = 1 / (float)Math.Sqrt(normal.X * normal.X + 1);
normal.Normalize();
}
else if (y != 0)
{
normal.Y = 0;
normal.X = (line.Y<0) ? 1 : -1;
}
else
{
normal.X = 1;
normal.Y = 0;
}
if (x < 0)
{
normal *= -1;
}
return normal;
}
[/sourcecode]
That code is well enough to generate a credible line in almost all situations. As for UVs, what I did was assign the even vertices the value (X,0) and odd vertices (X,1), where X is the distance elapsed since the line start.
Since our first project (Little Racers) has been completed, we’ve begun development of our next one.
Although some details are still vague, we can assure the game mechanics are a fresh approach to a popular genre, that will enhance cooperation and teamplay.
It’s still a little early to disclose the game name or details, please stay tuned for updates on the project status.
During the last review process, an issue was found that although it could’ve passed the review, we decided to fix it and resubmit again, following our policy of quality. The game won’t be able to begin the review process until next Sunday due to the new policy of the Community Games review process.
We’ve used this time to add some extra features, such as the Attract mode (typical of Arcade games, a non-interactive race starts when some time passes on the main menu), and car horns, that although they don’t do anything special, we’ve found testers to use it extensively to annoy other players :).
Yesterday I ran a profiling tool (CLR Profiler) to see how Little Racers does with heap memory allocation, and found something strange: The log showed that class System.Random allocated around 88Mbytes of RAM during the whole execution.
The reason of this is the way the particle system works: Each particle stores only a seed to generate its random values, and a new Random is generated with that seed each time it needs to be updated (that is, on every frame). So, if we’re showing 50 particles on a frame, we’re calling new Random(seed) 50 times.
With System.Random, there was no possible workaround since it doesn’t have a method available to set the seed without recreating everything. Also, it seems to do some hard work on creation, maybe allocating the N next random numbers, I don’t know.
Anyway, I found a nice replacement called FastRandom: This class has the same interface that System.Random, so they can be easily interchanged. Also, it has a method to set the seed without having to recreate the class.
Anyway, I found a bug in the provided code, related with the methods Next(int) and Next(int,int) , it seems to store a double with the minimum value of an int and then multiply it by the desired range. It didn’t work for me, so I just replaced it with a modulus. Maybe it’s a little slower, but it works perfectly.
During the first stages of Little Racers development, I found the need of parsing XML data during the game load. The XNA Content Pipeline system includes XML Parsing, but it uses it in a very particular way. I won’t go much further in the way XNA parses XML because, to be sincere, I’ve not tried it enough to test wether it’s good or not.
My first impression was that it was too strict (probably due to optimization and type safe issues), moreover during parse I would need access to some data structures that only were available at runtime, so I preferred to store plain XML and parse it during game load.
This can be done by extending the content pipeline and adding a new type. To do this we’ll need to add two new projects to our solution.
XmlSource project
The first project we’ll create is the one which has the class that stores our xml plain text. I’ve called it XmlSource.It will have two classes in total.
XmlSource
This class is a very simple one. It simply has a string with the xml plain text:
[sourcecode language=’csharp’]
public class XmlSource
{
public XmlSource(string xmlCode)
{
this.xmlCode = xmlCode;
}
private string xmlCode;
public string XmlCode { get { return xmlCode; } }
}
[/sourcecode]
XmlSourceReader
This class extends ContentTypeReader and simply creates an XmlSource instance from its binary representation. In our case, the binary representation wil be a simple string, so the read is straightforward.
[sourcecode language=’csharp’]
public class XmlSourceReader : ContentTypeReader
{
///
With this, our first project is finished. This project is platform-independant (The Xbox needs to read the binary data) and will have to be referenced from every project that uses the XmlSource class, including the second project we’re making:
XmlSourceImporter
The second project(I called it XmlDocumentImporter) is a project of type “Content Pipeline Extension Library”. This project is referenced from the Content projects, and converts the source text file to binary data that will be saved in the .xnb files.
This project has 2 files:
XmlSourceImporter.cs
This file converts the XML source file into an XmlSource instance, that will be further converted into binary data
[sourcecode language=’csharp’]
[ContentImporter(“.xml”, DisplayName = “Xml Source Importer”)]
class XmlSourceImporter : ContentImporter
{
public override XmlSource Import(string filename, ContentImporterContext context)
{
string sourceCode = System.IO.File.ReadAllText(filename);
return new XmlSource(sourceCode);
}
}
[/sourcecode]
XmlSourceWriter.cs
This file converts an XmlSource into binary data, as opposed to XmlSourceReader
[sourcecode language=’csharp’]
[ContentTypeWriter]
class XmlSourceWriter : ContentTypeWriter
{
protected override void Write(ContentWriter output, XmlSource value)
{
/*StringWriter sw=new StringWriter();
value.Save(sw);
string content = sw.ToString();*/
output.Write(value.XmlCode);
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return typeof(XmlDocument).AssemblyQualifiedName;
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(XmlDocumentReader).AssemblyQualifiedName;
}
}
[/sourcecode]
Sample of use
Once both projects set up (remember to add reference to XmlSourceImporter from the Content project), we can add .xml files to the content project. Under “Content importer”, we’ll need to select “Xml Source importer”, instead of the default XNA one.
Once done this, the program sould compile ok. Loading XML from the program now is very easy:
[sourcecode language=’csharp’]
XmlSource xs = Content.Load(AssetName);
XmlDocument xd = new XmlDocument();
xd.LoadXml(xs.XmlCode);
[/sourcecode]
I know this can be a little confusing, i’ll upload some binaries if someone asks for them.
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies. AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.