First Look at Map Editor

MapEditor

I’ve been working on a map editor for what seem likes forever now. I’ve gotten so much done and then I would just feel like the thing was written poorly and so I would completely reorganize it. I’ve done that about 3 times now.

Finally though I have an MVC pattern going in the code and I’m very comfortable with what I’ve written. I’m not sure when I’ll be finished but I should have something workable within the next weeks or so.

Where did I go?

It’s currently half past midnight and I can’t sleep. I haven’t posted to this blog in quite a while. I’ve been caught up with work and so much else lately that it seems impossible to get around to all the things I want to do in a day.

I did start another blog at snowxna.wordpress.com but I haven’t posted much there either lately. I think I’m going to try and merge the two eventually as I don’t really see the point in having both anymore.

I originally started blogging because I wanted to become a better writer and learn how to better express topics about programming to other people. This has been bugging me a lot lately at work so I think it’s maybe time I got back around to blogging.

I started the other blog because I thought maybe I should keep programming topics separate from others. That’s leaves me with very little to write about though as I do spend most of time programming. All that’s really left when you take that away is video games and music. I don’t see why I can’t sprinkle a little bit of that in around here.

xblcg.info

I haven’t had time to write anything as of late. Really busy with work and I’m spending most of my spare time either writing code or playing video games. I’d like to point people in the direction of http://www.xblcg.info/. I think this site is what community games has needed for the longest and glad to see the guys doing the good work.

http://www.xblcg.info/

M is for Massive

Scientific Ninja has a post about how the term MMORPG is a little overused by hobbyist developers. It’s a good read.

http://scientificninja.com/advice/m-is-for-massive

Calculating an angle from a Vector2

When you need to calculate an angle from a Vector2 structure, you can use this piece of code:

public static class Vector2Helper
{
public static float CalculateAngle(Vector2 v)
{
float angle = 0.0f;

if(v != Vector2.Zero)
{
v.Normalize();

angle = (float)Math.Acos(v.Y);

if(v.X < 0.0f)
angle = -angle;
}

return angle;
}
}

I used this to calculate an angle from the Vector2 of the Left Stick.

The original credit for this source code comes from here.

The Game Show Host Problem, aka The Monty Hall Problem

NOTE: This is a repost from my old blog.

So, me and my girlfriend went to see 21 last night and in the movie they make mention of The Game Show Host problem, aka The Monty Hall Problem.

The jist of the problem is this: You are on a game show. The host presents you with 3 doors, 1 of which has a car behind it, the other 2 have goats. The game show host tells you to pick a door. You do so, at which point the game show host opens up a door to show you a goat behind the door and then asks you if you would like to switch your choice to the other closed door. The question is then, should you switch your choice?

The correct answer is yes. More on why after the jump.

I won’t go too far into detail about why you should switch your answer, I’ll leave that to Wikipedia. Some things to note that may not be obvious: 1) The game show host will always open a door that is not the correct door 2) He will never open your door. These are the keys to this problem. By switching, you will win a prize 2/3 of the time as opposed to only winning 1/3 of the time if you do not.

Many people will argue that once the game show host opens the door with the goat behind it that there is now a 50% chance of you picking the right door by either staying with your door or switching. This is simply not true. Each door still only has 33.3% chance of being the door with the car behind it. The thing is though, once you pick your door, the game show host then eliminates a door based on 2 criteria: 1) The door is not the one with the prize behind it 2) The door is not yours. Due to these criteria, the odds of the correct door do not change for the door that you have picked, but rather change for the doors that you have not picked. The 2 doors not chosen by you then in a sense combine into one option and they together have a probability of 66.7%.

The Wikipedia article explains in much more mathematical detail why it is better to switch. I suggest you look there if I have done nothing but confuse you. This is simple strategy and probability. Knowing exactly how the game works can make you alot better at it.

Addicted to Twitter

I’ll have to admit, I didn’t get this whole twitter thing at first. The idea sounded dumb but I signed up anyway and just looked at it a few times then gave up.

Recently though I’ve gotten back into it and now I’m checking it religiously. I don’t know what joy it brings me but I definitely like it. It’s writing a really tiny blog 4 or 5 times a day.

Drawing 2D Lines as Rotated Quads

I haven’t had much time lately with work but one question I’ve seen asked many many times is how to draw lines of different widths. So, to cut to the chase I’ll share the code I’ve used to do it.

public void DrawLine(Vector3 p1, Color c1, Vector3 p2, Color c2, int width)
{
float distance = Vector3.Distance(p1, p2);
float halfDistance = distance / 2.0f;
float halfWidth = width / 2.0f;

Vector3 difference = p2 – p1;
Vector3 destination = new Vector3(p1.X + difference.X / 2.0f, p1.Y + difference.Y / 2.0f, p1.Z + difference.Z);

// Calculate angle between two points
float angle = (float)Math.Atan2(difference.Y, difference.X);

Vector3 v1, v2, v3, v4;

v1 = new Vector3(-halfDistance, -halfWidth, 0); // Top Left
v2 = new Vector3(halfDistance, -halfWidth, 0); // Top Right
v3 = new Vector3(halfDistance, halfWidth, 0); // Bottom Right
v4 = new Vector3(-halfDistance, halfWidth, 0); // Bottom Left

Matrix m =
Matrix.Identity *
Matrix.CreateRotationZ(angle) *
Matrix.CreateTranslation(destination);

v1 = Vector3.Transform(v1, m);
v2 = Vector3.Transform(v2, m);
v3 = Vector3.Transform(v3, m);
v4 = Vector3.Transform(v4, m);

DrawQuad(v1, c1, v2, c2, v3, c2, v4, c1);
}

I’ve left a lot of fluff code out. I usually check if the line is a width of 1 and draw a normal line. I also left out the code on how to draw a quad as that can be found many other places already.

Let me google that for you

Ever read anything on a forum and thought, “I know that’s one of the first results in Google”. Well, then send your response with Let me google that for you. It’s a great way to let people know that google is smarter than you and him.

Paint Wars

I was listening to “.NET Rocks” show #414 this morning and there was an interview with Chris Marinos. While in college he wrote an Xna game that uses the WiiMote as an input device. He’s recently ported the code to F#. It sounded really interesting so go check it out.

One thing that was said in the interview that I didn’t really agree with though, Xna was said to be able to “run Xbox 360 games on your PC”. This isn’t right and it portrays Xna in the wrong way to me. Xna is Microsoft’s managed DirectX solution. Although it is right now geared more toward the game community, it can still be used for other purposes.

Next Page »